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.
This commit is contained in:
parent
58a8e28918
commit
8b5ef27937
2 changed files with 29 additions and 0 deletions
|
@ -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:
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Add table
Reference in a new issue