From 085b3a729952896ccd0e40c17df569f4421f5493 Mon Sep 17 00:00:00 2001 From: Michael Dietz Date: Mon, 1 Feb 2021 09:52:07 -0600 Subject: rpc: deprecate `addresses` and `reqSigs` from rpc outputs 1) add a new sane "address" field (for outputs that have an identifiable address, which doesn't include bare multisig) 2) with -deprecatedrpc: leave "reqSigs" and "addresses" intact (with all weird/wrong behavior they have now) 3) without -deprecatedrpc: drop "reqSigs" and "addresses" entirely, always. --- src/core_write.cpp | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) (limited to 'src/core_write.cpp') diff --git a/src/core_write.cpp b/src/core_write.cpp index d3034ae25d..b35f835f42 100644 --- a/src/core_write.cpp +++ b/src/core_write.cpp @@ -156,10 +156,13 @@ void ScriptToUniv(const CScript& script, UniValue& out, bool include_address) } } +// TODO: from v23 ("addresses" and "reqSigs" deprecated) this method should be refactored to remove the `include_addresses` option +// this method can also be combined with `ScriptToUniv` as they will overlap void ScriptPubKeyToUniv(const CScript& scriptPubKey, - UniValue& out, bool fIncludeHex) + UniValue& out, bool fIncludeHex, bool include_addresses) { TxoutType type; + CTxDestination address; std::vector addresses; int nRequired; @@ -172,17 +175,22 @@ void ScriptPubKeyToUniv(const CScript& scriptPubKey, return; } - out.pushKV("reqSigs", nRequired); + if (ExtractDestination(scriptPubKey, address)) { + out.pushKV("address", EncodeDestination(address)); + } out.pushKV("type", GetTxnOutputType(type)); - UniValue a(UniValue::VARR); - for (const CTxDestination& addr : addresses) { - a.push_back(EncodeDestination(addr)); + if (include_addresses) { + UniValue a(UniValue::VARR); + for (const CTxDestination& addr : addresses) { + a.push_back(EncodeDestination(addr)); + } + out.pushKV("addresses", a); + out.pushKV("reqSigs", nRequired); } - out.pushKV("addresses", a); } -void TxToUniv(const CTransaction& tx, const uint256& hashBlock, UniValue& entry, bool include_hex, int serialize_flags, const CTxUndo* txundo) +void TxToUniv(const CTransaction& tx, const uint256& hashBlock, bool include_addresses, UniValue& entry, bool include_hex, int serialize_flags, const CTxUndo* txundo) { entry.pushKV("txid", tx.GetHash().GetHex()); entry.pushKV("hash", tx.GetWitnessHash().GetHex()); @@ -241,7 +249,7 @@ void TxToUniv(const CTransaction& tx, const uint256& hashBlock, UniValue& entry, out.pushKV("n", (int64_t)i); UniValue o(UniValue::VOBJ); - ScriptPubKeyToUniv(txout.scriptPubKey, o, true); + ScriptPubKeyToUniv(txout.scriptPubKey, o, true, include_addresses); out.pushKV("scriptPubKey", o); vout.push_back(out); -- cgit v1.2.3