From 1b7d323a726e5401efbf2a91df1313501cdf82b0 Mon Sep 17 00:00:00 2001 From: Ava Chow Date: Mon, 22 Jul 2024 17:14:27 -0400 Subject: [PATCH] Add PSBTInput::GetOutPoint Helper for getting the PSBTInput COutPoint --- src/node/psbt.cpp | 2 +- src/psbt.cpp | 9 +++++++-- src/psbt.h | 2 ++ src/rpc/rawtransaction.cpp | 5 ++--- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/node/psbt.cpp b/src/node/psbt.cpp index 62382e5602b..749007d2440 100644 --- a/src/node/psbt.cpp +++ b/src/node/psbt.cpp @@ -130,7 +130,7 @@ PSBTAnalysis AnalyzePSBT(PartiallySignedTransaction psbtx) mtx.vin[i].scriptSig = input.final_script_sig; mtx.vin[i].scriptWitness = input.final_script_witness; newcoin.nHeight = 1; - view.AddCoin(psbtx.tx->vin[i].prevout, std::move(newcoin), true); + view.AddCoin(input.GetOutPoint(), std::move(newcoin), true); } } diff --git a/src/psbt.cpp b/src/psbt.cpp index 3f5e2cde9c2..85c2f25a902 100644 --- a/src/psbt.cpp +++ b/src/psbt.cpp @@ -98,6 +98,11 @@ bool PartiallySignedTransaction::GetInputUTXO(CTxOut& utxo, int input_index) con return true; } +COutPoint PSBTInput::GetOutPoint() const +{ + return COutPoint(prev_txid, prev_out); +} + bool PSBTInput::IsNull() const { return !non_witness_utxo && witness_utxo.IsNull() && partial_sigs.empty() && unknown.empty() && hd_keypaths.empty() && redeem_script.empty() && witness_script.empty(); @@ -352,7 +357,7 @@ bool PSBTInputSignedAndVerified(const PartiallySignedTransaction& psbt, unsigned if (input.non_witness_utxo) { // If we're taking our information from a non-witness UTXO, verify that it matches the prevout. - COutPoint prevout = psbt.tx->vin[input_index].prevout; + COutPoint prevout = input.GetOutPoint(); if (prevout.n >= input.non_witness_utxo->vout.size()) { return false; } @@ -440,7 +445,7 @@ PSBTError SignPSBTInput(const SigningProvider& provider, PartiallySignedTransact if (input.non_witness_utxo) { // If we're taking our information from a non-witness UTXO, verify that it matches the prevout. - COutPoint prevout = tx.vin[index].prevout; + COutPoint prevout = input.GetOutPoint(); if (prevout.n >= input.non_witness_utxo->vout.size()) { return PSBTError::MISSING_INPUTS; } diff --git a/src/psbt.h b/src/psbt.h index 2325ca97be9..bb5ce49143f 100644 --- a/src/psbt.h +++ b/src/psbt.h @@ -309,6 +309,8 @@ public: void FromSignatureData(const SignatureData& sigdata); void Merge(const PSBTInput& input); uint32_t GetVersion() const { return m_psbt_version; } + COutPoint GetOutPoint() const; + explicit PSBTInput(uint32_t psbt_version, const Txid& prev_txid, uint32_t prev_out, std::optional sequence = std::nullopt) : m_psbt_version(psbt_version), prev_txid(prev_txid), diff --git a/src/rpc/rawtransaction.cpp b/src/rpc/rawtransaction.cpp index f3fb3eb7f0d..b5a063859ee 100644 --- a/src/rpc/rawtransaction.cpp +++ b/src/rpc/rawtransaction.cpp @@ -165,7 +165,7 @@ PartiallySignedTransaction ProcessPSBT(const std::string& psbt_string, const std if (tx) { psbt_input.non_witness_utxo = tx; } else { - coins[tx_in.prevout]; // Create empty map entry keyed by prevout + coins[psbt_input.GetOutPoint()]; // Create empty map entry keyed by prevout } } @@ -177,8 +177,7 @@ PartiallySignedTransaction ProcessPSBT(const std::string& psbt_string, const std // If there are still missing utxos, add them if they were found in the utxo set if (!input.non_witness_utxo) { - const CTxIn& tx_in = psbtx.tx->vin.at(i); - const Coin& coin = coins.at(tx_in.prevout); + const Coin& coin = coins.at(input.GetOutPoint()); if (!coin.out.IsNull() && IsSegWitOutput(provider, coin.out.scriptPubKey)) { input.witness_utxo = coin.out; }