From 77542cf2a5f8abb97dd46f782c1b0199cc062033 Mon Sep 17 00:00:00 2001 From: Andrew Chow Date: Tue, 31 Jul 2018 17:56:47 -0700 Subject: Move PSBT UTXO fetching to a separate method --- src/psbt.cpp | 14 ++++++++++++++ src/psbt.h | 8 ++++++++ 2 files changed, 22 insertions(+) (limited to 'src') diff --git a/src/psbt.cpp b/src/psbt.cpp index 0734edcf8e..32fb459dec 100644 --- a/src/psbt.cpp +++ b/src/psbt.cpp @@ -62,6 +62,20 @@ bool PartiallySignedTransaction::AddOutput(const CTxOut& txout, const PSBTOutput return true; } +bool PartiallySignedTransaction::GetInputUTXO(CTxOut& utxo, int input_index) const +{ + PSBTInput input = inputs[input_index]; + int prevout_index = tx->vin[input_index].prevout.n; + if (input.non_witness_utxo) { + utxo = input.non_witness_utxo->vout[prevout_index]; + } else if (!input.witness_utxo.IsNull()) { + utxo = input.witness_utxo; + } else { + return false; + } + return true; +} + 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(); diff --git a/src/psbt.h b/src/psbt.h index cc4882c580..27b0aedd05 100644 --- a/src/psbt.h +++ b/src/psbt.h @@ -394,6 +394,14 @@ struct PartiallySignedTransaction PartiallySignedTransaction() {} PartiallySignedTransaction(const PartiallySignedTransaction& psbt_in) : tx(psbt_in.tx), inputs(psbt_in.inputs), outputs(psbt_in.outputs), unknown(psbt_in.unknown) {} explicit PartiallySignedTransaction(const CMutableTransaction& tx); + /** + * Finds the UTXO for a given input index + * + * @param[out] utxo The UTXO of the input if found + * @param[in] input_index Index of the input to retrieve the UTXO of + * @return Whether the UTXO for the specified input was found + */ + bool GetInputUTXO(CTxOut& utxo, int input_index) const; template inline void Serialize(Stream& s) const { -- cgit v1.2.3