Skip to content

Commit 77542cf

Browse files
committed
Move PSBT UTXO fetching to a separate method
1 parent cb40b3a commit 77542cf

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/psbt.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,20 @@ bool PartiallySignedTransaction::AddOutput(const CTxOut& txout, const PSBTOutput
6262
return true;
6363
}
6464

65+
bool PartiallySignedTransaction::GetInputUTXO(CTxOut& utxo, int input_index) const
66+
{
67+
PSBTInput input = inputs[input_index];
68+
int prevout_index = tx->vin[input_index].prevout.n;
69+
if (input.non_witness_utxo) {
70+
utxo = input.non_witness_utxo->vout[prevout_index];
71+
} else if (!input.witness_utxo.IsNull()) {
72+
utxo = input.witness_utxo;
73+
} else {
74+
return false;
75+
}
76+
return true;
77+
}
78+
6579
bool PSBTInput::IsNull() const
6680
{
6781
return !non_witness_utxo && witness_utxo.IsNull() && partial_sigs.empty() && unknown.empty() && hd_keypaths.empty() && redeem_script.empty() && witness_script.empty();

src/psbt.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,14 @@ struct PartiallySignedTransaction
394394
PartiallySignedTransaction() {}
395395
PartiallySignedTransaction(const PartiallySignedTransaction& psbt_in) : tx(psbt_in.tx), inputs(psbt_in.inputs), outputs(psbt_in.outputs), unknown(psbt_in.unknown) {}
396396
explicit PartiallySignedTransaction(const CMutableTransaction& tx);
397+
/**
398+
* Finds the UTXO for a given input index
399+
*
400+
* @param[out] utxo The UTXO of the input if found
401+
* @param[in] input_index Index of the input to retrieve the UTXO of
402+
* @return Whether the UTXO for the specified input was found
403+
*/
404+
bool GetInputUTXO(CTxOut& utxo, int input_index) const;
397405

398406
template <typename Stream>
399407
inline void Serialize(Stream& s) const {

0 commit comments

Comments
 (0)