From cd5515a266d5b9e16696dca67662ea209a7e9e44 Mon Sep 17 00:00:00 2001 From: Andrew Chow Date: Mon, 11 Jan 2021 16:59:29 -0500 Subject: [PATCH] Change PSBT::AddOutput to take just PSBTOutput --- src/psbt.cpp | 15 +++++++++++---- src/psbt.h | 2 +- src/rpc/rawtransaction.cpp | 4 ++-- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/psbt.cpp b/src/psbt.cpp index 49b8258496..9cc32a6d73 100644 --- a/src/psbt.cpp +++ b/src/psbt.cpp @@ -153,11 +153,18 @@ bool PartiallySignedTransaction::AddInput(PSBTInput& psbtin) return false; } -bool PartiallySignedTransaction::AddOutput(const CTxOut& txout, const PSBTOutput& psbtout) +bool PartiallySignedTransaction::AddOutput(const PSBTOutput& psbtout) { - tx->vout.push_back(txout); - outputs.push_back(psbtout); - return true; + if (tx != nullopt) { + // This is a v0 psbt, do the v0 AddOutput + CTxOut txout(CAsset(), *psbtout.amount, psbtout.script); + tx->vout.push_back(txout); + outputs.push_back(psbtout); + return true; + } + + // TOOD: Do PSBTv2 + return false; } bool PSBTInput::GetUTXO(CTxOut& utxo) const diff --git a/src/psbt.h b/src/psbt.h index 78c0fbd393..0789e691c2 100644 --- a/src/psbt.h +++ b/src/psbt.h @@ -738,7 +738,7 @@ struct PartiallySignedTransaction * same actual Bitcoin transaction.) Returns true if the merge succeeded, false otherwise. */ [[nodiscard]] bool Merge(const PartiallySignedTransaction& psbt); bool AddInput(PSBTInput& psbtin); - bool AddOutput(const CTxOut& txout, const PSBTOutput& psbtout); + bool AddOutput(const PSBTOutput& psbtout); void SetupFromTx(const CMutableTransaction& tx); void CacheUnsignedTxPieces(); bool ComputeTimeLock(uint32_t& locktime) const; diff --git a/src/rpc/rawtransaction.cpp b/src/rpc/rawtransaction.cpp index 61efbdb40b..3f48c6f8d3 100644 --- a/src/rpc/rawtransaction.cpp +++ b/src/rpc/rawtransaction.cpp @@ -2152,7 +2152,7 @@ static RPCHelpMan joinpsbts() } } for (unsigned int i = 0; i < psbt.tx->vout.size(); ++i) { - merged_psbt.AddOutput(psbt.tx->vout[i], psbt.outputs[i]); + merged_psbt.AddOutput(psbt.outputs[i]); } for (auto& xpub_pair : psbt.m_xpubs) { if (merged_psbt.m_xpubs.count(xpub_pair.first) == 0) { @@ -2182,7 +2182,7 @@ static RPCHelpMan joinpsbts() shuffled_psbt.AddInput(merged_psbt.inputs[i]); } for (int i : output_indices) { - shuffled_psbt.AddOutput(merged_psbt.tx->vout[i], merged_psbt.outputs[i]); + shuffled_psbt.AddOutput(merged_psbt.outputs[i]); } shuffled_psbt.unknown.insert(merged_psbt.unknown.begin(), merged_psbt.unknown.end());