mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-23 04:18:35 +01:00
Merge #19517: psbt: Increment input value sum only once per UTXO in decodepsbt
75122780e2Increment 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: utACK75122780e2ryanofsky: Code review ACK75122780e2Tree-SHA512: 004ec1597790a88a98098f1a26534d10ab0130a438dec0913522a529a8d7f18ad679948617dbcad6e541fbab5bcb2682aeed386b67746807c03b64d76ce5441d
This commit is contained in:
@@ -1105,39 +1105,38 @@ UniValue decodepsbt(const JSONRPCRequest& request)
|
|||||||
UniValue in(UniValue::VOBJ);
|
UniValue in(UniValue::VOBJ);
|
||||||
// UTXOs
|
// UTXOs
|
||||||
bool have_a_utxo = false;
|
bool have_a_utxo = false;
|
||||||
|
CTxOut txout;
|
||||||
if (!input.witness_utxo.IsNull()) {
|
if (!input.witness_utxo.IsNull()) {
|
||||||
const CTxOut& txout = input.witness_utxo;
|
txout = input.witness_utxo;
|
||||||
|
|
||||||
|
UniValue o(UniValue::VOBJ);
|
||||||
|
ScriptToUniv(txout.scriptPubKey, o, true);
|
||||||
|
|
||||||
UniValue out(UniValue::VOBJ);
|
UniValue out(UniValue::VOBJ);
|
||||||
|
|
||||||
out.pushKV("amount", ValueFromAmount(txout.nValue));
|
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);
|
||||||
|
|
||||||
|
have_a_utxo = true;
|
||||||
|
}
|
||||||
|
if (have_a_utxo) {
|
||||||
if (MoneyRange(txout.nValue) && MoneyRange(total_in + txout.nValue)) {
|
if (MoneyRange(txout.nValue) && MoneyRange(total_in + txout.nValue)) {
|
||||||
total_in += txout.nValue;
|
total_in += txout.nValue;
|
||||||
} else {
|
} else {
|
||||||
// Hack to just not show fee later
|
// Hack to just not show fee later
|
||||||
have_all_utxos = false;
|
have_all_utxos = false;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
UniValue o(UniValue::VOBJ);
|
|
||||||
ScriptToUniv(txout.scriptPubKey, o, true);
|
|
||||||
out.pushKV("scriptPubKey", o);
|
|
||||||
in.pushKV("witness_utxo", out);
|
|
||||||
have_a_utxo = true;
|
|
||||||
}
|
|
||||||
if (input.non_witness_utxo) {
|
|
||||||
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;
|
|
||||||
} else {
|
|
||||||
// Hack to just not show fee later
|
|
||||||
have_all_utxos = false;
|
|
||||||
}
|
|
||||||
have_a_utxo = true;
|
|
||||||
}
|
|
||||||
if (!have_a_utxo) {
|
|
||||||
have_all_utxos = false;
|
have_all_utxos = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user