| 42 | using node::NodeContext; |
| 43 | |
| 44 | static RPCHelpMan validateaddress() |
| 45 | { |
| 46 | return RPCHelpMan{ |
| 47 | "validateaddress", |
| 48 | "\nReturn information about the given bitcoin address.\n", |
| 49 | { |
| 50 | {"address", RPCArg::Type::STR, RPCArg::Optional::NO, "The bitcoin address to validate"}, |
| 51 | }, |
| 52 | RPCResult{ |
| 53 | RPCResult::Type::OBJ, "", "", |
| 54 | { |
| 55 | {RPCResult::Type::BOOL, "isvalid", "If the address is valid or not"}, |
| 56 | {RPCResult::Type::BOOL, "isvalid_parent", "If the address is valid or not for parent chain"}, |
| 57 | {RPCResult::Type::STR, "address", /*optional=*/true, "The bitcoin address validated"}, |
| 58 | {RPCResult::Type::STR_HEX, "scriptPubKey", /*optional=*/true, "The hex-encoded scriptPubKey generated by the address"}, |
| 59 | {RPCResult::Type::BOOL, "isscript", /*optional=*/true, "If the key is a script"}, |
| 60 | {RPCResult::Type::BOOL, "iswitness", /*optional=*/true, "If the address is a witness address"}, |
| 61 | {RPCResult::Type::NUM, "witness_version", /*optional=*/true, "The version number of the witness program"}, |
| 62 | {RPCResult::Type::STR_HEX, "witness_program", /*optional=*/true, "The hex value of the witness program"}, |
| 63 | {RPCResult::Type::STR_HEX, "confidential_key", "the raw blinding public key for that address, if any. \"\" if none"}, |
| 64 | {RPCResult::Type::STR, "unconfidential", "The address without confidentiality key"}, |
| 65 | {RPCResult::Type::OBJ, "parent_address_info", "If the address isvalid_parent, this object contains details about the parent address type", |
| 66 | { |
| 67 | {RPCResult::Type::STR, "address", ""}, |
| 68 | {RPCResult::Type::STR_HEX, "scriptPubKey", ""}, |
| 69 | }}, |
| 70 | {RPCResult::Type::STR, "error", /*optional=*/true, "Error message, if any"}, |
| 71 | {RPCResult::Type::STR, "error_parent", /* optional */ true, "Error message, if any"}, |
| 72 | {RPCResult::Type::ARR, "error_locations", /*optional=*/true, "Indices of likely error locations in address, if known (e.g. Bech32 errors)", |
| 73 | { |
| 74 | {RPCResult::Type::NUM, "index", "index of a potential error"}, |
| 75 | }}, |
| 76 | } |
| 77 | }, |
| 78 | RPCExamples{ |
| 79 | HelpExampleCli("validateaddress", "\"" + EXAMPLE_ADDRESS[0] + "\"") + |
| 80 | HelpExampleRpc("validateaddress", "\"" + EXAMPLE_ADDRESS[0] + "\"") |
| 81 | }, |
| 82 | [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue |
| 83 | { |
| 84 | std::string error_msg; |
| 85 | std::vector<int> error_locations; |
| 86 | CTxDestination dest = DecodeDestination(request.params[0].get_str(), error_msg, &error_locations); |
| 87 | std::string error_msg_parent; |
| 88 | CTxDestination parent_dest = DecodeParentDestination(request.params[0].get_str(), error_msg_parent); |
| 89 | const bool isValid = IsValidDestination(dest); |
| 90 | const bool is_valid_parent = IsValidDestination(parent_dest); |
| 91 | CHECK_NONFATAL(isValid == error_msg.empty()); |
| 92 | CHECK_NONFATAL(is_valid_parent == error_msg_parent.empty()); |
| 93 | |
| 94 | UniValue ret(UniValue::VOBJ); |
| 95 | ret.pushKV("isvalid", isValid); |
| 96 | ret.pushKV("isvalid_parent", is_valid_parent); |
| 97 | if (isValid) { |
| 98 | std::string currentAddress = EncodeDestination(dest); |
| 99 | ret.pushKV("address", currentAddress); |
| 100 | |
| 101 | CScript scriptPubKey = GetScriptForDestination(dest); |
nothing calls this directly
no test coverage detected