当前位置: 首页>>代码示例>>Java>>正文


Java SendRequest.forTx方法代码示例

本文整理汇总了Java中com.google.bitcoin.core.Wallet.SendRequest.forTx方法的典型用法代码示例。如果您正苦于以下问题:Java SendRequest.forTx方法的具体用法?Java SendRequest.forTx怎么用?Java SendRequest.forTx使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.bitcoin.core.Wallet.SendRequest的用法示例。


在下文中一共展示了SendRequest.forTx方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: customTransactionSpending

import com.google.bitcoin.core.Wallet.SendRequest; //导入方法依赖的package包/类
@Test
public void customTransactionSpending() throws Exception {
    // We'll set up a wallet that receives a coin, then sends a coin of lesser value and keeps the change.
    BigInteger v1 = Utils.toNanoCoins(3, 0);
    sendMoneyToWallet(v1, AbstractBlockChain.NewBlockType.BEST_CHAIN);
    assertEquals(v1, wallet.getBalance());
    assertEquals(1, wallet.getPoolSize(WalletTransaction.Pool.UNSPENT));
    assertEquals(1, wallet.getTransactions(true).size());

    ECKey k2 = new ECKey();
    Address a2 = k2.toAddress(params);
    BigInteger v2 = toNanoCoins(0, 50);
    BigInteger v3 = toNanoCoins(0, 75);
    BigInteger v4 = toNanoCoins(1, 25);

    Transaction t2 = new Transaction(params);
    t2.addOutput(v2, a2);
    t2.addOutput(v3, a2);
    t2.addOutput(v4, a2);
    SendRequest req = SendRequest.forTx(t2);
    req.ensureMinRequiredFee = false;
    wallet.completeTx(req);

    // Do some basic sanity checks.
    assertEquals(1, t2.getInputs().size());
    assertEquals(myAddress, t2.getInputs().get(0).getScriptSig().getFromAddress(params));
    assertEquals(TransactionConfidence.ConfidenceType.UNKNOWN, t2.getConfidence().getConfidenceType());

    // We have NOT proven that the signature is correct!
    wallet.commitTx(t2);
    assertEquals(1, wallet.getPoolSize(WalletTransaction.Pool.PENDING));
    assertEquals(1, wallet.getPoolSize(WalletTransaction.Pool.SPENT));
    assertEquals(2, wallet.getTransactions(true).size());
}
 
开发者ID:HashEngineering,项目名称:megacoinj,代码行数:35,代码来源:WalletTest.java

示例2: spendOutputFromPendingTransaction

import com.google.bitcoin.core.Wallet.SendRequest; //导入方法依赖的package包/类
@Test
public void spendOutputFromPendingTransaction() throws Exception {
    // We'll set up a wallet that receives a coin, then sends a coin of lesser value and keeps the change.
    BigInteger v1 = Utils.toNanoCoins(1, 0);
    sendMoneyToWallet(v1, AbstractBlockChain.NewBlockType.BEST_CHAIN);
    // First create our current transaction
    ECKey k2 = new ECKey();
    wallet.addKey(k2);
    BigInteger v2 = toNanoCoins(0, 50);
    Transaction t2 = new Transaction(params);
    TransactionOutput o2 = new TransactionOutput(params, t2, v2, k2.toAddress(params));
    t2.addOutput(o2);
    SendRequest req = SendRequest.forTx(t2);
    req.ensureMinRequiredFee = false;
    wallet.completeTx(req);

    // Commit t2, so it is placed in the pending pool
    wallet.commitTx(t2);
    assertEquals(0, wallet.getPoolSize(WalletTransaction.Pool.UNSPENT));
    assertEquals(1, wallet.getPoolSize(WalletTransaction.Pool.PENDING));
    assertEquals(2, wallet.getTransactions(true).size());

    // Now try to the spend the output.
    ECKey k3 = new ECKey();
    BigInteger v3 = toNanoCoins(0, 25);
    Transaction t3 = new Transaction(params);
    t3.addOutput(v3, k3.toAddress(params));
    t3.addInput(o2);
    t3.signInputs(SigHash.ALL, wallet);

    // Commit t3, so the coins from the pending t2 are spent
    wallet.commitTx(t3);
    assertEquals(0, wallet.getPoolSize(WalletTransaction.Pool.UNSPENT));
    assertEquals(2, wallet.getPoolSize(WalletTransaction.Pool.PENDING));
    assertEquals(3, wallet.getTransactions(true).size());

    // Now the output of t2 must not be available for spending
    assertFalse(o2.isAvailableForSpending());
}
 
开发者ID:HashEngineering,项目名称:megacoinj,代码行数:40,代码来源:WalletTest.java

示例3: customTransactionSpending

import com.google.bitcoin.core.Wallet.SendRequest; //导入方法依赖的package包/类
@Test
public void customTransactionSpending() throws Exception {
    // We'll set up a wallet that receives a coin, then sends a coin of lesser value and keeps the change.
    BigInteger v1 = Utils.toNanoCoins(3, 0);
    sendMoneyToWallet(v1, AbstractBlockChain.NewBlockType.BEST_CHAIN);
    assertEquals(v1, wallet.getBalance());
    assertEquals(1, wallet.getPoolSize(WalletTransaction.Pool.UNSPENT));
    assertEquals(1, wallet.getPoolSize(WalletTransaction.Pool.ALL));

    ECKey k2 = new ECKey();
    Address a2 = k2.toAddress(params);
    BigInteger v2 = toNanoCoins(0, 50);
    BigInteger v3 = toNanoCoins(0, 75);
    BigInteger v4 = toNanoCoins(1, 25);

    Transaction t2 = new Transaction(params);
    t2.addOutput(v2, a2);
    t2.addOutput(v3, a2);
    t2.addOutput(v4, a2);
    SendRequest req = SendRequest.forTx(t2);
    req.ensureMinRequiredFee = false;
    boolean complete = wallet.completeTx(req);

    // Do some basic sanity checks.
    assertTrue(complete);
    assertEquals(1, t2.getInputs().size());
    assertEquals(myAddress, t2.getInputs().get(0).getScriptSig().getFromAddress(params));
    assertEquals(TransactionConfidence.ConfidenceType.UNKNOWN, t2.getConfidence().getConfidenceType());

    // We have NOT proven that the signature is correct!
    wallet.commitTx(t2);
    assertEquals(1, wallet.getPoolSize(WalletTransaction.Pool.PENDING));
    assertEquals(1, wallet.getPoolSize(WalletTransaction.Pool.SPENT));
    assertEquals(2, wallet.getPoolSize(WalletTransaction.Pool.ALL));
}
 
开发者ID:sserrano44,项目名称:bitcoinj-watcher-service,代码行数:36,代码来源:WalletTest.java

示例4: spendOutputFromPendingTransaction

import com.google.bitcoin.core.Wallet.SendRequest; //导入方法依赖的package包/类
@Test
public void spendOutputFromPendingTransaction() throws Exception {
    // We'll set up a wallet that receives a coin, then sends a coin of lesser value and keeps the change.
    BigInteger v1 = Utils.toNanoCoins(1, 0);
    sendMoneyToWallet(v1, AbstractBlockChain.NewBlockType.BEST_CHAIN);
    // First create our current transaction
    ECKey k2 = new ECKey();
    wallet.addKey(k2);
    BigInteger v2 = toNanoCoins(0, 50);
    Transaction t2 = new Transaction(params);
    TransactionOutput o2 = new TransactionOutput(params, t2, v2, k2.toAddress(params));
    t2.addOutput(o2);
    SendRequest req = SendRequest.forTx(t2);
    req.ensureMinRequiredFee = false;
    boolean complete = wallet.completeTx(req);
    assertTrue(complete);

    // Commit t2, so it is placed in the pending pool
    wallet.commitTx(t2);
    assertEquals(0, wallet.getPoolSize(WalletTransaction.Pool.UNSPENT));
    assertEquals(1, wallet.getPoolSize(WalletTransaction.Pool.PENDING));
    assertEquals(2, wallet.getPoolSize(WalletTransaction.Pool.ALL));

    // Now try to the spend the output.
    ECKey k3 = new ECKey();
    BigInteger v3 = toNanoCoins(0, 25);
    Transaction t3 = new Transaction(params);
    t3.addOutput(v3, k3.toAddress(params));
    t3.addInput(o2);
    t3.signInputs(SigHash.ALL, wallet);

    // Commit t3, so the coins from the pending t2 are spent
    wallet.commitTx(t3);
    assertEquals(0, wallet.getPoolSize(WalletTransaction.Pool.UNSPENT));
    assertEquals(2, wallet.getPoolSize(WalletTransaction.Pool.PENDING));
    assertEquals(3, wallet.getPoolSize(WalletTransaction.Pool.ALL));

    // Now the output of t2 must not be available for spending
    assertFalse(o2.isAvailableForSpending());
}
 
开发者ID:sserrano44,项目名称:bitcoinj-watcher-service,代码行数:41,代码来源:WalletTest.java


注:本文中的com.google.bitcoin.core.Wallet.SendRequest.forTx方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。