@Test public void coinbaseTransactionAvailability() throws Exception { Wallet wallet2 = Wallet.createDeterministic(UNITTEST, Script.ScriptType.P2PKH); ECKey receiveKey = wallet2.freshReceiveKey(); int height = 1; chain.addWallet(wallet2); Address addressToSendTo = LegacyAddress.fromKey(UNITTEST, receiveKey); Block b1 = UNITTEST.getGenesisBlock().createNextBlockWithCoinbase(Block.BLOCK_VERSION_GENESIS, wallet.currentReceiveKey().getPubKey(), height++); chain.add(b1); assertNotNull(coinbaseTransaction); assertEquals(Coin.ZERO, wallet.getBalance()); assertEquals(wallet.getBalance(BalanceType.ESTIMATED), FIFTY_COINS); assertTrue(!coinbaseTransaction.isMature()); try { wallet.createSend(addressToSendTo, valueOf(49, 0)); fail(); } catch (InsufficientMoneyException e) { } for (int i = 0; i < UNITTEST.getSpendableCoinbaseDepth() - 2; i++) { Transaction tx2 = createFakeTx(UNITTEST, COIN, LegacyAddress.fromKey(UNITTEST, new ECKey())); Block b2 = createFakeBlock(blockStore, height++, tx2).block; chain.add(b2); assertEquals(Coin.ZERO, wallet.getBalance()); assertEquals(wallet.getBalance(BalanceType.ESTIMATED), FIFTY_COINS); assertTrue(!coinbaseTransaction.isMature()); try { wallet.createSend(addressToSendTo, valueOf(49, 0)); fail(); } catch (InsufficientMoneyException e) { } } Transaction tx3 = createFakeTx(UNITTEST, COIN, LegacyAddress.fromKey(UNITTEST, new ECKey())); Block b3 = createFakeBlock(blockStore, height++, tx3).block; chain.add(b3); assertEquals(wallet.getBalance(), FIFTY_COINS); assertEquals(wallet.getBalance(BalanceType.ESTIMATED), FIFTY_COINS); assertTrue(coinbaseTransaction.isMature()); Transaction coinbaseSend2 = wallet.createSend(addressToSendTo, valueOf(49, 0)); assertNotNull(coinbaseSend2); wallet.commitTx(coinbaseSend2); assertEquals(wallet.getBalance(BalanceType.ESTIMATED), COIN); assertEquals(wallet.getBalance(BalanceType.AVAILABLE), ZERO); Block b4 = createFakeBlock(blockStore, height++, coinbaseSend2).block; chain.add(b4); assertEquals(wallet.getBalance(BalanceType.AVAILABLE), COIN); assertEquals(wallet2.getBalance(BalanceType.ESTIMATED), valueOf(49, 0)); assertEquals(wallet2.getBalance(BalanceType.AVAILABLE), valueOf(49, 0)); }
@Override public boolean add(FilteredBlock block) throws VerificationException, PrunedException { boolean success = super.add(block); if (success) { trackFilteredTransactions(block.getTransactionCount()); } return success; }
BlockChain extends AbstractBlockChain { @Override public boolean add(FilteredBlock block) throws VerificationException, PrunedException { boolean success = super.add(block); if (success) { trackFilteredTransactions(block.getTransactionCount()); } return success; } }
BlockChain extends AbstractBlockChain { @Override public boolean add(FilteredBlock block) throws VerificationException, PrunedException { boolean success = super.add(block); if (success) { trackFilteredTransactions(block.getTransactionCount()); } return success; } BlockChain(Context context, Wallet wallet, BlockStore blockStore);  BlockChain(NetworkParameters params, Wallet wallet, BlockStore blockStore);  BlockChain(Context context, BlockStore blockStore);  BlockChain(NetworkParameters params, BlockStore blockStore);  BlockChain(Context params, List<? extends Wallet> wallets, BlockStore blockStore);  BlockChain(NetworkParameters params, List<? extends Wallet> wallets, BlockStore blockStore); }
BlockChain extends AbstractBlockChain { @Override public boolean add(FilteredBlock block) throws VerificationException, PrunedException { boolean success = super.add(block); if (success) { trackFilteredTransactions(block.getTransactionCount()); } return success; } BlockChain(Context context, Wallet wallet, BlockStore blockStore);  BlockChain(NetworkParameters params, Wallet wallet, BlockStore blockStore);  BlockChain(Context context, BlockStore blockStore);  BlockChain(NetworkParameters params, BlockStore blockStore);  BlockChain(Context params, List<? extends Wallet> wallets, BlockStore blockStore);  BlockChain(NetworkParameters params, List<? extends Wallet> wallets, BlockStore blockStore); @Override boolean add(FilteredBlock block); }
BlockChain extends AbstractBlockChain { @Override public boolean add(FilteredBlock block) throws VerificationException, PrunedException { boolean success = super.add(block); if (success) { trackFilteredTransactions(block.getTransactionCount()); } return success; } BlockChain(Context context, Wallet wallet, BlockStore blockStore);  BlockChain(NetworkParameters params, Wallet wallet, BlockStore blockStore);  BlockChain(Context context, BlockStore blockStore);  BlockChain(NetworkParameters params, BlockStore blockStore);  BlockChain(Context params, List<? extends Wallet> wallets, BlockStore blockStore);  BlockChain(NetworkParameters params, List<? extends Wallet> wallets, BlockStore blockStore); @Override boolean add(FilteredBlock block);  }