本文整理汇总了Java中org.bitcoinj.script.Script.getScriptSigWithSignature方法的典型用法代码示例。如果您正苦于以下问题:Java Script.getScriptSigWithSignature方法的具体用法?Java Script.getScriptSigWithSignature怎么用?Java Script.getScriptSigWithSignature使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bitcoinj.script.Script
的用法示例。
在下文中一共展示了Script.getScriptSigWithSignature方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: signInputs
import org.bitcoinj.script.Script; //导入方法依赖的package包/类
@Override
public boolean signInputs(ProposedTransaction propTx, KeyBag keyBag) {
Transaction tx = propTx.partialTx;
int numInputs = tx.getInputs().size();
for (int i = 0; i < numInputs; i++) {
TransactionInput txIn = tx.getInput(i);
TransactionOutput txOut = txIn.getConnectedOutput();
if (txOut == null) {
continue;
}
Script scriptPubKey = txOut.getScriptPubKey();
if (!scriptPubKey.isPayToScriptHash()) {
log.warn("CustomTransactionSigner works only with P2SH transactions");
return false;
}
Script inputScript = checkNotNull(txIn.getScriptSig());
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) {
// Expected.
}
RedeemData redeemData = txIn.getConnectedRedeemData(keyBag);
if (redeemData == null) {
log.warn("No redeem data found for input {}", i);
continue;
}
Sha256Hash sighash = tx.hashForSignature(i, redeemData.redeemScript, Transaction.SigHash.ALL, false);
SignatureAndKey sigKey = getSignature(sighash, propTx.keyPaths.get(scriptPubKey));
TransactionSignature txSig = new TransactionSignature(sigKey.sig, Transaction.SigHash.ALL, false);
int sigIndex = inputScript.getSigInsertionIndex(sighash, sigKey.pubKey);
inputScript = scriptPubKey.getScriptSigWithSignature(inputScript, txSig.encodeToBitcoin(), sigIndex);
txIn.setScriptSig(inputScript);
}
return true;
}