org.bitcoinj.core.Transaction.addInput()方法的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(8.4k)|赞(0)|评价(0)|浏览(130)

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

Transaction.addInput介绍

[英]Creates and adds an input to this transaction, with no checking that it's valid.
[中]创建并向该事务添加输入,而不检查其是否有效。

代码示例

代码示例来源:origin: Coinomi/coinomi-android

private static void resetTxInputs(Transaction tx, List<TransactionInput> originalInputs) {
    tx.clearInputs();
    for (TransactionInput input : originalInputs)
      tx.addInput(input);
  }
}

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

private void resetTxInputs(SendRequest req, List<TransactionInput> originalInputs) {
  req.tx.clearInputs();
  for (TransactionInput input : originalInputs)
    req.tx.addInput(input);
}

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

/**
 * Adds an input to this transaction that imports value from the given output. Note that this input is <i>not</i>
 * complete and after every input is added with {@link #addInput()} and every output is added with
 * {@link #addOutput()}, a {@link TransactionSigner} must be used to finalize the transaction and finish the inputs
 * off. Otherwise it won't be accepted by the network.
 * @return the newly created input.
 */
public TransactionInput addInput(TransactionOutput from) {
  return addInput(new TransactionInput(params, this, from));
}

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

/**
 * Adds an input to this transaction that imports value from the given output. Note that this input is <i>not</i>
 * complete and after every input is added with {@link #addInput()} and every output is added with
 * {@link #addOutput()}, a {@link TransactionSigner} must be used to finalize the transaction and finish the inputs
 * off. Otherwise it won't be accepted by the network.
 * @return the newly created input.
 */
public TransactionInput addInput(TransactionOutput from) {
  return addInput(new TransactionInput(params, this, from));
}

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

/**
 * Adds an input to this transaction that imports value from the given output. Note that this input is <i>not</i>
 * complete and after every input is added with {@link #addInput(TransactionInput)} and every output is added with
 * {@link #addOutput(TransactionOutput)}, a {@link TransactionSigner} must be used to finalize the transaction and
 * finish the inputs off. Otherwise it won't be accepted by the network.
 * @return the newly created input.
 */
public TransactionInput addInput(TransactionOutput from) {
  return addInput(new TransactionInput(params, this, from));
}

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

/**
 * Creates and adds an input to this transaction, with no checking that it's valid.
 * @return the newly created input.
 */
public TransactionInput addInput(Sha256Hash spendTxHash, long outputIndex, Script script) {
  return addInput(
      new TransactionInput(
          params,
          this,
          script.getProgram(),
          new TransactionOutPoint(params, outputIndex, spendTxHash)));
}

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

/**
 * Creates and adds an input to this transaction, with no checking that it's valid.
 * @return the newly created input.
 */
public TransactionInput addInput(Sha256Hash spendTxHash, long outputIndex, Script script) {
  return addInput(new TransactionInput(params, this, script.getProgram(), new TransactionOutPoint(params, outputIndex, spendTxHash)));
}

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

/**
 * Creates and adds an input to this transaction, with no checking that it's valid.
 * @return the newly created input.
 */
public TransactionInput addInput(Sha256Hash spendTxHash, long outputIndex, Script script) {
  return addInput(new TransactionInput(params, this, script.getProgram(), new TransactionOutPoint(params, outputIndex, spendTxHash)));
}

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

private synchronized Transaction makeUnsignedChannelContract(Coin valueToMe) throws ValueOutOfRangeException {
  Transaction tx = new Transaction(wallet.getParams());
  tx.addInput(getContractInternal().getOutput(0));
  // Our output always comes first.
  // TODO: We should drop myKey in favor of output key + multisig key separation
  // (as its always obvious who the client is based on T2 output order)
  tx.addOutput(valueToMe, myKey.toAddress(wallet.getParams()));
  return tx;
}

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

private synchronized Transaction makeUnsignedChannelContract(Coin valueToMe) throws ValueOutOfRangeException {
  Transaction tx = new Transaction(wallet.getParams());
  tx.addInput(getContractInternal().getOutput(0));
  // Our output always comes first.
  // TODO: We should drop myKey in favor of output key + multisig key separation
  // (as its always obvious who the client is based on T2 output order)
  tx.addOutput(valueToMe, myKey.toAddress(wallet.getParams()));
  return tx;
}

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

private synchronized Transaction makeUnsignedChannelContract(Coin valueToMe) throws ValueOutOfRangeException {
  Transaction tx = new Transaction(wallet.getParams());
  tx.addInput(getContractInternal().getOutput(0));
  // Our output always comes first.
  // TODO: We should drop myKey in favor of output key + multisig key separation
  // (as its always obvious who the client is based on T2 output order)
  tx.addOutput(valueToMe, myKey.toAddress(wallet.getParams()));
  return tx;
}

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

private synchronized Transaction makeUnsignedChannelContract(Coin valueToMe) throws ValueOutOfRangeException {
  Transaction tx = new Transaction(wallet.getParams());
  tx.addInput(getContractInternal().getOutput(0));
  // Our output always comes first.
  // TODO: We should drop myKey in favor of output key + multisig key separation
  // (as its always obvious who the client is based on T2 output order)
  tx.addOutput(valueToMe, myKey.toAddress(wallet.getParams()));
  return tx;
}

代码示例来源:origin: blockchain/thunder

public Transaction getClosingTransaction (ChannelStatus channelStatus, float feePerByte) {
  //For the sake of privacy (and simplicity) we use lexicographically ordering here, as defined in BIP69
  Transaction transaction = new Transaction(Constants.getNetwork());
  transaction.addInput(channel.anchorTxHash, 0, Tools.getDummyScript());
  //TODO deduct the transaction fee correctly from both amounts
  //TODO would be better to have another address on file that we can use here..
  long feePerParty = (Tools.getTransactionFees(2, 2, feePerByte) / 2);
  transaction.addOutput(Coin.valueOf(channelStatus.amountClient - feePerParty), channel.channelStatus.addressClient);
  transaction.addOutput(Coin.valueOf(channelStatus.amountServer - feePerParty), channel.channelStatus.addressServer);
  return Tools.applyBIP69(transaction);
}

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

@Test(expected = VerificationException.CoinbaseScriptSizeOutOfRange.class)
public void coinbaseScriptSigTooSmall() throws Exception {
  tx.clearInputs();
  tx.addInput(Sha256Hash.ZERO_HASH, 0xFFFFFFFFL, new ScriptBuilder().build());
  tx.verify();
}

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

@Test(expected = VerificationException.UnexpectedCoinbaseInput.class)
public void coinbaseInputInNonCoinbaseTX() throws Exception {
  tx.addInput(Sha256Hash.ZERO_HASH, 0xFFFFFFFFL, new ScriptBuilder().data(new byte[10]).build());
  tx.verify();
}

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

protected synchronized SendRequest makeUnsignedChannelContract(Coin valueToMe) {
  Transaction tx = new Transaction(wallet.getParams());
  if (!getTotalValue().subtract(valueToMe).equals(Coin.ZERO)) {
    tx.addOutput(getTotalValue().subtract(valueToMe), getClientKey().toAddress(wallet.getParams()));
  }
  tx.addInput(contract.getOutput(0));
  return SendRequest.forTx(tx);
}

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

protected synchronized SendRequest makeUnsignedChannelContract(Coin valueToMe) {
  Transaction tx = new Transaction(wallet.getParams());
  if (!getTotalValue().subtract(valueToMe).equals(Coin.ZERO)) {
    tx.addOutput(getTotalValue().subtract(valueToMe), getClientKey().toAddress(wallet.getParams()));
  }
  tx.addInput(contract.getOutput(0));
  return SendRequest.forTx(tx);
}

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

/** Create a fake transaction, without change. */
public static Transaction createFakeTxWithoutChange(final NetworkParameters params, final TransactionOutput output) {
  Transaction prevTx = FakeTxBuilder.createFakeTx(params, Coin.COIN, new ECKey().toAddress(params));
  Transaction tx = new Transaction(params);
  tx.addOutput(output);
  tx.addInput(prevTx.getOutput(0));
  return tx;
}

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

protected synchronized SendRequest makeUnsignedChannelContract(Coin valueToMe) {
  Transaction tx = new Transaction(wallet.getParams());
  if (!getTotalValue().subtract(valueToMe).equals(Coin.ZERO)) {
    tx.addOutput(getTotalValue().subtract(valueToMe), getClientKey().toAddress(wallet.getParams()));
  }
  tx.addInput(contract.getOutput(0));
  return SendRequest.forTx(tx);
}

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

@Test(expected = VerificationException.CoinbaseScriptSizeOutOfRange.class)
public void coinbaseScriptSigTooLarge() throws Exception {
  tx.clearInputs();
  TransactionInput input = tx.addInput(Sha256Hash.ZERO_HASH, 0xFFFFFFFFL, new ScriptBuilder().data(new byte[99]).build());
  assertEquals(101, input.getScriptBytes().length);
  tx.verify();
}

相关文章

微信公众号

最新文章

更多

Transaction类方法