mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-20 15:19:07 +01:00
Merge #17578: rpc: simplify getaddressinfo labels, deprecate previous behavior
8925df86c4doc: update release notes (Jon Atack)8bb405bbadtest: getaddressinfo labels purpose deprecation test (Jon Atack)60aba1f2f1rpc: simplify getaddressinfo labels, deprecate previous behavior (Jon Atack)7851f14ccfrpc: incorporate review feedback from PR 17283 (Jon Atack) Pull request description: This PR builds on #17283 (now merged) and is followed by #17585. It modifies the value returned by rpc getaddressinfo `labels` to an array of label name strings and deprecates the previous behavior of returning an array of JSON hash structures containing label `name` and address `purpose` key/value pairs. before ``` "labels": [ { "name": "DOUBLE SPEND", "purpose": "receive" } ``` after ``` "labels": [ "DOUBLE SPEND" ] ``` The deprecated behavior can be re-enabled by starting bitcoind with `-deprecatedrpc=labelspurpose`. For context, see: - https://github.com/bitcoin/bitcoin/pull/17283#issuecomment-554458001 - http://www.erisian.com.au/bitcoin-core-dev/log-2019-12-13.html#l-425 (lines 425-427) - http://www.erisian.com.au/bitcoin-core-dev/log-2019-11-22.html#l-622 Reviewers: This PR may be tested manually by building, then running bitcoind with and without the `-deprecatedrpc=labelspurpose` flag while verifying the rpc getaddressinfo help text and `labels` output. Next steps: deprecate the rpc getaddressinfo `label` field (EDIT: done in #17585) and add support for multiple labels per address. This PR will unblock those. ACKs for top commit: jnewbery: reACK8925df8promag: Code review ACK8925df86c4. meshcollider: Code review ACK8925df86c4Tree-SHA512: c2b717209996da32b6484de7bb8800e7048410f9ce6afdb3e02a6866bd4a8f2c730f905fca27b10b877b91cf407f546e69e8c4feb9cd934325a6c71c166bd438
This commit is contained in:
@@ -3726,6 +3726,8 @@ UniValue getaddressinfo(const JSONRPCRequest& request)
|
||||
return NullUniValue;
|
||||
}
|
||||
|
||||
const std::string example_address = "\"bc1q09vm5lfy0j5reeulh4x5752q25uqqvz34hufdl\"";
|
||||
|
||||
RPCHelpMan{"getaddressinfo",
|
||||
"\nReturn information about the given bitcoin address.\n"
|
||||
"Some of the information will only be present if the address is in the active wallet.\n",
|
||||
@@ -3760,24 +3762,26 @@ UniValue getaddressinfo(const JSONRPCRequest& request)
|
||||
" getaddressinfo output fields for the embedded address, excluding metadata (timestamp, hdkeypath,\n"
|
||||
" hdseedid) and relation to the wallet (ismine, iswatchonly).\n"
|
||||
" \"iscompressed\" : true|false, (boolean, optional) If the pubkey is compressed.\n"
|
||||
" \"label\" : \"label\" (string) The label associated with the address. Defaults to \"\". Equivalent to the name field in the labels array.\n"
|
||||
" \"label\" : \"label\" (string) The label associated with the address. Defaults to \"\". Equivalent to the label name in the labels array below.\n"
|
||||
" \"timestamp\" : timestamp, (number, optional) The creation time of the key, if available, expressed in " + UNIX_EPOCH_TIME + ".\n"
|
||||
" \"hdkeypath\" : \"keypath\" (string, optional) The HD keypath, if the key is HD and available.\n"
|
||||
" \"hdseedid\" : \"<hash160>\" (string, optional) The Hash160 of the HD seed.\n"
|
||||
" \"hdmasterfingerprint\" : \"<hash160>\" (string, optional) The fingerprint of the master key.\n"
|
||||
" \"labels\" (object) An array of labels associated with the address. Currently limited to one label but returned\n"
|
||||
" \"labels\" (json object) An array of labels associated with the address. Currently limited to one label but returned\n"
|
||||
" as an array to keep the API stable if multiple labels are enabled in the future.\n"
|
||||
" [\n"
|
||||
" \"label name\" (string) The label name. Defaults to \"\". Equivalent to the label field above.\n\n"
|
||||
" DEPRECATED, will be removed in 0.21. To re-enable, launch bitcoind with `-deprecatedrpc=labelspurpose`:\n"
|
||||
" { (json object of label data)\n"
|
||||
" \"name\": \"label name\" (string) The label name. Defaults to \"\". Equivalent to the label field above.\n"
|
||||
" \"purpose\": \"purpose\" (string) The purpose of the associated address (send or receive).\n"
|
||||
" },...\n"
|
||||
" \"name\" : \"label name\" (string) The label name. Defaults to \"\". Equivalent to the label field above.\n"
|
||||
" \"purpose\" : \"purpose\" (string) The purpose of the associated address (send or receive).\n"
|
||||
" }\n"
|
||||
" ]\n"
|
||||
"}\n"
|
||||
},
|
||||
RPCExamples{
|
||||
HelpExampleCli("getaddressinfo", "\"bc1q09vm5lfy0j5reeulh4x5752q25uqqvz34hufdl\"") +
|
||||
HelpExampleRpc("getaddressinfo", "\"bc1q09vm5lfy0j5reeulh4x5752q25uqqvz34hufdl\"")
|
||||
HelpExampleCli("getaddressinfo", example_address) +
|
||||
HelpExampleRpc("getaddressinfo", example_address)
|
||||
},
|
||||
}.Check(request);
|
||||
|
||||
@@ -3785,7 +3789,6 @@ UniValue getaddressinfo(const JSONRPCRequest& request)
|
||||
|
||||
UniValue ret(UniValue::VOBJ);
|
||||
CTxDestination dest = DecodeDestination(request.params[0].get_str());
|
||||
|
||||
// Make sure the destination is valid
|
||||
if (!IsValidDestination(dest)) {
|
||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid address");
|
||||
@@ -3811,24 +3814,18 @@ UniValue getaddressinfo(const JSONRPCRequest& request)
|
||||
|
||||
ret.pushKV("iswatchonly", bool(mine & ISMINE_WATCH_ONLY));
|
||||
|
||||
// Return DescribeWalletAddress fields.
|
||||
// Always returned: isscript, ischange, iswitness.
|
||||
// Optional: witness_version, witness_program, script, hex, pubkeys (array),
|
||||
// sigsrequired, pubkey, embedded, iscompressed.
|
||||
UniValue detail = DescribeWalletAddress(pwallet, dest);
|
||||
ret.pushKVs(detail);
|
||||
|
||||
// Return label field if existing. Currently only one label can be
|
||||
// associated with an address, so the label should be equivalent to the
|
||||
// value of the name key/value pair in the labels hash array below.
|
||||
// value of the name key/value pair in the labels array below.
|
||||
if (pwallet->mapAddressBook.count(dest)) {
|
||||
ret.pushKV("label", pwallet->mapAddressBook[dest].name);
|
||||
}
|
||||
|
||||
ret.pushKV("ischange", pwallet->IsChange(scriptPubKey));
|
||||
|
||||
// Fetch KeyMetadata, if present, for the timestamp, hdkeypath, hdseedid,
|
||||
// and hdmasterfingerprint fields.
|
||||
ScriptPubKeyMan* spk_man = pwallet->GetScriptPubKeyMan(scriptPubKey);
|
||||
if (spk_man) {
|
||||
if (const CKeyMetadata* meta = spk_man->GetMetadata(dest)) {
|
||||
@@ -3841,15 +3838,22 @@ UniValue getaddressinfo(const JSONRPCRequest& request)
|
||||
}
|
||||
}
|
||||
|
||||
// Return a labels array containing a hash of key/value pairs for the label
|
||||
// name and address purpose. The name value is equivalent to the label field
|
||||
// above. Currently only one label can be associated with an address, but we
|
||||
// return an array so the API remains stable if we allow multiple labels to
|
||||
// be associated with an address in the future.
|
||||
// Return a `labels` array containing the label associated with the address,
|
||||
// equivalent to the `label` field above. Currently only one label can be
|
||||
// associated with an address, but we return an array so the API remains
|
||||
// stable if we allow multiple labels to be associated with an address in
|
||||
// the future.
|
||||
//
|
||||
// DEPRECATED: The previous behavior of returning an array containing a JSON
|
||||
// object of `name` and `purpose` key/value pairs has been deprecated.
|
||||
UniValue labels(UniValue::VARR);
|
||||
std::map<CTxDestination, CAddressBookData>::iterator mi = pwallet->mapAddressBook.find(dest);
|
||||
if (mi != pwallet->mapAddressBook.end()) {
|
||||
labels.push_back(AddressBookDataToJSON(mi->second, true));
|
||||
if (pwallet->chain().rpcEnableDeprecated("labelspurpose")) {
|
||||
labels.push_back(AddressBookDataToJSON(mi->second, true));
|
||||
} else {
|
||||
labels.push_back(mi->second.name);
|
||||
}
|
||||
}
|
||||
ret.pushKV("labels", std::move(labels));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user