From 3da0e160124ffdc14e9aaa5d02fd04c232d431cc Mon Sep 17 00:00:00 2001 From: Ava Chow Date: Mon, 22 Jul 2024 17:14:20 -0400 Subject: [PATCH] Replace PSBT.tx with PSBT::GetUnsignedTx and PSBT::GetUniqueID The global unsigned tx is decomposed into separate fields inside of PSBT, which mirrors what PSBTv2 will do. However, we still need to get the global unsigned tx so PSBT::GetUnsignedTx is introduced to do that. In order to also have a stable unique ID, we also introduce PSBT::GetUniqueID to replace uses of PSBT.tx.GetHash(). --- src/node/psbt.cpp | 8 +- src/psbt.cpp | 105 +++++++++++++++++++------- src/psbt.h | 11 +-- src/rpc/rawtransaction.cpp | 11 +-- src/test/fuzz/psbt.cpp | 6 +- src/wallet/test/psbt_wallet_tests.cpp | 1 - 6 files changed, 99 insertions(+), 43 deletions(-) diff --git a/src/node/psbt.cpp b/src/node/psbt.cpp index 5b78001c6d6..699d1d5f7ce 100644 --- a/src/node/psbt.cpp +++ b/src/node/psbt.cpp @@ -18,6 +18,13 @@ PSBTAnalysis AnalyzePSBT(PartiallySignedTransaction psbtx) // Go through each input and build status PSBTAnalysis result; + std::optional unsigned_tx = psbtx.GetUnsignedTx(); + if (!unsigned_tx) { + result.SetInvalid("PSBT cannot be made into a valid transaction"); + return result; + } + CMutableTransaction& mtx = *unsigned_tx; + bool calc_fee = true; CAmount in_amt = 0; @@ -116,7 +123,6 @@ PSBTAnalysis AnalyzePSBT(PartiallySignedTransaction psbtx) result.fee = fee; // Estimate the size - CMutableTransaction mtx(*psbtx.tx); CCoinsViewCache view{&CoinsViewEmpty::Get()}; bool success = true; diff --git a/src/psbt.cpp b/src/psbt.cpp index d7320682b27..a87079610d6 100644 --- a/src/psbt.cpp +++ b/src/psbt.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include