本文整理汇总了Java中org.bitcoinj.core.Transaction.getInputs方法的典型用法代码示例。如果您正苦于以下问题:Java Transaction.getInputs方法的具体用法?Java Transaction.getInputs怎么用?Java Transaction.getInputs使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bitcoinj.core.Transaction
的用法示例。
在下文中一共展示了Transaction.getInputs方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getTotalReceived
import org.bitcoinj.core.Transaction; //导入方法依赖的package包/类
/**
* Returns the amount of bitcoin ever received via output. <b>This is not the balance!</b> If an output spends from a
* transaction whose inputs are also to our wallet, the input amounts are deducted from the outputs contribution, with a minimum of zero
* contribution. The idea behind this is we avoid double counting money sent to us.
* @return the total amount of satoshis received, regardless of whether it was spent or not.
*/
public Coin getTotalReceived() {
Coin total = Coin.ZERO;
// Include outputs to us if they were not just change outputs, ie the inputs to us summed to less
// than the outputs to us.
for (Transaction tx: transactions.values()) {
Coin txTotal = Coin.ZERO;
for (TransactionOutput output : tx.getOutputs()) {
if (output.isMine(this)) {
txTotal = txTotal.add(output.getValue());
}
}
for (TransactionInput in : tx.getInputs()) {
TransactionOutput prevOut = in.getConnectedOutput();
if (prevOut != null && prevOut.isMine(this)) {
txTotal = txTotal.subtract(prevOut.getValue());
}
}
if (txTotal.isPositive()) {
total = total.add(txTotal);
}
}
return total;
}
示例2: isEntirelySelf
import org.bitcoinj.core.Transaction; //导入方法依赖的package包/类
public static boolean isEntirelySelf(final Transaction tx, final Wallet wallet) {
for (final TransactionInput input : tx.getInputs()) {
final TransactionOutput connectedOutput = input.getConnectedOutput();
if (connectedOutput == null || !connectedOutput.isMine(wallet))
return false;
}
for (final TransactionOutput output : tx.getOutputs()) {
if (!output.isMine(wallet))
return false;
}
return true;
}
示例3: isNotSpendingTxnsInConfidenceType
import org.bitcoinj.core.Transaction; //导入方法依赖的package包/类
/** Finds if tx is NOT spending other txns which are in the specified confidence type */
private boolean isNotSpendingTxnsInConfidenceType(Transaction tx, ConfidenceType confidenceType) {
for (TransactionInput txInput : tx.getInputs()) {
Transaction connectedTx = this.getTransaction(txInput.getOutpoint().getHash());
if (connectedTx != null && connectedTx.getConfidence().getConfidenceType().equals(confidenceType)) {
return false;
}
}
return true;
}
示例4: spends
import org.bitcoinj.core.Transaction; //导入方法依赖的package包/类
/** Finds whether txA spends txB */
boolean spends(Transaction txA, Transaction txB) {
for (TransactionInput txInput : txA.getInputs()) {
if (txInput.getOutpoint().getHash().equals(txB.getHash())) {
return true;
}
}
return false;
}
示例5: getTotalSent
import org.bitcoinj.core.Transaction; //导入方法依赖的package包/类
/**
* Returns the amount of bitcoin ever sent via output. If an output is sent to our own wallet, because of change or
* rotating keys or whatever, we do not count it. If the wallet was
* involved in a shared transaction, i.e. there is some input to the transaction that we don't have the key for, then
* we multiply the sum of the output values by the proportion of satoshi coming in to our inputs. Essentially we treat
* inputs as pooling into the transaction, becoming fungible and being equally distributed to all outputs.
* @return the total amount of satoshis sent by us
*/
public Coin getTotalSent() {
Coin total = Coin.ZERO;
for (Transaction tx: transactions.values()) {
// Count spent outputs to only if they were not to us. This means we don't count change outputs.
Coin txOutputTotal = Coin.ZERO;
for (TransactionOutput out : tx.getOutputs()) {
if (out.isMine(this) == false) {
txOutputTotal = txOutputTotal.add(out.getValue());
}
}
// Count the input values to us
Coin txOwnedInputsTotal = Coin.ZERO;
for (TransactionInput in : tx.getInputs()) {
TransactionOutput prevOut = in.getConnectedOutput();
if (prevOut != null && prevOut.isMine(this)) {
txOwnedInputsTotal = txOwnedInputsTotal.add(prevOut.getValue());
}
}
// If there is an input that isn't from us, i.e. this is a shared transaction
Coin txInputsTotal = tx.getInputSum();
if (txOwnedInputsTotal != txInputsTotal) {
// multiply our output total by the appropriate proportion to account for the inputs that we don't own
BigInteger txOutputTotalNum = new BigInteger(txOutputTotal.toString());
txOutputTotalNum = txOutputTotalNum.multiply(new BigInteger(txOwnedInputsTotal.toString()));
txOutputTotalNum = txOutputTotalNum.divide(new BigInteger(txInputsTotal.toString()));
txOutputTotal = Coin.valueOf(txOutputTotalNum.longValue());
}
total = total.add(txOutputTotal);
}
return total;
}
示例6: processTxFromBestChain
import org.bitcoinj.core.Transaction; //导入方法依赖的package包/类
/**
* Handle when a transaction becomes newly active on the best chain, either due to receiving a new block or a
* re-org. Places the tx into the right pool, handles coinbase transactions, handles double-spends and so on.
*/
private void processTxFromBestChain(Transaction tx, boolean forceAddToPool) throws VerificationException {
checkState(lock.isHeldByCurrentThread());
checkState(!pending.containsKey(tx.getHash()));
// This TX may spend our existing outputs even though it was not pending. This can happen in unit
// tests, if keys are moved between wallets, if we're catching up to the chain given only a set of keys,
// or if a dead coinbase transaction has moved back onto the main chain.
boolean isDeadCoinbase = tx.isCoinBase() && dead.containsKey(tx.getHash());
if (isDeadCoinbase) {
// There is a dead coinbase tx being received on the best chain. A coinbase tx is made dead when it moves
// to a side chain but it can be switched back on a reorg and resurrected back to spent or unspent.
// So take it out of the dead pool. Note that we don't resurrect dependent transactions here, even though
// we could. Bitcoin Core nodes on the network have deleted the dependent transactions from their mempools
// entirely by this point. We could and maybe should rebroadcast them so the network remembers and tries
// to confirm them again. But this is a deeply unusual edge case that due to the maturity rule should never
// happen in practice, thus for simplicities sake we ignore it here.
log.info(" coinbase tx <-dead: confidence {}", tx.getHashAsString(),
tx.getConfidence().getConfidenceType().name());
dead.remove(tx.getHash());
}
// Update tx and other unspent/pending transactions by connecting inputs/outputs.
updateForSpends(tx, true);
// Now make sure it ends up in the right pool. Also, handle the case where this TX is double-spending
// against our pending transactions. Note that a tx may double spend our pending transactions and also send
// us money/spend our money.
boolean hasOutputsToMe = tx.getValueSentToMe(this).signum() > 0;
boolean hasOutputsFromMe = false;
if (hasOutputsToMe) {
// Needs to go into either unspent or spent (if the outputs were already spent by a pending tx).
if (tx.isEveryOwnedOutputSpent(this)) {
log.info(" tx {} ->spent (by pending)", tx.getHashAsString());
addWalletTransaction(Pool.SPENT, tx);
} else {
log.info(" tx {} ->unspent", tx.getHashAsString());
addWalletTransaction(Pool.UNSPENT, tx);
}
} else if (tx.getValueSentFromMe(this).signum() > 0) {
hasOutputsFromMe = true;
// Didn't send us any money, but did spend some. Keep it around for record keeping purposes.
log.info(" tx {} ->spent", tx.getHashAsString());
addWalletTransaction(Pool.SPENT, tx);
} else if (forceAddToPool) {
// Was manually added to pending, so we should keep it to notify the user of confidence information
log.info(" tx {} ->spent (manually added)", tx.getHashAsString());
addWalletTransaction(Pool.SPENT, tx);
}
// Kill txns in conflict with this tx
Set<Transaction> doubleSpendTxns = findDoubleSpendsAgainst(tx, pending);
if (!doubleSpendTxns.isEmpty()) {
// no need to addTransactionsDependingOn(doubleSpendTxns) because killTxns() already kills dependencies;
killTxns(doubleSpendTxns, tx);
}
if (!hasOutputsToMe
&& !hasOutputsFromMe
&& !forceAddToPool
&& !findDoubleSpendsAgainst(tx, transactions).isEmpty())
{
// disconnect irrelevant inputs (otherwise might cause protobuf serialization issue)
for (TransactionInput input : tx.getInputs()) {
TransactionOutput output = input.getConnectedOutput();
if (output != null && !output.isMineOrWatched(this)) {
input.disconnect();
}
}
}
}
示例7: signTransaction
import org.bitcoinj.core.Transaction; //导入方法依赖的package包/类
/**
* <p>Given a send request containing transaction, attempts to sign it's inputs. This method expects transaction
* to have all necessary inputs connected or they will be ignored.</p>
* <p>Actual signing is done by pluggable {@link #signers} and it's not guaranteed that
* transaction will be complete in the end.</p>
*/
public void signTransaction(SendRequest req) {
lock.lock();
try {
Transaction tx = req.tx;
List<TransactionInput> inputs = tx.getInputs();
List<TransactionOutput> outputs = tx.getOutputs();
checkState(inputs.size() > 0);
checkState(outputs.size() > 0);
KeyBag maybeDecryptingKeyBag = new DecryptingKeyBag(this, req.aesKey);
int numInputs = tx.getInputs().size();
for (int i = 0; i < numInputs; i++) {
TransactionInput txIn = tx.getInput(i);
if (txIn.getConnectedOutput() == null) {
// Missing connected output, assuming already signed.
continue;
}
try {
// We assume if its already signed, its hopefully got a SIGHASH type that will not invalidate when
// we sign missing pieces (to check this would require either assuming any signatures are signing
// standard output types or a way to get processed signatures out of script execution)
txIn.getScriptSig().correctlySpends(tx, i, txIn.getConnectedOutput().getScriptPubKey());
log.warn("Input {} already correctly spends output, assuming SIGHASH type used will be safe and skipping signing.", i);
continue;
} catch (ScriptException e) {
log.debug("Input contained an incorrect signature", e);
// Expected.
}
Script scriptPubKey = txIn.getConnectedOutput().getScriptPubKey();
RedeemData redeemData = txIn.getConnectedRedeemData(maybeDecryptingKeyBag);
checkNotNull(redeemData, "Transaction exists in wallet that we cannot redeem: %s", txIn.getOutpoint().getHash());
txIn.setScriptSig(scriptPubKey.createEmptyInputScript(redeemData.keys.get(0), redeemData.redeemScript));
}
TransactionSigner.ProposedTransaction proposal = new TransactionSigner.ProposedTransaction(tx);
for (TransactionSigner signer : signers) {
if (!signer.signInputs(proposal, maybeDecryptingKeyBag))
log.info("{} returned false for the tx", signer.getClass().getName());
}
// resolve missing sigs if any
new MissingSigResolutionSigner(req.missingSigsMode).signInputs(proposal, maybeDecryptingKeyBag);
} finally {
lock.unlock();
}
}