aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPieter Wuille <pieter.wuille@gmail.com>2019-02-16 15:49:36 -0800
committerPieter Wuille <pieter.wuille@gmail.com>2019-05-10 14:31:22 -0700
commit3135c1a2d2e2fb31bc362c848bd2456d576e408b (patch)
tree7208865e9fd0c744e70e6c30b4bffa9519b81e96 /src
parentfb90ec3c33e824f5abb6a68452c683d6ce8b3e4a (diff)
downloadbitcoin-3135c1a2d2e2fb31bc362c848bd2456d576e408b.tar.xz
Abstract out UpdatePSBTOutput from FillPSBT
Diffstat (limited to 'src')
-rw-r--r--src/psbt.cpp19
-rw-r--r--src/psbt.h6
-rw-r--r--src/wallet/psbtwallet.cpp11
3 files changed, 26 insertions, 10 deletions
diff --git a/src/psbt.cpp b/src/psbt.cpp
index 97bda51a63..2362d4d497 100644
--- a/src/psbt.cpp
+++ b/src/psbt.cpp
@@ -215,6 +215,25 @@ bool PSBTInputSigned(const PSBTInput& input)
return !input.final_script_sig.empty() || !input.final_script_witness.IsNull();
}
+void UpdatePSBTOutput(const SigningProvider& provider, PartiallySignedTransaction& psbt, int index)
+{
+ const CTxOut& out = psbt.tx->vout.at(index);
+ PSBTOutput& psbt_out = psbt.outputs.at(index);
+
+ // Fill a SignatureData with output info
+ SignatureData sigdata;
+ psbt_out.FillSignatureData(sigdata);
+
+ // Construct a would-be spend of this output, to update sigdata with.
+ // Note that ProduceSignature is used to fill in metadata (not actual signatures),
+ // so provider does not need to provide any private keys (it can be a HidingSigningProvider).
+ MutableTransactionSignatureCreator creator(psbt.tx.get_ptr(), /* index */ 0, out.nValue, SIGHASH_ALL);
+ ProduceSignature(provider, creator, out.scriptPubKey, sigdata);
+
+ // Put redeem_script, witness_script, key paths, into PSBTOutput.
+ psbt_out.FromSignatureData(sigdata);
+}
+
bool SignPSBTInput(const SigningProvider& provider, PartiallySignedTransaction& psbt, int index, int sighash, SignatureData* out_sigdata, bool use_dummy)
{
PSBTInput& input = psbt.inputs.at(index);
diff --git a/src/psbt.h b/src/psbt.h
index 1bc1e91a84..f3840b9ed3 100644
--- a/src/psbt.h
+++ b/src/psbt.h
@@ -565,6 +565,12 @@ bool PSBTInputSigned(const PSBTInput& input);
/** Signs a PSBTInput, verifying that all provided data matches what is being signed. */
bool SignPSBTInput(const SigningProvider& provider, PartiallySignedTransaction& psbt, int index, int sighash = SIGHASH_ALL, SignatureData* out_sigdata = nullptr, bool use_dummy = false);
+/** Updates a PSBTOutput with information from provider.
+ *
+ * This fills in the redeem_script, witness_script, and hd_keypaths where possible.
+ */
+void UpdatePSBTOutput(const SigningProvider& provider, PartiallySignedTransaction& psbt, int index);
+
/**
* Finalizes a PSBT if possible, combining partial signatures.
*
diff --git a/src/wallet/psbtwallet.cpp b/src/wallet/psbtwallet.cpp
index 1b17b09763..ebc48795a0 100644
--- a/src/wallet/psbtwallet.cpp
+++ b/src/wallet/psbtwallet.cpp
@@ -44,16 +44,7 @@ TransactionError FillPSBT(const CWallet* pwallet, PartiallySignedTransaction& ps
// Fill in the bip32 keypaths and redeemscripts for the outputs so that hardware wallets can identify change
for (unsigned int i = 0; i < psbtx.tx->vout.size(); ++i) {
- const CTxOut& out = psbtx.tx->vout.at(i);
- PSBTOutput& psbt_out = psbtx.outputs.at(i);
-
- // Fill a SignatureData with output info
- SignatureData sigdata;
- psbt_out.FillSignatureData(sigdata);
-
- MutableTransactionSignatureCreator creator(psbtx.tx.get_ptr(), 0, out.nValue, 1);
- ProduceSignature(HidingSigningProvider(pwallet, true, !bip32derivs), creator, out.scriptPubKey, sigdata);
- psbt_out.FromSignatureData(sigdata);
+ UpdatePSBTOutput(HidingSigningProvider(pwallet, true, !bip32derivs), psbtx, i);
}
return TransactionError::OK;