aboutsummaryrefslogtreecommitdiff
path: root/src/core_write.cpp
diff options
context:
space:
mode:
authorMichael Dietz <michael.dietz@waya.ai>2021-02-01 09:52:07 -0600
committerMichael Dietz <michael.dietz@waya.ai>2021-03-23 10:51:43 -0400
commit085b3a729952896ccd0e40c17df569f4421f5493 (patch)
treeb6cfbbd212573c4d9af93cf03c21e39abc4352b0 /src/core_write.cpp
parent3c87dbe95c925274f80234ad4a88beb5a05fdfff (diff)
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.
Diffstat (limited to 'src/core_write.cpp')
-rw-r--r--src/core_write.cpp24
1 files changed, 16 insertions, 8 deletions
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<CTxDestination> 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);