Changeset View
Changeset View
Standalone View
Standalone View
src/psbt.cpp
Show First 20 Lines • Show All 167 Lines • ▼ Show 20 Lines | |||||
} | } | ||||
bool PSBTInputSigned(PSBTInput &input) { | bool PSBTInputSigned(PSBTInput &input) { | ||||
return !input.final_script_sig.empty(); | return !input.final_script_sig.empty(); | ||||
} | } | ||||
bool SignPSBTInput(const SigningProvider &provider, | bool SignPSBTInput(const SigningProvider &provider, | ||||
PartiallySignedTransaction &psbt, int index, | PartiallySignedTransaction &psbt, int index, | ||||
SigHashType sighash) { | SigHashType sighash, SignatureData *out_sigdata, | ||||
bool use_dummy) { | |||||
PSBTInput &input = psbt.inputs.at(index); | PSBTInput &input = psbt.inputs.at(index); | ||||
const CMutableTransaction &tx = *psbt.tx; | const CMutableTransaction &tx = *psbt.tx; | ||||
if (PSBTInputSigned(input)) { | if (PSBTInputSigned(input)) { | ||||
return true; | return true; | ||||
} | } | ||||
// Fill SignatureData with input info | // Fill SignatureData with input info | ||||
SignatureData sigdata; | SignatureData sigdata; | ||||
input.FillSignatureData(sigdata); | input.FillSignatureData(sigdata); | ||||
// Get UTXO | // Get UTXO | ||||
CTxOut utxo; | CTxOut utxo; | ||||
// Verify input sanity | // Verify input sanity | ||||
if (!input.IsSane()) { | if (!input.IsSane()) { | ||||
return false; | return false; | ||||
} | } | ||||
if (input.utxo.IsNull()) { | if (input.utxo.IsNull()) { | ||||
return false; | return false; | ||||
} | } | ||||
utxo = input.utxo; | utxo = input.utxo; | ||||
bool sig_complete{false}; | |||||
if (use_dummy) { | |||||
sig_complete = ProduceSignature(provider, DUMMY_SIGNATURE_CREATOR, | |||||
utxo.scriptPubKey, sigdata); | |||||
} else { | |||||
MutableTransactionSignatureCreator creator(&tx, index, utxo.nValue, | MutableTransactionSignatureCreator creator(&tx, index, utxo.nValue, | ||||
sighash); | sighash); | ||||
bool sig_complete = | sig_complete = | ||||
ProduceSignature(provider, creator, utxo.scriptPubKey, sigdata); | ProduceSignature(provider, creator, utxo.scriptPubKey, sigdata); | ||||
} | |||||
input.FromSignatureData(sigdata); | input.FromSignatureData(sigdata); | ||||
// Fill in the missing info | |||||
if (out_sigdata != nullptr) { | |||||
out_sigdata->missing_pubkeys = sigdata.missing_pubkeys; | |||||
out_sigdata->missing_sigs = sigdata.missing_sigs; | |||||
out_sigdata->missing_redeem_script = sigdata.missing_redeem_script; | |||||
} | |||||
return sig_complete; | return sig_complete; | ||||
} | } | ||||
bool FinalizePSBT(PartiallySignedTransaction &psbtx) { | bool FinalizePSBT(PartiallySignedTransaction &psbtx) { | ||||
// Finalize input signatures -- in case we have partial signatures that add | // Finalize input signatures -- in case we have partial signatures that add | ||||
// up to a complete | // up to a complete | ||||
// signature, but have not combined them yet (e.g. because the combiner | // signature, but have not combined them yet (e.g. because the combiner | ||||
// that created this PartiallySignedTransaction did not understand them), | // that created this PartiallySignedTransaction did not understand them), | ||||
▲ Show 20 Lines • Show All 44 Lines • Show Last 20 Lines |