[rpc] Remove the addresses field from the getaddressinfo return object

The "addresses" field was confusing because it refered to public keys
using their P2PKH address.  It was included in the return object when
needed for backward compatibility. Remove that compatibility now that
the -deprecatedrpc=validateaddress option has been removed.

New applications should use the 'embedded'->'address' field for P2SH or
P2WSH wrapped addresses, and 'pubkeys' for inspecting multisig
participants.
This commit is contained in:
John Newbery 2019-04-04 16:02:53 -04:00
parent 0e9cb2d24d
commit b4338c151d

View file

@ -3408,7 +3408,7 @@ class DescribeWalletAddressVisitor : public boost::static_visitor<UniValue>
public: public:
CWallet * const pwallet; CWallet * const pwallet;
void ProcessSubScript(const CScript& subscript, UniValue& obj, bool include_addresses = false) const void ProcessSubScript(const CScript& subscript, UniValue& obj) const
{ {
// Always present: script type and redeemscript // Always present: script type and redeemscript
std::vector<std::vector<unsigned char>> solutions_data; std::vector<std::vector<unsigned char>> solutions_data;
@ -3417,7 +3417,6 @@ public:
obj.pushKV("hex", HexStr(subscript.begin(), subscript.end())); obj.pushKV("hex", HexStr(subscript.begin(), subscript.end()));
CTxDestination embedded; CTxDestination embedded;
UniValue a(UniValue::VARR);
if (ExtractDestination(subscript, embedded)) { if (ExtractDestination(subscript, embedded)) {
// Only when the script corresponds to an address. // Only when the script corresponds to an address.
UniValue subobj(UniValue::VOBJ); UniValue subobj(UniValue::VOBJ);
@ -3430,7 +3429,6 @@ public:
// Always report the pubkey at the top level, so that `getnewaddress()['pubkey']` always works. // Always report the pubkey at the top level, so that `getnewaddress()['pubkey']` always works.
if (subobj.exists("pubkey")) obj.pushKV("pubkey", subobj["pubkey"]); if (subobj.exists("pubkey")) obj.pushKV("pubkey", subobj["pubkey"]);
obj.pushKV("embedded", std::move(subobj)); obj.pushKV("embedded", std::move(subobj));
if (include_addresses) a.push_back(EncodeDestination(embedded));
} else if (which_type == TX_MULTISIG) { } else if (which_type == TX_MULTISIG) {
// Also report some information on multisig scripts (which do not have a corresponding address). // Also report some information on multisig scripts (which do not have a corresponding address).
// TODO: abstract out the common functionality between this logic and ExtractDestinations. // TODO: abstract out the common functionality between this logic and ExtractDestinations.
@ -3438,17 +3436,10 @@ public:
UniValue pubkeys(UniValue::VARR); UniValue pubkeys(UniValue::VARR);
for (size_t i = 1; i < solutions_data.size() - 1; ++i) { for (size_t i = 1; i < solutions_data.size() - 1; ++i) {
CPubKey key(solutions_data[i].begin(), solutions_data[i].end()); CPubKey key(solutions_data[i].begin(), solutions_data[i].end());
if (include_addresses) a.push_back(EncodeDestination(key.GetID()));
pubkeys.push_back(HexStr(key.begin(), key.end())); pubkeys.push_back(HexStr(key.begin(), key.end()));
} }
obj.pushKV("pubkeys", std::move(pubkeys)); obj.pushKV("pubkeys", std::move(pubkeys));
} }
// The "addresses" field is confusing because it refers to public keys using their P2PKH address.
// For that reason, only add the 'addresses' field when needed for backward compatibility. New applications
// can use the 'embedded'->'address' field for P2SH or P2WSH wrapped addresses, and 'pubkeys' for
// inspecting multisig participants.
if (include_addresses) obj.pushKV("addresses", std::move(a));
} }
explicit DescribeWalletAddressVisitor(CWallet* _pwallet) : pwallet(_pwallet) {} explicit DescribeWalletAddressVisitor(CWallet* _pwallet) : pwallet(_pwallet) {}
@ -3471,7 +3462,7 @@ public:
UniValue obj(UniValue::VOBJ); UniValue obj(UniValue::VOBJ);
CScript subscript; CScript subscript;
if (pwallet && pwallet->GetCScript(scriptID, subscript)) { if (pwallet && pwallet->GetCScript(scriptID, subscript)) {
ProcessSubScript(subscript, obj, pwallet->chain().rpcEnableDeprecated("validateaddress")); ProcessSubScript(subscript, obj);
} }
return obj; return obj;
} }