org.bitcoinj.wallet.Wallet.getBalanceFuture()方法的使用及代码示例

x33g5p2x  于2022-02-03 转载在 其他  
字(4.4k)|赞(0)|评价(0)|浏览(106)

本文整理了Java中org.bitcoinj.wallet.Wallet.getBalanceFuture()方法的一些代码示例,展示了Wallet.getBalanceFuture()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Wallet.getBalanceFuture()方法的具体详情如下:
包路径:org.bitcoinj.wallet.Wallet
类名称:Wallet
方法名:getBalanceFuture

Wallet.getBalanceFuture介绍

[英]Returns a future that will complete when the balance of the given type has becom equal or larger to the given value. If the wallet already has a large enough balance the future is returned in a pre-completed state. Note that this method is not blocking, if you want to actually wait immediately, you have to call .get() on the result.

Also note that by the time the future completes, the wallet may have changed yet again if something else is going on in parallel, so you should treat the returned balance as advisory and be prepared for sending money to fail! Finally please be aware that any listeners on the future will run either on the calling thread if it completes immediately, or eventually on a background thread if the balance is not yet at the right level. If you do something that means you know the balance should be sufficient to trigger the future, you can use org.bitcoinj.utils.Threading#waitForUserCode() to block until the future had a chance to be updated.
[中]返回当给定类型的余额等于或大于给定值时将完成的未来。如果钱包已经有足够大的余额,未来将以预先完成的状态返回。注意,这个方法不是阻塞的,如果你真的想立即等待,你必须调用。获取()结果。
还要注意的是,当未来完成时,如果其他事情同时发生,钱包可能已经再次发生变化,因此你应该将返回的余额视为建议,并做好发送失败资金的准备!最后,请注意,未来的任何侦听器都将在调用线程上运行(如果它立即完成),或者最终在后台线程上运行(如果平衡尚未达到正确的水平)。如果你做的事情意味着你知道平衡应该足以触发未来,你可以使用org。比特币。乌提尔斯。线程#waitForUserCode()阻止,直到将来有机会更新。

代码示例

代码示例来源:origin: HashEngineering/dashj

private void waitForSufficientBalance(Coin amount) {
    // Not enough money in the wallet.
    Coin amountPlusFee = amount.add(Transaction.REFERENCE_DEFAULT_MIN_TX_FEE);
    // ESTIMATED because we don't really need to wait for confirmation.
    ListenableFuture<Coin> balanceFuture = appKit.wallet().getBalanceFuture(amountPlusFee, Wallet.BalanceType.ESTIMATED);
    if (!balanceFuture.isDone()) {
      System.out.println("Please send " + amountPlusFee.toFriendlyString() +
          " to " + myKey.toAddress(params));
      Futures.getUnchecked(balanceFuture);
    }
  }
}

代码示例来源:origin: HashEngineering/dashj

ListenableFuture<Coin> balanceFuture = kit.wallet().getBalanceFuture(value, BalanceType.AVAILABLE);
FutureCallback<Coin> callback = new FutureCallback<Coin>() {
  @Override

代码示例来源:origin: HashEngineering/dashj

kit.wallet().getBalanceFuture(COIN, Wallet.BalanceType.AVAILABLE).get();
Transaction tx1 = kit.wallet().createSend(Address.fromBase58(params, "muYPFNCv7KQEG2ZLM7Z3y96kJnNyXJ53wm"), CENT);
Transaction tx2 = kit.wallet().createSend(Address.fromBase58(params, "muYPFNCv7KQEG2ZLM7Z3y96kJnNyXJ53wm"), CENT.add(SATOSHI.multiply(10)));

代码示例来源:origin: HashEngineering/dashj

System.out.println("Send some money to " + kit.wallet().currentReceiveAddress());
System.out.println("... and wait for it to confirm");
kit.wallet().getBalanceFuture(feeToTest, Wallet.BalanceType.AVAILABLE).get();

代码示例来源:origin: greenaddress/GreenBits

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());
}

相关文章

微信公众号

最新文章

更多

Wallet类方法