Skip to content

Commit 032cfdc

Browse files
committed
Merge #19517: psbt: Increment input value sum only once per UTXO in decodepsbt
7512278 Increment input value sum only once per UTXO in decodepsbt (Andrew Chow) Pull request description: Refactors the UTXO processing of `decodepsbt` to extract the relevant `CTxOut` and handle the input amounts from that. This avoids double counting the input value. Fixes #19516 ACKs for top commit: sipa: utACK 7512278 ryanofsky: Code review ACK 7512278 Tree-SHA512: 004ec1597790a88a98098f1a26534d10ab0130a438dec0913522a529a8d7f18ad679948617dbcad6e541fbab5bcb2682aeed386b67746807c03b64d76ce5441d
2 parents f4de89e + 7512278 commit 032cfdc

File tree

1 file changed

+16
-17
lines changed

1 file changed

+16
-17
lines changed

src/rpc/rawtransaction.cpp

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)