public synchronized ListenableFuture<TransactionConfidence> getDepthFuture(final int depth) { return getDepthFuture(depth, Threading.USER_THREAD); }
public synchronized ListenableFuture<TransactionConfidence> getDepthFuture(final int depth) { return getDepthFuture(depth, Threading.USER_THREAD); }
public synchronized ListenableFuture<TransactionConfidence> getDepthFuture(final int depth) { return getDepthFuture(depth, Threading.USER_THREAD); }
public synchronized ListenableFuture<TransactionConfidence> getDepthFuture(final int depth) { return getDepthFuture(depth, Threading.USER_THREAD); }
@Override public void onCoinsReceived(Wallet w, Transaction tx, Coin prevBalance, Coin newBalance) { // Runs in the dedicated "user thread" (see bitcoinj docs for more info on this). // // The transaction "tx" can either be pending, or included into a block (we didn't see the broadcast). Coin value = tx.getValueSentToMe(w); System.out.println("Received tx for " + value.toFriendlyString() + ": " + tx); System.out.println("Transaction will be forwarded after it confirms."); // Wait until it's made it into the block chain (may run immediately if it's already there). // // For this dummy app of course, we could just forward the unconfirmed transaction. If it were // to be double spent, no harm done. Wallet.allowSpendingUnconfirmedTransactions() would have to // be called in onSetupCompleted() above. But we don't do that here to demonstrate the more common // case of waiting for a block. Futures.addCallback(tx.getConfidence().getDepthFuture(1), new FutureCallback<TransactionConfidence>() { @Override public void onSuccess(TransactionConfidence result) { forwardCoins(tx); } @Override public void onFailure(Throwable t) { // This kind of future can't fail, just rethrow in case something weird happens. throw new RuntimeException(t); } }); } });
protected void watchCloseConfirmations() { // When we see the close transaction get enough confirmations, we can just delete the record // of this channel along with the refund tx from the wallet, because we're not going to need // any of that any more. final TransactionConfidence confidence = storedChannel.close.getConfidence(); int numConfirms = Context.get().getEventHorizon(); ListenableFuture<TransactionConfidence> future = confidence.getDepthFuture(numConfirms, Threading.SAME_THREAD); Futures.addCallback(future, new FutureCallback<TransactionConfidence>() { @Override public void onSuccess(TransactionConfidence result) { deleteChannelFromWallet(); } @Override public void onFailure(Throwable t) { Throwables.propagate(t); } }); }
protected void watchCloseConfirmations() { // When we see the close transaction get enough confirmations, we can just delete the record // of this channel along with the refund tx from the wallet, because we're not going to need // any of that any more. final TransactionConfidence confidence = storedChannel.close.getConfidence(); int numConfirms = Context.get().getEventHorizon(); ListenableFuture<TransactionConfidence> future = confidence.getDepthFuture(numConfirms, Threading.SAME_THREAD); Futures.addCallback(future, new FutureCallback<TransactionConfidence>() { @Override public void onSuccess(TransactionConfidence result) { deleteChannelFromWallet(); } @Override public void onFailure(Throwable t) { Throwables.propagate(t); } }); }
protected void watchCloseConfirmations() { // When we see the close transaction get enough confirmations, we can just delete the record // of this channel along with the refund tx from the wallet, because we're not going to need // any of that any more. final TransactionConfidence confidence = storedChannel.close.getConfidence(); int numConfirms = Context.get().getEventHorizon(); ListenableFuture<TransactionConfidence> future = confidence.getDepthFuture(numConfirms, Threading.SAME_THREAD); Futures.addCallback(future, new FutureCallback<TransactionConfidence>() { @Override public void onSuccess(TransactionConfidence result) { deleteChannelFromWallet(); } @Override public void onFailure(Throwable t) { Throwables.propagate(t); } }); }
protected void watchCloseConfirmations() { // When we see the close transaction get enough confirmations, we can just delete the record // of this channel along with the refund tx from the wallet, because we're not going to need // any of that any more. final TransactionConfidence confidence = storedChannel.close.getConfidence(); int numConfirms = Context.get().getEventHorizon(); ListenableFuture<TransactionConfidence> future = confidence.getDepthFuture(numConfirms, Threading.SAME_THREAD); Futures.addCallback(future, new FutureCallback<TransactionConfidence>() { @Override public void onSuccess(TransactionConfidence result) { deleteChannelFromWallet(); } @Override public void onFailure(Throwable t) { Throwables.propagate(t); } }); }
kit.peerGroup().broadcastTransaction(request.tx).future().get(); System.out.println("Send complete, waiting for confirmation"); request.tx.getConfidence().getDepthFuture(1).get();
private void receiveATransactionAmount(Wallet wallet, Address toAddress, Coin amount) { final ListenableFuture<Coin> availFuture = wallet.getBalanceFuture(amount, Wallet.BalanceType.AVAILABLE); final ListenableFuture<Coin> estimatedFuture = wallet.getBalanceFuture(amount, Wallet.BalanceType.ESTIMATED); assertFalse(availFuture.isDone()); assertFalse(estimatedFuture.isDone()); // Send some pending coins to the wallet. Transaction t1 = sendMoneyToWallet(wallet, null, amount, toAddress); Threading.waitForUserCode(); final ListenableFuture<TransactionConfidence> depthFuture = t1.getConfidence().getDepthFuture(1); assertFalse(depthFuture.isDone()); assertEquals(ZERO, wallet.getBalance()); assertEquals(amount, wallet.getBalance(Wallet.BalanceType.ESTIMATED)); assertFalse(availFuture.isDone()); // Our estimated balance has reached the requested level. assertTrue(estimatedFuture.isDone()); assertEquals(1, wallet.getPoolSize(Pool.PENDING)); assertEquals(0, wallet.getPoolSize(Pool.UNSPENT)); // Confirm the coins. sendMoneyToWallet(wallet, AbstractBlockChain.NewBlockType.BEST_CHAIN, t1); assertEquals("Incorrect confirmed tx balance", amount, wallet.getBalance()); assertEquals("Incorrect confirmed tx PENDING pool size", 0, wallet.getPoolSize(Pool.PENDING)); assertEquals("Incorrect confirmed tx UNSPENT pool size", 1, wallet.getPoolSize(Pool.UNSPENT)); assertEquals("Incorrect confirmed tx ALL pool size", 1, wallet.getTransactions(true).size()); Threading.waitForUserCode(); assertTrue(availFuture.isDone()); assertTrue(estimatedFuture.isDone()); assertTrue(depthFuture.isDone()); }