本文整理汇总了Java中org.bitcoinj.core.Transaction.addInput方法的典型用法代码示例。如果您正苦于以下问题:Java Transaction.addInput方法的具体用法?Java Transaction.addInput怎么用?Java Transaction.addInput使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bitcoinj.core.Transaction
的用法示例。
在下文中一共展示了Transaction.addInput方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: childPaysForParent
import org.bitcoinj.core.Transaction; //导入方法依赖的package包/类
/**
* Construct a SendRequest for a CPFP (child-pays-for-parent) transaction. The resulting transaction is already
* completed, so you should directly proceed to signing and broadcasting/committing the transaction. CPFP is
* currently only supported by a few miners, so use with care.
*/
public static SendRequest childPaysForParent(Wallet wallet, Transaction parentTransaction, Coin feeRaise) {
TransactionOutput outputToSpend = null;
for (final TransactionOutput output : parentTransaction.getOutputs()) {
if (output.isMine(wallet) && output.isAvailableForSpending()
&& output.getValue().isGreaterThan(feeRaise)) {
outputToSpend = output;
break;
}
}
// TODO spend another confirmed output of own wallet if needed
checkNotNull(outputToSpend, "Can't find adequately sized output that spends to us");
final Transaction tx = new Transaction(parentTransaction.getParams());
tx.addInput(outputToSpend);
tx.addOutput(outputToSpend.getValue().subtract(feeRaise), wallet.freshAddress(KeyPurpose.CHANGE));
tx.setPurpose(Transaction.Purpose.RAISE_FEE);
final SendRequest req = forTx(tx);
req.completed = true;
return req;
}
示例2: sendBroadcastAnnouncement
import org.bitcoinj.core.Transaction; //导入方法依赖的package包/类
public void sendBroadcastAnnouncement(BroadcastAnnouncement ba, File f, ProofMessage pm, int lockTime) throws InsufficientMoneyException {
//build transaction
Transaction tx = new Transaction(params);
Script s = ba.buildScript();
System.out.println("Script size is " + s.SIG_SIZE);
//System.out.println(s.getScriptType());
ECKey psnymKey = new ECKey();
long unixTime = System.currentTimeMillis() / 1000L;
//TODO use bitcoin nets median time
tx.setLockTime(CLTVScriptPair.currentBitcoinBIP113Time(bc)-1);
CLTVScriptPair sp = new CLTVScriptPair(psnymKey, CLTVScriptPair.currentBitcoinBIP113Time(bc)+lockTime);
w.importKey(psnymKey);
tx.addOutput(new TransactionOutput(params, tx, pm.getLastTransactionOutput().getValue().subtract(estimateBroadcastFee()), sp.getPubKeyScript().getProgram()));
tx.addOutput(Coin.ZERO, s);
tx.addInput(pm.getLastTransactionOutput());
tx.getInput(0).setSequenceNumber(3); //the concrete value doesn't matter, this is just for cltv
tx.getInput(0).setScriptSig(pm.getScriptPair().calculateSigScript(tx, 0, w));
try {
w.commitTx(tx);
w.saveToFile(f);
} catch (IOException e1) {
e1.printStackTrace();
}
TransactionBroadcast broadcast = pg.broadcastTransaction(tx);
pm.addTransaction(tx, 0, sp);
pm.writeToFile();
System.out.println("save broadcast announcement to file");
}
示例3: doRaiseFee
import org.bitcoinj.core.Transaction; //导入方法依赖的package包/类
private void doRaiseFee(final KeyParameter encryptionKey) {
// construct child-pays-for-parent
final TransactionOutput outputToSpend = checkNotNull(findSpendableOutput(wallet, transaction, feeRaise));
final Transaction transactionToSend = new Transaction(Constants.NETWORK_PARAMETERS);
transactionToSend.addInput(outputToSpend);
transactionToSend.addOutput(outputToSpend.getValue().subtract(feeRaise),
wallet.freshAddress(KeyPurpose.CHANGE));
transactionToSend.setPurpose(Transaction.Purpose.RAISE_FEE);
final SendRequest sendRequest = SendRequest.forTx(transactionToSend);
sendRequest.aesKey = encryptionKey;
try {
wallet.signTransaction(sendRequest);
log.info("raise fee: cpfp {}", transactionToSend);
wallet.commitTx(transactionToSend);
application.broadcastTransaction(transactionToSend);
state = State.DONE;
updateView();
dismiss();
} catch (final KeyCrypterException x) {
badPasswordView.setVisibility(View.VISIBLE);
state = State.INPUT;
updateView();
passwordView.requestFocus();
log.info("raise fee: bad spending password");
}
}
示例4: addSuppliedInputs
import org.bitcoinj.core.Transaction; //导入方法依赖的package包/类
private void addSuppliedInputs(Transaction tx, List<TransactionInput> originalInputs) {
for (TransactionInput input : originalInputs)
tx.addInput(new TransactionInput(params, tx, input.bitcoinSerialize()));
}
示例5: rekeyOneBatch
import org.bitcoinj.core.Transaction; //导入方法依赖的package包/类
@Nullable
private Transaction rekeyOneBatch(long timeSecs, @Nullable KeyParameter aesKey, List<Transaction> others, boolean sign) {
lock.lock();
try {
// Build the transaction using some custom logic for our special needs. Last parameter to
// KeyTimeCoinSelector is whether to ignore pending transactions or not.
//
// We ignore pending outputs because trying to rotate these is basically racing an attacker, and
// we're quite likely to lose and create stuck double spends. Also, some users who have 0.9 wallets
// have already got stuck double spends in their wallet due to the Bloom-filtering block reordering
// bug that was fixed in 0.10, thus, making a re-key transaction depend on those would cause it to
// never confirm at all.
CoinSelector keyTimeSelector = new KeyTimeCoinSelector(this, timeSecs, true);
FilteringCoinSelector selector = new FilteringCoinSelector(keyTimeSelector);
for (Transaction other : others)
selector.excludeOutputsSpentBy(other);
// TODO: Make this use the standard SendRequest.
CoinSelection toMove = selector.select(Coin.ZERO, calculateAllSpendCandidates());
if (toMove.valueGathered.equals(Coin.ZERO)) return null; // Nothing to do.
maybeUpgradeToHD(aesKey);
Transaction rekeyTx = new Transaction(params);
for (TransactionOutput output : toMove.gathered) {
rekeyTx.addInput(output);
}
// When not signing, don't waste addresses.
rekeyTx.addOutput(toMove.valueGathered, sign ? freshReceiveAddress() : currentReceiveAddress());
if (!adjustOutputDownwardsForFee(rekeyTx, toMove, Transaction.DEFAULT_TX_FEE, true)) {
log.error("Failed to adjust rekey tx for fees.");
return null;
}
rekeyTx.getConfidence().setSource(TransactionConfidence.Source.SELF);
rekeyTx.setPurpose(Transaction.Purpose.KEY_ROTATION);
SendRequest req = SendRequest.forTx(rekeyTx);
req.aesKey = aesKey;
if (sign)
signTransaction(req);
// KeyTimeCoinSelector should never select enough inputs to push us oversize.
checkState(rekeyTx.unsafeBitcoinSerialize().length < Transaction.MAX_STANDARD_TX_SIZE);
return rekeyTx;
} catch (VerificationException e) {
throw new RuntimeException(e); // Cannot happen.
} finally {
lock.unlock();
}
}