@Override protected void onSetupCompleted() { if (wallet().getImportedKeys().size() < 1) wallet().importKey(new ECKey()); wallet().allowSpendingUnconfirmedTransactions(); view.displayWalletPath(vWalletFile.getAbsolutePath()); setupWalletListeners(wallet()); Log.d("myLogs", "My address = " + wallet().freshReceiveAddress()); } };
req.feePerKb = feePerKb; if (allowUnconfirmed) { wallet.allowSpendingUnconfirmedTransactions();
appKit.wallet().allowSpendingUnconfirmedTransactions();
req.feePerKb = feePerKb; if (allowUnconfirmed) { wallet.allowSpendingUnconfirmedTransactions();
@Test public void testAddTransactionsDependingOn() throws Exception { CoinSelector originalCoinSelector = wallet.getCoinSelector(); try { wallet.allowSpendingUnconfirmedTransactions(); sendMoneyToWallet(AbstractBlockChain.NewBlockType.BEST_CHAIN, valueOf(2, 0)); Transaction send1 = checkNotNull(wallet.createSend(OTHER_ADDRESS, valueOf(1, 0))); Transaction send2 = checkNotNull(wallet.createSend(OTHER_ADDRESS, valueOf(1, 20))); wallet.commitTx(send1); Transaction send1b = checkNotNull(wallet.createSend(OTHER_ADDRESS, valueOf(0, 50))); wallet.commitTx(send1b); Transaction send1c = checkNotNull(wallet.createSend(OTHER_ADDRESS, valueOf(0, 25))); wallet.commitTx(send1c); wallet.commitTx(send2); Set<Transaction> txns = new HashSet<>(); txns.add(send1); wallet.addTransactionsDependingOn(txns, wallet.getTransactions(true)); assertEquals(3, txns.size()); assertTrue(txns.contains(send1)); assertTrue(txns.contains(send1b)); assertTrue(txns.contains(send1c)); } finally { wallet.setCoinSelector(originalCoinSelector); } }
CoinSelector originalCoinSelector = wallet.getCoinSelector(); try { wallet.allowSpendingUnconfirmedTransactions(); Transaction send1 = sendMoneyToWallet(AbstractBlockChain.NewBlockType.BEST_CHAIN, valueOf(2, 0)); Transaction send1a = checkNotNull(wallet.createSend(OTHER_ADDRESS, valueOf(1, 0)));
@Test public void doubleSpendForBuildingTx() throws Exception { CoinSelector originalCoinSelector = wallet.getCoinSelector(); try { wallet.allowSpendingUnconfirmedTransactions(); sendMoneyToWallet(AbstractBlockChain.NewBlockType.BEST_CHAIN, valueOf(2, 0)); Transaction send1 = checkNotNull(wallet.createSend(OTHER_ADDRESS, valueOf(1, 0))); Transaction send2 = checkNotNull(wallet.createSend(OTHER_ADDRESS, valueOf(1, 20))); sendMoneyToWallet(AbstractBlockChain.NewBlockType.BEST_CHAIN, send1); assertUnspent(send1); wallet.receivePending(send2, null); assertUnspent(send1); assertDead(send2); } finally { wallet.setCoinSelector(originalCoinSelector); } }
@Test public void txSpendingDeadTx() throws Exception { CoinSelector originalCoinSelector = wallet.getCoinSelector(); try { wallet.allowSpendingUnconfirmedTransactions(); sendMoneyToWallet(AbstractBlockChain.NewBlockType.BEST_CHAIN, valueOf(2, 0)); Transaction send1 = checkNotNull(wallet.createSend(OTHER_ADDRESS, valueOf(1, 0))); Transaction send2 = checkNotNull(wallet.createSend(OTHER_ADDRESS, valueOf(1, 20))); wallet.commitTx(send1); assertPending(send1); Transaction send1b = checkNotNull(wallet.createSend(OTHER_ADDRESS, valueOf(0, 50))); sendMoneyToWallet(AbstractBlockChain.NewBlockType.BEST_CHAIN, send2); assertDead(send1); assertUnspent(send2); wallet.receivePending(send1b, null); assertDead(send1); assertUnspent(send2); assertDead(send1b); } finally { wallet.setCoinSelector(originalCoinSelector); } }
@Test public void orderingInsideBlock() throws Exception { // Test that transactions received in the same block have their ordering preserved when reorganising. // This covers issue 468. // Receive some money to the wallet. Transaction t1 = FakeTxBuilder.createFakeTx(PARAMS, COIN, coinsTo); final Block b1 = FakeTxBuilder.makeSolvedTestBlock(PARAMS.genesisBlock, t1); chain.add(b1); // Send a couple of payments one after the other (so the second depends on the change output of the first). wallet.allowSpendingUnconfirmedTransactions(); Transaction t2 = checkNotNull(wallet.createSend(new ECKey().toAddress(PARAMS), CENT)); wallet.commitTx(t2); Transaction t3 = checkNotNull(wallet.createSend(new ECKey().toAddress(PARAMS), CENT)); wallet.commitTx(t3); chain.add(FakeTxBuilder.makeSolvedTestBlock(b1, t2, t3)); final Coin coins0point98 = COIN.subtract(CENT).subtract(CENT); assertEquals(coins0point98, wallet.getBalance()); // Now round trip the wallet and force a re-org. ByteArrayOutputStream bos = new ByteArrayOutputStream(); wallet.saveToFileStream(bos); wallet = Wallet.loadFromFileStream(new ByteArrayInputStream(bos.toByteArray())); final Block b2 = FakeTxBuilder.makeSolvedTestBlock(b1, t2, t3); final Block b3 = FakeTxBuilder.makeSolvedTestBlock(b2); chain.add(b2); chain.add(b3); // And verify that the balance is as expected. Because new ECKey() is non-deterministic, if the order // isn't being stored correctly this should fail 50% of the time. assertEquals(coins0point98, wallet.getBalance()); }
send1 = PARAMS.getDefaultSerializer().makeTransaction(buf); wallet.commitTx(send2); wallet.allowSpendingUnconfirmedTransactions(); assertEquals(value, wallet.getBalance(Wallet.BalanceType.ESTIMATED));