diff options
author | MarcoFalke <falke.marco@gmail.com> | 2020-12-16 11:28:22 +0100 |
---|---|---|
committer | MarcoFalke <falke.marco@gmail.com> | 2020-12-19 09:45:39 +0100 |
commit | fadd4029dced574778ade228931a7706f92bc676 (patch) | |
tree | 0779b54f6c47226ccd1524ff3855c63350ae6ed9 | |
parent | 20f4a9421ba644a1a1443aa16feb0aa481a0974f (diff) | |
download | bitcoin-fadd4029dced574778ade228931a7706f92bc676.tar.xz |
psbt: Assert that tx has a value in UpdatePSBTOutput
This was previously done implicitly in boost::optional by BOOST_ASSERT.
Also, it was checked at runtime by valgrind if for some reason the
assert was disabled.
std::optional dereference won't assert, so add the Assert here
explicitly.
The explicit Assert also helps to document the code better.
-rw-r--r-- | src/psbt.cpp | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/src/psbt.cpp b/src/psbt.cpp index 3fb743e5db..4db57d3cd0 100644 --- a/src/psbt.cpp +++ b/src/psbt.cpp @@ -3,6 +3,8 @@ // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include <psbt.h> + +#include <util/check.h> #include <util/strencodings.h> @@ -207,7 +209,8 @@ size_t CountPSBTUnsignedInputs(const PartiallySignedTransaction& psbt) { void UpdatePSBTOutput(const SigningProvider& provider, PartiallySignedTransaction& psbt, int index) { - const CTxOut& out = psbt.tx->vout.at(index); + CMutableTransaction& tx = *Assert(psbt.tx); + const CTxOut& out = tx.vout.at(index); PSBTOutput& psbt_out = psbt.outputs.at(index); // Fill a SignatureData with output info @@ -217,7 +220,7 @@ void UpdatePSBTOutput(const SigningProvider& provider, PartiallySignedTransactio // 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); + MutableTransactionSignatureCreator creator(&tx, /* index */ 0, out.nValue, SIGHASH_ALL); ProduceSignature(provider, creator, out.scriptPubKey, sigdata); // Put redeem_script, witness_script, key paths, into PSBTOutput. |