Make SignPSBTInput operate on a private SignatureData object
This commit is contained in:
1 parent
cad5dd2368
commit
917353c8b0
4 files changed
+15
-15
No files matched your search
@@ -1641,8 +1641,7 @@ UniValue finalizepsbt(const JSONRPCRequest& request)
|
|||||||
for (unsigned int i = 0; i < psbtx.tx->vin.size(); ++i) {
|
for (unsigned int i = 0; i < psbtx.tx->vin.size(); ++i) {
|
||||||
PSBTInput& input = psbtx.inputs.at(i);
|
PSBTInput& input = psbtx.inputs.at(i);
|
||||||
|
|
||||||
SignatureData sigdata;
|
complete &= SignPSBTInput(DUMMY_SIGNING_PROVIDER, *psbtx.tx, input, i, 1);
|
||||||
complete &= SignPSBTInput(DUMMY_SIGNING_PROVIDER, *psbtx.tx, input, sigdata, i, 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
UniValue result(UniValue::VOBJ);
|
UniValue result(UniValue::VOBJ);
|
||||||
|
|||||||
+12
-1
@@ -237,7 +237,7 @@ bool ProduceSignature(const SigningProvider& provider, const BaseSignatureCreato
|
|||||||
return sigdata.complete;
|
return sigdata.complete;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SignPSBTInput(const SigningProvider& provider, const CMutableTransaction& tx, PSBTInput& input, SignatureData& sigdata, int index, int sighash)
|
bool SignPSBTInput(const SigningProvider& provider, const CMutableTransaction& tx, PSBTInput& input, int index, int sighash)
|
||||||
{
|
{
|
||||||
// if this input has a final scriptsig or scriptwitness, don't do anything with it
|
// 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()) {
|
if (!input.final_script_sig.empty() || !input.final_script_witness.IsNull()) {
|
||||||
@@ -245,6 +245,7 @@ bool SignPSBTInput(const SigningProvider& provider, const CMutableTransaction& t
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Fill SignatureData with input info
|
// Fill SignatureData with input info
|
||||||
|
SignatureData sigdata;
|
||||||
input.FillSignatureData(sigdata);
|
input.FillSignatureData(sigdata);
|
||||||
|
|
||||||
// Get UTXO
|
// Get UTXO
|
||||||
@@ -276,6 +277,16 @@ bool SignPSBTInput(const SigningProvider& provider, const CMutableTransaction& t
|
|||||||
// Verify that a witness signature was produced in case one was required.
|
// Verify that a witness signature was produced in case one was required.
|
||||||
if (require_witness_sig && !sigdata.witness) return false;
|
if (require_witness_sig && !sigdata.witness) return false;
|
||||||
input.FromSignatureData(sigdata);
|
input.FromSignatureData(sigdata);
|
||||||
|
|
||||||
|
// If both UTXO types are present, drop the unnecessary one.
|
||||||
|
if (input.non_witness_utxo && !input.witness_utxo.IsNull()) {
|
||||||
|
if (sigdata.witness) {
|
||||||
|
input.non_witness_utxo = nullptr;
|
||||||
|
} else {
|
||||||
|
input.witness_utxo.SetNull();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return sig_complete;
|
return sig_complete;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -696,7 +696,7 @@ bool SignSignature(const SigningProvider &provider, const CScript& fromPubKey, C
|
|||||||
bool SignSignature(const SigningProvider &provider, const CTransaction& txFrom, CMutableTransaction& txTo, unsigned int nIn, int nHashType);
|
bool SignSignature(const SigningProvider &provider, const CTransaction& txFrom, CMutableTransaction& txTo, unsigned int nIn, int nHashType);
|
||||||
|
|
||||||
/** Signs a PSBTInput, verifying that all provided data matches what is being signed. */
|
/** Signs a PSBTInput, verifying that all provided data matches what is being signed. */
|
||||||
bool SignPSBTInput(const SigningProvider& provider, const CMutableTransaction& tx, PSBTInput& input, SignatureData& sigdata, int index, int sighash = 1);
|
bool SignPSBTInput(const SigningProvider& provider, const CMutableTransaction& tx, PSBTInput& input, int index, int sighash = SIGHASH_ALL);
|
||||||
|
|
||||||
/** Extract signature data from a transaction input, and insert it. */
|
/** Extract signature data from a transaction input, and insert it. */
|
||||||
SignatureData DataFromTransaction(const CMutableTransaction& tx, unsigned int nIn, const CTxOut& txout);
|
SignatureData DataFromTransaction(const CMutableTransaction& tx, unsigned int nIn, const CTxOut& txout);
|
||||||
|
|||||||
@@ -4461,17 +4461,7 @@ bool FillPSBT(const CWallet* pwallet, PartiallySignedTransaction& psbtx, const C
|
|||||||
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Specified Sighash and sighash in PSBT do not match.");
|
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Specified Sighash and sighash in PSBT do not match.");
|
||||||
}
|
}
|
||||||
|
|
||||||
SignatureData sigdata;
|
complete &= SignPSBTInput(HidingSigningProvider(pwallet, !sign, !bip32derivs), *psbtx.tx, input, i, sighash_type);
|
||||||
complete &= SignPSBTInput(HidingSigningProvider(pwallet, !sign, !bip32derivs), *psbtx.tx, input, sigdata, i, sighash_type);
|
|
||||||
|
|
||||||
if (it != pwallet->mapWallet.end()) {
|
|
||||||
// Drop the unnecessary UTXO if we added both from the wallet.
|
|
||||||
if (sigdata.witness) {
|
|
||||||
input.non_witness_utxo = nullptr;
|
|
||||||
} else {
|
|
||||||
input.witness_utxo.SetNull();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fill in the bip32 keypaths and redeemscripts for the outputs so that hardware wallets can identify change
|
// Fill in the bip32 keypaths and redeemscripts for the outputs so that hardware wallets can identify change
|
||||||
|
|||||||
Reference in new issue
Block a user