Merge 4b15ffe991 into merged_master (Bitcoin PR #20832)

This commit is contained in:
Andrew Poelstra 2021-06-18 20:01:45 +00:00
commit d6c85c5620
7 changed files with 156 additions and 22 deletions

View file

@ -43,9 +43,9 @@ static RPCHelpMan validateaddress()
RPCResult{
RPCResult::Type::OBJ, "", "",
{
{RPCResult::Type::BOOL, "isvalid", "If the address is valid or not. If not, this is the only property returned."},
{RPCResult::Type::BOOL, "isvalid_parent", "If the address is valid or not for parent chain. Valid or not, no additional details will be appended unlike `isvalid`"},
{RPCResult::Type::STR, "address", "The address validated"},
{RPCResult::Type::BOOL, "isvalid", "If the address is valid or not"},
{RPCResult::Type::BOOL, "isvalid_parent", "If the address is valid or not for parent chain"},
{RPCResult::Type::STR, "address", "The bitcoin address validated"},
{RPCResult::Type::STR_HEX, "scriptPubKey", "The hex-encoded scriptPubKey generated by the address"},
{RPCResult::Type::BOOL, "isscript", "If the key is a script"},
{RPCResult::Type::BOOL, "iswitness", "If the address is a witness address"},
@ -58,6 +58,8 @@ static RPCHelpMan validateaddress()
{RPCResult::Type::STR, "address", ""},
{RPCResult::Type::STR_HEX, "scriptPubKey", ""},
}},
{RPCResult::Type::STR, "error", /* optional */ true, "Error message, if any"},
{RPCResult::Type::STR, "error_parent", /* optional */ true, "Error message, if any"},
}
},
RPCExamples{
@ -66,15 +68,19 @@ static RPCHelpMan validateaddress()
},
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
{
CTxDestination dest = DecodeDestination(request.params[0].get_str());
CTxDestination parent_dest = DecodeParentDestination(request.params[0].get_str());
std::string error_msg;
CTxDestination dest = DecodeDestination(request.params[0].get_str(), error_msg);
std::string error_msg_parent;
CTxDestination parent_dest = DecodeParentDestination(request.params[0].get_str(), error_msg_parent);
bool isValid = IsValidDestination(dest);
bool is_valid_parent = IsValidDestination(parent_dest);
CHECK_NONFATAL(isValid == error_msg.empty());
CHECK_NONFATAL(is_valid_parent == error_msg_parent.empty());
UniValue ret(UniValue::VOBJ);
ret.pushKV("isvalid", isValid);
ret.pushKV("isvalid_parent", is_valid_parent);
if (isValid)
{
if (isValid) {
std::string currentAddress = EncodeDestination(dest);
ret.pushKV("address", currentAddress);
@ -100,6 +106,11 @@ static RPCHelpMan validateaddress()
parent_info.pushKVs(blind_detail);
ret.pushKV("parent_address_info", parent_info);
}
if (!isValid && !is_valid_parent) {
ret.pushKV("error", error_msg);
ret.pushKV("error_parent", error_msg_parent);
}
return ret;
},
};