@@ -1105,39 +1105,38 @@ UniValue decodepsbt(const JSONRPCRequest& request)
11051105 UniValue in (UniValue::VOBJ);
11061106 // UTXOs
11071107 bool have_a_utxo = false ;
1108+ CTxOut txout;
11081109 if (!input.witness_utxo .IsNull ()) {
1109- const CTxOut& txout = input.witness_utxo ;
1110-
1111- UniValue out (UniValue::VOBJ);
1112-
1113- out.pushKV (" amount" , ValueFromAmount (txout.nValue ));
1114- if (MoneyRange (txout.nValue ) && MoneyRange (total_in + txout.nValue )) {
1115- total_in += txout.nValue ;
1116- } else {
1117- // Hack to just not show fee later
1118- have_all_utxos = false ;
1119- }
1110+ txout = input.witness_utxo ;
11201111
11211112 UniValue o (UniValue::VOBJ);
11221113 ScriptToUniv (txout.scriptPubKey , o, true );
1114+
1115+ UniValue out (UniValue::VOBJ);
1116+ out.pushKV (" amount" , ValueFromAmount (txout.nValue ));
11231117 out.pushKV (" scriptPubKey" , o);
1118+
11241119 in.pushKV (" witness_utxo" , out);
1120+
11251121 have_a_utxo = true ;
11261122 }
11271123 if (input.non_witness_utxo ) {
1124+ txout = input.non_witness_utxo ->vout [psbtx.tx ->vin [i].prevout .n ];
1125+
11281126 UniValue non_wit (UniValue::VOBJ);
11291127 TxToUniv (*input.non_witness_utxo , uint256 (), non_wit, false );
11301128 in.pushKV (" non_witness_utxo" , non_wit);
1131- CAmount utxo_val = input.non_witness_utxo ->vout [psbtx.tx ->vin [i].prevout .n ].nValue ;
1132- if (MoneyRange (utxo_val) && MoneyRange (total_in + utxo_val)) {
1133- total_in += utxo_val;
1129+
1130+ have_a_utxo = true ;
1131+ }
1132+ if (have_a_utxo) {
1133+ if (MoneyRange (txout.nValue ) && MoneyRange (total_in + txout.nValue )) {
1134+ total_in += txout.nValue ;
11341135 } else {
11351136 // Hack to just not show fee later
11361137 have_all_utxos = false ;
11371138 }
1138- have_a_utxo = true ;
1139- }
1140- if (!have_a_utxo) {
1139+ } else {
11411140 have_all_utxos = false ;
11421141 }
11431142
0 commit comments