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

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

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

Wallet.setCoinSelector介绍

[英]A coin selector is responsible for choosing which outputs to spend when creating transactions. The default selector implements a policy of spending transactions that appeared in the best chain and pending transactions that were created by this wallet, but not others. You can override the coin selector for any given send operation by changing SendRequest#coinSelector.
[中]硬币选择器负责在创建交易时选择要花费的输出。默认选择器实现一个策略,即支出出现在最佳链中的交易,以及由该钱包创建的待定交易,但不包括其他交易。通过更改SendRequest#coinSelector,可以覆盖任何给定发送操作的硬币选择器。

代码示例

代码示例来源:origin: cash.bitcoinj/bitcoinj-core

/**
 * Convenience wrapper for <tt>setCoinSelector(Wallet.AllowUnconfirmedCoinSelector.get())</tt>. If this method
 * is called on the wallet then transactions will be used for spending regardless of their confidence. This can
 * be dangerous - only use this if you absolutely know what you're doing!
 */
public void allowSpendingUnconfirmedTransactions() {
  setCoinSelector(AllowUnconfirmedCoinSelector.get());
}

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

/**
 * Convenience wrapper for <tt>setCoinSelector(Wallet.AllowUnconfirmedCoinSelector.get())</tt>. If this method
 * is called on the wallet then transactions will be used for spending regardless of their confidence. This can
 * be dangerous - only use this if you absolutely know what you're doing!
 */
public void allowSpendingUnconfirmedTransactions() {
  setCoinSelector(AllowUnconfirmedCoinSelector.get());
}

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

/**
 * Convenience wrapper for <tt>setCoinSelector(Wallet.AllowUnconfirmedCoinSelector.get())</tt>. If this method
 * is called on the wallet then transactions will be used for spending regardless of their confidence. This can
 * be dangerous - only use this if you absolutely know what you're doing!
 */
public void allowSpendingUnconfirmedTransactions() {
  setCoinSelector(AllowUnconfirmedCoinSelector.get());
}

代码示例来源:origin: fr.acinq/bitcoinj-core

/**
 * Convenience wrapper for <tt>setCoinSelector(Wallet.AllowUnconfirmedCoinSelector.get())</tt>. If this method
 * is called on the wallet then transactions will be used for spending regardless of their confidence. This can
 * be dangerous - only use this if you absolutely know what you're doing!
 */
public void allowSpendingUnconfirmedTransactions() {
  setCoinSelector(AllowUnconfirmedCoinSelector.get());
}

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

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

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

assertTrue(sortedTxns.indexOf(send2b) < sortedTxns.indexOf(send2c));
} finally {
  wallet.setCoinSelector(originalCoinSelector);

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

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

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

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

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

@Test
public void testStandardWalletDisconnect() throws Exception {
  NetworkParameters params = UnitTestParams.get();
  Wallet w = new Wallet(new Context(params));
  w.setCoinSelector(new AllowUnconfirmedCoinSelector());
  Address a = w.currentReceiveAddress();
  Transaction tx1 = FakeTxBuilder.createFakeTxWithoutChangeAddress(params, Coin.COIN, a);
  w.receivePending(tx1, null);
  Transaction tx2 = new Transaction(params);
  tx2.addOutput(Coin.valueOf(99000000), new ECKey());
  w.completeTx(SendRequest.forTx(tx2));
  TransactionInput txInToDisconnect = tx2.getInput(0);
  assertEquals(tx1, txInToDisconnect.getOutpoint().fromTx);
  assertNull(txInToDisconnect.getOutpoint().connectedOutput);
  txInToDisconnect.disconnect();
  assertNull(txInToDisconnect.getOutpoint().fromTx);
  assertNull(txInToDisconnect.getOutpoint().connectedOutput);
}

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

assertDead(txD2);
} finally {
  wallet.setCoinSelector(originalCoinSelector);

相关文章

微信公众号

最新文章

更多

Wallet类方法