aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Chow <achow101-github@achow101.com>2020-07-14 12:16:18 -0400
committerfanquake <fanquake@gmail.com>2020-07-15 12:06:43 +0800
commitbad9cf8f404ab70df7d3df430885430f76fea596 (patch)
tree364eb61653bd1fc38e77c770793e8b88413ea1f9
parent2f6c7c0f6f47571eb36f54d07e1de7f47c10d354 (diff)
downloadbitcoin-bad9cf8f404ab70df7d3df430885430f76fea596.tar.xz
Increment input value sum only once per UTXO in decodepsbt
Github-Pull: #19517 Rebased-From: 75122780e2c46505d977e24c5612dfa9442ab754
-rw-r--r--src/rpc/rawtransaction.cpp33
1 files changed, 16 insertions, 17 deletions
diff --git a/src/rpc/rawtransaction.cpp b/src/rpc/rawtransaction.cpp
index 746900fdab..b9ec3c53d6 100644
--- a/src/rpc/rawtransaction.cpp
+++ b/src/rpc/rawtransaction.cpp
@@ -1117,39 +1117,38 @@ UniValue decodepsbt(const JSONRPCRequest& request)
UniValue in(UniValue::VOBJ);
// UTXOs
bool have_a_utxo = false;
+ CTxOut txout;
if (!input.witness_utxo.IsNull()) {
- const CTxOut& txout = input.witness_utxo;
-
- UniValue out(UniValue::VOBJ);
-
- out.pushKV("amount", ValueFromAmount(txout.nValue));
- if (MoneyRange(txout.nValue) && MoneyRange(total_in + txout.nValue)) {
- total_in += txout.nValue;
- } else {
- // Hack to just not show fee later
- have_all_utxos = false;
- }
+ txout = input.witness_utxo;
UniValue o(UniValue::VOBJ);
ScriptToUniv(txout.scriptPubKey, o, true);
+
+ UniValue out(UniValue::VOBJ);
+ out.pushKV("amount", ValueFromAmount(txout.nValue));
out.pushKV("scriptPubKey", o);
+
in.pushKV("witness_utxo", out);
+
have_a_utxo = true;
}
if (input.non_witness_utxo) {
+ txout = input.non_witness_utxo->vout[psbtx.tx->vin[i].prevout.n];
+
UniValue non_wit(UniValue::VOBJ);
TxToUniv(*input.non_witness_utxo, uint256(), non_wit, false);
in.pushKV("non_witness_utxo", non_wit);
- CAmount utxo_val = input.non_witness_utxo->vout[psbtx.tx->vin[i].prevout.n].nValue;
- if (MoneyRange(utxo_val) && MoneyRange(total_in + utxo_val)) {
- total_in += utxo_val;
+
+ have_a_utxo = true;
+ }
+ if (have_a_utxo) {
+ if (MoneyRange(txout.nValue) && MoneyRange(total_in + txout.nValue)) {
+ total_in += txout.nValue;
} else {
// Hack to just not show fee later
have_all_utxos = false;
}
- have_a_utxo = true;
- }
- if (!have_a_utxo) {
+ } else {
have_all_utxos = false;
}