/** * <p>Constructs a BlockChain connected to the given wallet and store. To obtain a {@link Wallet} you can construct * one from scratch, or you can deserialize a saved wallet from disk using * {@link Wallet#loadFromFile(java.io.File, WalletExtension...)}</p> * * <p>For the store, you should use {@link org.bitcoinj.store.SPVBlockStore} or you could also try a * {@link org.bitcoinj.store.MemoryBlockStore} if you want to hold all headers in RAM and don't care about * disk serialization (this is rare).</p> */ public BlockChain(Context context, Wallet wallet, BlockStore blockStore) throws BlockStoreException { this(context, new ArrayList<Wallet>(), blockStore); addWallet(wallet); }
public void addWalletToBlockChain(Wallet wallet) { if (blockChain != null && wallet != null) { log.trace("Adding wallet {} to blockChain {}", wallet, blockChain); blockChain.addWallet(wallet); } else { log.debug("Could not add wallet to blockChain - one or more is missing"); } }
/** * <p>Constructs a BlockChain connected to the given wallet and store. To obtain a {@link Wallet} you can construct * one from scratch, or you can deserialize a saved wallet from disk using * {@link Wallet#loadFromFile(java.io.File, WalletExtension...)}</p> * * <p>For the store, you should use {@link org.bitcoinj.store.SPVBlockStore} or you could also try a * {@link org.bitcoinj.store.MemoryBlockStore} if you want to hold all headers in RAM and don't care about * disk serialization (this is rare).</p> */ public BlockChain(Context context, Wallet wallet, BlockStore blockStore) throws BlockStoreException { this(context, new ArrayList<Wallet>(), blockStore); addWallet(wallet); }
/** * <p>Constructs a BlockChain connected to the given wallet and store. To obtain a {@link Wallet} you can construct * one from scratch, or you can deserialize a saved wallet from disk using * {@link Wallet#loadFromFile}</p> * * <p>For the store, you should use {@link org.bitcoinj.store.SPVBlockStore} or you could also try a * {@link org.bitcoinj.store.MemoryBlockStore} if you want to hold all headers in RAM and don't care about * disk serialization (this is rare).</p> */ public BlockChain(Context context, Wallet wallet, BlockStore blockStore) throws BlockStoreException { this(context, new ArrayList<Wallet>(), blockStore); addWallet(wallet); }
/** * <p>Constructs a BlockChain connected to the given wallet and store. To obtain a {@link Wallet} you can construct * one from scratch, or you can deserialize a saved wallet from disk using * {@link Wallet#loadFromFile(java.io.File, WalletExtension...)}</p> * * <p>For the store, you should use {@link org.bitcoinj.store.SPVBlockStore} or you could also try a * {@link org.bitcoinj.store.MemoryBlockStore} if you want to hold all headers in RAM and don't care about * disk serialization (this is rare).</p> */ public BlockChain(Context context, Wallet wallet, BlockStore blockStore) throws BlockStoreException { this(context, new ArrayList<Wallet>(), blockStore); addWallet(wallet); }
private void walletSetUp() { this.wallet = new Wallet(this.bitcoinContext); this.bitcoinBlockchain.addWallet(wallet); bitcoinPeerGroup.addWallet(wallet); }
public BitcoinTestPaymentService(BlockChain bitcoinBlockchain, Context bitcoinContext, NetworkParameters bitcoinNetworkParameters, PeerGroup peerGroup, String walletPassword, String walletPath) throws IOException, CipherException, UnreadableWalletException { this.bitcoinBlockchain = bitcoinBlockchain; this.bitcoinContext = bitcoinContext; this.bitcoinNetworkParameters = bitcoinNetworkParameters; this.peerGroup = peerGroup; File walletFile = new File(walletPath); if (walletFile.exists()) { LOG.info("Wallet exists... trying to load from: {}", walletPath); this.bitcoinWallet = Wallet.loadFromFile(new File(walletPath)); } else { LOG.info("Wallet does NOT exist... creating one.", walletPath); this.bitcoinWallet = new Wallet(this.bitcoinContext); this.bitcoinWallet.saveToFile(walletFile); } LOG.info("Wallet loaded: address={}", this.bitcoinWallet.currentReceiveAddress()); this.bitcoinWallet.autosaveToFile(walletFile, 500, TimeUnit.MILLISECONDS, null); this.bitcoinBlockchain.addWallet(this.bitcoinWallet); peerGroup.addWallet(this.bitcoinWallet); }
blockChain.addWallet(wallet); log.debug("Created block chain '{}' with height '{}'", blockChain, blockChain.getBestChainHeight());
vPeerGroup.addPeerDiscovery(discovery != null ? discovery : new DnsDiscovery(params)); vChain.addWallet(vWallet); vPeerGroup.addWallet(vWallet); onSetupCompleted();
vPeerGroup.addPeerDiscovery(discovery != null ? discovery : new DnsDiscovery(params)); vChain.addWallet(vWallet); vPeerGroup.addWallet(vWallet); onSetupCompleted();
vPeerGroup.addPeerDiscovery(discovery != null ? discovery : new DnsDiscovery(params)); vChain.addWallet(vWallet); vPeerGroup.addWallet(vWallet); onSetupCompleted();
vPeerGroup.addPeerDiscovery(discovery != null ? discovery : new DnsDiscovery(params)); vChain.addWallet(vWallet); vPeerGroup.addWallet(vWallet); onSetupCompleted();
chain.addWallet(wallet); peers.addWallet(wallet);
@Override @Before public void setUp() throws Exception { Utils.setMockClock(); // Use mock clock super.setUp(); Context.propagate(new Context(PARAMS, 100, Coin.ZERO, false)); wallet.addExtension(new StoredPaymentChannelClientStates(wallet, new TransactionBroadcaster() { @Override public TransactionBroadcast broadcastTransaction(Transaction tx) { fail(); return null; } })); sendMoneyToWallet(AbstractBlockChain.NewBlockType.BEST_CHAIN, COIN); chain = new BlockChain(PARAMS, wallet, blockStore); // Recreate chain as sendMoneyToWallet will confuse it serverWallet = new Wallet(PARAMS); serverKey = serverWallet.freshReceiveKey(); chain.addWallet(serverWallet); broadcasts = new LinkedBlockingQueue<>(); mockBroadcaster = new TransactionBroadcaster() { @Override public TransactionBroadcast broadcastTransaction(Transaction tx) { SettableFuture<Transaction> future = SettableFuture.create(); broadcasts.add(new TxFuturePair(tx, future)); return TransactionBroadcast.createMockBroadcast(tx, future); } }; }
@Test public void receiveTxBroadcastOnAddedWallet() throws Exception { // Check that when we receive transactions on all our peers, we do the right thing. peerGroup.start(); // Create a peer. InboundMessageQueuer p1 = connectPeer(1); Wallet wallet2 = new Wallet(PARAMS); ECKey key2 = wallet2.freshReceiveKey(); Address address2 = key2.toAddress(PARAMS); peerGroup.addWallet(wallet2); blockChain.addWallet(wallet2); assertEquals(BloomFilter.class, waitForOutbound(p1).getClass()); assertEquals(MemoryPoolMessage.class, waitForOutbound(p1).getClass()); Coin value = COIN; Transaction t1 = FakeTxBuilder.createFakeTx(PARAMS, value, address2); InventoryMessage inv = new InventoryMessage(PARAMS); inv.addTransaction(t1); inbound(p1, inv); assertTrue(outbound(p1) instanceof GetDataMessage); inbound(p1, t1); // Asks for dependency. GetDataMessage getdata = (GetDataMessage) outbound(p1); assertNotNull(getdata); inbound(p1, new NotFoundMessage(PARAMS, getdata.getItems())); pingAndWait(p1); assertEquals(value, wallet2.getBalance(Wallet.BalanceType.ESTIMATED)); }
@Test public void rollbackBlockStore() throws Exception { // This test simulates an issue on Android, that causes the VM to crash while receiving a block, so that the // block store is persisted but the wallet is not. Block b1 = PARAMS.getGenesisBlock().createNextBlock(coinbaseTo); Block b2 = b1.createNextBlock(coinbaseTo); // Add block 1, no frills. assertTrue(chain.add(b1)); assertEquals(b1.cloneAsHeader(), chain.getChainHead().getHeader()); assertEquals(1, chain.getBestChainHeight()); assertEquals(1, wallet.getLastBlockSeenHeight()); // Add block 2 while wallet is disconnected, to simulate crash. chain.removeWallet(wallet); assertTrue(chain.add(b2)); assertEquals(b2.cloneAsHeader(), chain.getChainHead().getHeader()); assertEquals(2, chain.getBestChainHeight()); assertEquals(1, wallet.getLastBlockSeenHeight()); // Add wallet back. This will detect the height mismatch and repair the damage done. chain.addWallet(wallet); assertEquals(b1.cloneAsHeader(), chain.getChainHead().getHeader()); assertEquals(1, chain.getBestChainHeight()); assertEquals(1, wallet.getLastBlockSeenHeight()); // Now add block 2 correctly. assertTrue(chain.add(b2)); assertEquals(b2.cloneAsHeader(), chain.getChainHead().getHeader()); assertEquals(2, chain.getBestChainHeight()); assertEquals(2, wallet.getLastBlockSeenHeight()); } }
ECKey receiveKey = wallet2.freshReceiveKey(); int height = 1; chain.addWallet(wallet2);