Skip to content

Commit fadd402

Browse files
author
MarcoFalke
committed
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.
1 parent 20f4a94 commit fadd402

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/psbt.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
44

55
#include <psbt.h>
6+
7+
#include <util/check.h>
68
#include <util/strencodings.h>
79

810

@@ -207,7 +209,8 @@ size_t CountPSBTUnsignedInputs(const PartiallySignedTransaction& psbt) {
207209

208210
void UpdatePSBTOutput(const SigningProvider& provider, PartiallySignedTransaction& psbt, int index)
209211
{
210-
const CTxOut& out = psbt.tx->vout.at(index);
212+
CMutableTransaction& tx = *Assert(psbt.tx);
213+
const CTxOut& out = tx.vout.at(index);
211214
PSBTOutput& psbt_out = psbt.outputs.at(index);
212215

213216
// Fill a SignatureData with output info
@@ -217,7 +220,7 @@ void UpdatePSBTOutput(const SigningProvider& provider, PartiallySignedTransactio
217220
// Construct a would-be spend of this output, to update sigdata with.
218221
// Note that ProduceSignature is used to fill in metadata (not actual signatures),
219222
// so provider does not need to provide any private keys (it can be a HidingSigningProvider).
220-
MutableTransactionSignatureCreator creator(psbt.tx.get_ptr(), /* index */ 0, out.nValue, SIGHASH_ALL);
223+
MutableTransactionSignatureCreator creator(&tx, /* index */ 0, out.nValue, SIGHASH_ALL);
221224
ProduceSignature(provider, creator, out.scriptPubKey, sigdata);
222225

223226
// Put redeem_script, witness_script, key paths, into PSBTOutput.

0 commit comments

Comments
 (0)