当前位置: 首页>>代码示例>>Java>>正文


Java Context类代码示例

本文整理汇总了Java中org.bitcoinj.core.Context的典型用法代码示例。如果您正苦于以下问题:Java Context类的具体用法?Java Context怎么用?Java Context使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Context类属于org.bitcoinj.core包,在下文中一共展示了Context类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: Wallet

import org.bitcoinj.core.Context; //导入依赖的package包/类
private Wallet(Context context, KeyChainGroup keyChainGroup) {
    this.context = context;
    this.params = context.getParams();
    this.keyChainGroup = checkNotNull(keyChainGroup);
    if (params.getId().equals(NetworkParameters.ID_UNITTESTNET))
        this.keyChainGroup.setLookaheadSize(5);  // Cut down excess computation for unit tests.
    // If this keyChainGroup was created fresh just now (new wallet), make HD so a backup can be made immediately
    // without having to call current/freshReceiveKey. If there are already keys in the chain of any kind then
    // we're probably being deserialized so leave things alone: the API user can upgrade later.
    if (this.keyChainGroup.numKeys() == 0)
        this.keyChainGroup.createAndActivateNewHDChain();
    watchedScripts = Sets.newHashSet();
    unspent = new HashMap<>();
    spent = new HashMap<>();
    pending = new HashMap<>();
    dead = new HashMap<>();
    transactions = new HashMap<>();
    extensions = new HashMap<>();
    // Use a linked hash map to ensure ordering of event listeners is correct.
    confidenceChanged = new LinkedHashMap<>();
    signers = new ArrayList<>();
    addTransactionSigner(new LocalTransactionSigner());
    createTransientState();
}
 
开发者ID:guodroid,项目名称:okwallet,代码行数:25,代码来源:Wallet.java

示例2: Wallet

import org.bitcoinj.core.Context; //导入依赖的package包/类
private Wallet(Context context, KeyChainGroup keyChainGroup) {
    this.context = context;
    this.params = context.getParams();
    this.keyChainGroup = checkNotNull(keyChainGroup);
    if (params.getId().equals(NetworkParameters.ID_UNITTESTNET))
        this.keyChainGroup.setLookaheadSize(5);  // Cut down excess computation for unit tests.
    // If this keyChainGroup was created fresh just now (new wallet), make HD so a backup can be made immediately
    // without having to call current/freshReceiveKey. If there are already keys in the chain of any kind then
    // we're probably being deserialized so leave things alone: the API user can upgrade later.
    if (this.keyChainGroup.numKeys() == 0)
        this.keyChainGroup.createAndActivateNewHDChain();
    watchedScripts = Sets.newHashSet();
    unspent = new HashMap<Sha256Hash, Transaction>();
    spent = new HashMap<Sha256Hash, Transaction>();
    pending = new HashMap<Sha256Hash, Transaction>();
    dead = new HashMap<Sha256Hash, Transaction>();
    transactions = new HashMap<Sha256Hash, Transaction>();
    extensions = new HashMap<String, WalletExtension>();
    // Use a linked hash map to ensure ordering of event listeners is correct.
    confidenceChanged = new LinkedHashMap<Transaction, TransactionConfidence.Listener.ChangeReason>();
    signers = new ArrayList<TransactionSigner>();
    addTransactionSigner(new LocalTransactionSigner());
    createTransientState();
}
 
开发者ID:Grant-Redmond,项目名称:cryptwallet,代码行数:25,代码来源:Wallet.java

示例3: NameLookupLatestLevelDBTransactionCache

import org.bitcoinj.core.Context; //导入依赖的package包/类
public NameLookupLatestLevelDBTransactionCache (Context context, File directory, DBFactory dbFactory, BlockChain chain, BlockStore store, PeerGroup peerGroup) throws IOException {
    this.chain = chain;
    this.store = store;
    this.peerGroup = peerGroup;
    
    this.context = context;
    this.params = context.getParams();
    
    this.path = directory;
    Options options = new Options();
    options.createIfMissing();
    
    try {
        tryOpen(directory, dbFactory, options);
    } catch (IOException e) {
        dbFactory.repair(directory, options);
        tryOpen(directory, dbFactory, options);
    }
    
    chain.addNewBestBlockListener(Threading.SAME_THREAD, this);
    chain.addReorganizeListener(Threading.SAME_THREAD, this);
    chain.addTransactionReceivedListener(Threading.SAME_THREAD, this);
}
 
开发者ID:dogecoin,项目名称:libdohj,代码行数:24,代码来源:NameLookupLatestLevelDBTransactionCache.java

示例4: newThread

import org.bitcoinj.core.Context; //导入依赖的package包/类
@Override
public Thread newThread(Runnable r) {
    final String name = context.getParams().getId() + " worker #"
            + (++threadCount);
    final Thread thread = new Thread(group, () -> {
        Context.propagate(context);
        r.run();
    }, name);

    if (uncaughtExceptionHandler != null) {
        thread.setUncaughtExceptionHandler(uncaughtExceptionHandler);
    }
    thread.setDaemon(true);

    return thread;
}
 
开发者ID:rnicoll,项目名称:cate,代码行数:17,代码来源:NetworkThreadFactory.java

示例5: shouldSetContextOnThread

import org.bitcoinj.core.Context; //导入依赖的package包/类
/**
 * Generate a thread and confirm the context is set on it.
 */
@Test
public void shouldSetContextOnThread() throws InterruptedException {
    final Context expected = new Context(TestNet3Params.get());
    final Context broken = new Context(DogecoinTestNet3Params.get());
    final NetworkThreadFactory factory = new NetworkThreadFactory(expected);

    // Progagate the wrong context onto this thread
    Context.propagate(broken);
    assertEquals(broken, Context.get());

    final ThreadMonitor monitor = new ThreadMonitor();
    final Thread thread = factory.newThread(monitor);
    thread.run();
    thread.join();
    
    assertEquals(expected, monitor.actual);
}
 
开发者ID:rnicoll,项目名称:cate,代码行数:21,代码来源:NetworkThreadFactoryTest.java

示例6: main

import org.bitcoinj.core.Context; //导入依赖的package包/类
public static void main(String[] args) {
    BriefLogFormatter.initWithSilentBitcoinJ();
    ch.qos.logback.classic.Logger rootLogger = (ch.qos.logback.classic.Logger)
            LoggerFactory.getLogger(ch.qos.logback.classic.Logger.ROOT_LOGGER_NAME);
    rootLogger.setLevel(Level.OFF);
    boolean generate = false;
    switch (args[0]) {
        case "generate":
            generate = true;
            break;
        default:
            System.out.println("Usage:\n generate: returns a new wallet " +
                    "seed and creation time");
            break;
    }


    if(generate){
        final NetworkParameters params = TestNet3Params.get();
        Context context = new Context(params);
        Wallet wallet = new Wallet(context);
        DeterministicSeed seed = wallet.getKeyChainSeed();
        String seedString = seed.getMnemonicCode().toString();
        System.out.println(seedString.substring(1,seedString.length()-1));
        System.out.println(seed.getCreationTimeSeconds());
    }


}
 
开发者ID:IUNO-TDM,项目名称:PaymentService,代码行数:30,代码来源:WalletInitializer.java

示例7: prepare

import org.bitcoinj.core.Context; //导入依赖的package包/类
@Before
    public void prepare () {
        Context.getOrCreate(Constants.getNetwork());

        node1 = new ClientObject();
        node2 = new ClientObject();

        node1.isServer = false;
        node2.isServer = true;

        node1.name = "LNPayment1";
        node2.name = "LNPayment2";

        messageFactory1 = new LNPaymentMessageFactoryImpl(dbHandler1);
        messageFactory2 = new LNPaymentMessageFactoryImpl(dbHandler2);

        channel1 = getMockChannel();
        channel2 = getMockChannel();

//        channel1.channelStatus.applyConfiguration(configuration);
//        channel2.channelStatus.applyConfiguration(configuration);

        channel1.retrieveDataFromOtherChannel(channel2);
        channel2.retrieveDataFromOtherChannel(channel1);

        paymentLogic1 = new LNPaymentLogicImpl(messageFactory1, dbHandler1);
        paymentLogic2 = new LNPaymentLogicImpl(messageFactory2, dbHandler2);

        paymentLogic1.initialise(channel1);
        paymentLogic2.initialise(channel2);
    }
 
开发者ID:blockchain,项目名称:thunder,代码行数:32,代码来源:LNPaymentLogicImplTest.java

示例8: getChain

import org.bitcoinj.core.Context; //导入依赖的package包/类
@Bean
public BlockChain getChain(final NetworkParameters params,
                           final SPVBlockStore blockStore,
                           final Context context)
        throws BlockStoreException {
    return new BlockChain(context, blockStore);
}
 
开发者ID:yopeio,项目名称:payment-api,代码行数:8,代码来源:BitcoinjConfiguration.java

示例9: setUp

import org.bitcoinj.core.Context; //导入依赖的package包/类
@Before
public void setUp() throws Exception {

    this.blockStore = new SPVBlockStore(this.params, new File("tbtc_blockstore"));
    final BlockChain chain = new BlockChain(new Context(this.params), this.blockStore);

    final PeerGroup peerGroup = new PeerGroup(this.params, chain);
    final BlockchainSettings settings = new BlockchainSettings(1, BigDecimal.ZERO, BigDecimal.TEN, "target", "central.wallet", "admin", "password");
    this.service = new BitcoinjBlockchainServiceImpl(this.params, chain, peerGroup, this.transactionService, this.walletService, this.accountService, settings);
    this.service.init();

    this.wallets.add(this.wallet);
    when(this.accountService.getByEmail("admin")).thenReturn(this.account);
    when(this.account.getWallets()).thenReturn(this.wallets);
    when(this.transactionService.getByReceiverHash(anyString())).thenReturn(this.transaction, this.transaction);
    when(this.wallet.toBuilder()).thenReturn(Wallet.builder());
    when(this.wallet.getContent()).thenAnswer(new Answer<String>() {
        @Override
        public String answer(final InvocationOnMock invocation) throws Throwable {
            counter ++;
            if (counter == 1) {
                return FileUtils.readFileToString(new File("src/test/resources/content.cnt"));
            }
            return FileUtils.readFileToString(new File("src/test/resources/content1.cnt"));
        }

    });
}
 
开发者ID:yopeio,项目名称:payment-api,代码行数:29,代码来源:BitcoinjBlockchainServiceImplTest.java

示例10: prepare

import org.bitcoinj.core.Context; //导入依赖的package包/类
@Before
public void prepare () {
    Context.getOrCreate(Constants.getNetwork());

    node1 = new NodeClient();
    node2 = new NodeClient();

    node1.isServer = false;
    node2.isServer = true;

    node1.name = "LNPayment1";
    node2.name = "LNPayment2";

    messageFactory1 = new LNPaymentMessageFactoryImpl(dbHandler1);
    messageFactory2 = new LNPaymentMessageFactoryImpl(dbHandler2);

    channel1 = new Channel();
    channel2 = new Channel();

    channel1.channelStatus.applyConfiguration(configuration);
    channel2.channelStatus.applyConfiguration(configuration);

    channel1.retrieveDataFromOtherChannel(channel2);
    channel2.retrieveDataFromOtherChannel(channel1);

    paymentLogic1 = new LNPaymentLogicImpl(messageFactory1, dbHandler1);
    paymentLogic2 = new LNPaymentLogicImpl(messageFactory2, dbHandler2);

    paymentLogic1.initialise(channel1);
    paymentLogic2.initialise(channel2);
}
 
开发者ID:matsjj,项目名称:thundernetwork,代码行数:32,代码来源:LNPaymentLogicImplTest.java

示例11: Network

import org.bitcoinj.core.Context; //导入依赖的package包/类
/**
 * @param context context this network manages.
 * @param controller the controller to push events back to.
 * @param directory the data directory to store the wallet and SPV chain in.
 * @param networkExecutor executor for tasks belonging to this network.
 * Must exist after the lifecycle of network (so that service status listeners
 * can be attached to it).
 */
public Network(final Context context, final MainController controller,
        final File directory, final Executor networkExecutor,
        final BiConsumer<Network, Wallet> registerWalletHook) {
    super(context, directory, "cate_" + context.getParams().getId());
    this.controller = controller;
    this.networkExecutor = networkExecutor;
    autoStop = false;
    blockingStartup = true;
    this.registerWalletHook = registerWalletHook;

    monetaryFormatter = context.getParams().getMonetaryFormat();
    addListener(new Service.Listener() {
        @Override
        public void running() {
            estimatedBalance.set(monetaryFormatter.format(wallet().getBalance(Wallet.BalanceType.ESTIMATED)).toString());
            try {
                blocks.set(store().getChainHead().getHeight());
            } catch (BlockStoreException ex) {
                logger.error("Error getting current chain head while starting wallet "
                        + params.getId(), ex);
            }
            encrypted.set(wallet().isEncrypted());
        }

        @Override
        public void failed(Service.State from, Throwable failure) {
            controller.onNetworkFailed(Network.this, from, failure);
        }
    }, networkExecutor);
}
 
开发者ID:rnicoll,项目名称:cate,代码行数:39,代码来源:Network.java

示例12: NetworkThreadFactory

import org.bitcoinj.core.Context; //导入依赖的package包/类
/**
 * @param context context to propagate to all threads created by this factory.
 */
public NetworkThreadFactory(final Context context) {
    assert context != null;
    this.context = context;
    this.group = new ThreadGroup(context.getParams().getId() + " threads");
    this.uncaughtExceptionHandler = null;
}
 
开发者ID:rnicoll,项目名称:cate,代码行数:10,代码来源:NetworkThreadFactory.java

示例13: testprovider

import org.bitcoinj.core.Context; //导入依赖的package包/类
@Test
public void testprovider() throws Exception {
	
	String providerTx = "0100000001ceea58a6abe24b758091af9b20f11298fcecac97a1ae00bd0864f3d77f2e346a030000006b48304502210085dac060f7e49985900deac71723d2447ea039c7ddaae0002d7b04e6c9f53c9f02203dd0c56e2c6c933fe8d285625a609f1e5231b5fa9c0900b1c01315604bc90973012102177443482b37347f589c248fd171c788e5a23e9719537235d35cf5411322aaa4ffffffff04e87a0100000000001976a9143dd956abd892d5e88583357aaa516fd63c3f858288ac0000000000000000536a4c500000000000000200004000000800400000004000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a0860100000000001976a91446b6a63b00eb2acf86735e846c5e79abb8582f6388ac483b0900000000001976a914901d5e68ab54d5a5b0ca734fa29efe366401850088ac00000000";
	
	final ProviderRegister dummyProvider = new DummyProviderRegister();
	
	final UserRegister dummyUser = new DummyUserRegister();
	
	final RegisterFactory dummyFactory = new DummyRegisterFactory(dummyUser, dummyProvider, new DummyTransactionManager());
	
	Transaction originalTransaction = UniquidRegTest.get().getDefaultSerializer().makeTransaction(Hex.decode(providerTx));
	
	final Context c = Context.getOrCreate(UniquidRegTest.get());
	
	
	ProviderContract contract = new ProviderContract(new UniquidNodeStateContext() {
		
		@Override
		public void setUniquidNodeState(UniquidNodeState nodeState) {
			
		}
		
		@Override
		public Wallet getUserWallet() {
			return null;
		}
		
		@Override
		public UniquidNodeEventService getUniquidNodeEventService() {
			return new UniquidNodeEventService();
		}
		
		@Override
		public String getPublicKey() {
			return null;
		}
		
		@Override
		public Wallet getProviderWallet() {
			return new DummyWallet(c);
		}
		
		@Override
		public Address getImprintingAddress() {
			return null;
		}
		
		@Override
		public UniquidNodeConfiguration getUniquidNodeConfiguration() {
			return new UniquidNodeConfigurationImpl() {
				
				@Override
				public RegisterFactory getRegisterFactory() {
					return dummyFactory;
				}
				
				@Override
				public NetworkParameters getNetworkParameters() {
					return UniquidRegTest.get();
				}
				
			};
		}
	});
	
	contract.doRealContract(originalTransaction);
	
	Assert.assertEquals(1, dummyProvider.getAllChannels().size());
	
}
 
开发者ID:uniquid,项目名称:uidcore-java,代码行数:72,代码来源:ProviderContractTest.java

示例14: DummyWallet

import org.bitcoinj.core.Context; //导入依赖的package包/类
public DummyWallet(Context context) {
	super(context);
}
 
开发者ID:uniquid,项目名称:uidcore-java,代码行数:4,代码来源:ProviderContractTest.java

示例15: getContext

import org.bitcoinj.core.Context; //导入依赖的package包/类
/** Returns the API context that this wallet was created with. */
public Context getContext() {
    return context;
}
 
开发者ID:guodroid,项目名称:okwallet,代码行数:5,代码来源:Wallet.java


注:本文中的org.bitcoinj.core.Context类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。