diff options
author | Andrew Chow <achow101-github@achow101.com> | 2018-06-28 18:56:34 -0700 |
---|---|---|
committer | Andrew Chow <achow101-github@achow101.com> | 2018-07-13 14:27:31 -0700 |
commit | 8b5ef2793748065727a9a2498805ae5b269dcb4f (patch) | |
tree | 66d4ffbac5555defeb41c4dd6118ad73998634d4 /src | |
parent | 58a8e28918025c28f19ba19cbaa4a72374162942 (diff) |
SignPSBTInput wrapper function
The SignPSBTInput function takes a PSBTInput, SignatureData, SigningProvider,
and other data necessary for signing. It fills the SignatureData with data from
the PSBTInput, retrieves the UTXO from the PSBTInput, signs and finalizes the
input if possible, and then extracts the results from the SignatureData and
puts them back into the PSBTInput.
Diffstat (limited to 'src')
-rw-r--r-- | src/script/sign.cpp | 26 | ||||
-rw-r--r-- | src/script/sign.h | 3 |
2 files changed, 29 insertions, 0 deletions
diff --git a/src/script/sign.cpp b/src/script/sign.cpp index 28dfdecdfc..f9907f5e00 100644 --- a/src/script/sign.cpp +++ b/src/script/sign.cpp @@ -234,6 +234,32 @@ bool ProduceSignature(const SigningProvider& provider, const BaseSignatureCreato return sigdata.complete; } +bool SignPSBTInput(const SigningProvider& provider, const CMutableTransaction& tx, PSBTInput& input, SignatureData& sigdata, int index, int sighash) +{ + // if this input has a final scriptsig or scriptwitness, don't do anything with it + if (!input.final_script_sig.empty() || !input.final_script_witness.IsNull()) { + return true; + } + + // Fill SignatureData with input info + input.FillSignatureData(sigdata); + + // Get UTXO + CTxOut utxo; + if (input.non_witness_utxo) { + utxo = input.non_witness_utxo->vout[tx.vin[index].prevout.n]; + } else if (!input.witness_utxo.IsNull()) { + utxo = input.witness_utxo; + } else { + return false; + } + + MutableTransactionSignatureCreator creator(&tx, index, utxo.nValue, sighash); + bool sig_complete = ProduceSignature(provider, creator, utxo.scriptPubKey, sigdata); + input.FromSignatureData(sigdata); + return sig_complete; +} + class SignatureExtractorChecker final : public BaseSignatureChecker { private: diff --git a/src/script/sign.h b/src/script/sign.h index ab2153e3b9..9f0382e257 100644 --- a/src/script/sign.h +++ b/src/script/sign.h @@ -634,6 +634,9 @@ bool ProduceSignature(const SigningProvider& provider, const BaseSignatureCreato bool SignSignature(const SigningProvider &provider, const CScript& fromPubKey, CMutableTransaction& txTo, unsigned int nIn, const CAmount& amount, int nHashType); bool SignSignature(const SigningProvider &provider, const CTransaction& txFrom, CMutableTransaction& txTo, unsigned int nIn, int nHashType); +/** Signs a PSBTInput */ +bool SignPSBTInput(const SigningProvider& provider, const CMutableTransaction& tx, PSBTInput& input, SignatureData& sigdata, int index, int sighash = 1); + /** Extract signature data from a transaction input, and insert it. */ SignatureData DataFromTransaction(const CMutableTransaction& tx, unsigned int nIn, const CTxOut& txout); void UpdateInput(CTxIn& input, const SignatureData& data); |