| 34 | #include <univalue.h> |
| 35 | |
| 36 | static UniValue validateaddress(const JSONRPCRequest& request) |
| 37 | { |
| 38 | if (request.fHelp || request.params.size() != 1) |
| 39 | throw std::runtime_error( |
| 40 | "validateaddress \"address\"\n" |
| 41 | "\nReturn information about the given bitcoin address.\n" |
| 42 | "DEPRECATION WARNING: Parts of this command have been deprecated and moved to getaddressinfo. Clients must\n" |
| 43 | "transition to using getaddressinfo to access this information before upgrading to v0.18. The following deprecated\n" |
| 44 | "fields have moved to getaddressinfo and will only be shown here with -deprecatedrpc=validateaddress: ismine, iswatchonly,\n" |
| 45 | "script, hex, pubkeys, sigsrequired, pubkey, addresses, embedded, iscompressed, account, timestamp, hdkeypath, kdmasterkeyid.\n" |
| 46 | "\nArguments:\n" |
| 47 | "1. \"address\" (string, required) The bitcoin address to validate\n" |
| 48 | "\nResult:\n" |
| 49 | "{\n" |
| 50 | " \"isvalid\" : true|false, (boolean) If the address is valid or not. If not, this is the only property returned.\n" |
| 51 | " \"address\" : \"address\", (string) The bitcoin address validated\n" |
| 52 | " \"scriptPubKey\" : \"hex\", (string) The hex encoded scriptPubKey generated by the address\n" |
| 53 | " \"isscript\" : true|false, (boolean) If the key is a script\n" |
| 54 | " \"iswitness\" : true|false, (boolean) If the address is a witness address\n" |
| 55 | " \"witness_version\" : version (numeric, optional) The version number of the witness program\n" |
| 56 | " \"witness_program\" : \"hex\" (string, optional) The hex value of the witness program\n" |
| 57 | "}\n" |
| 58 | "\nExamples:\n" |
| 59 | + HelpExampleCli("validateaddress", "\"1PSSGeFHDnKNxiEyFrD1wcEaHr9hrQDDWc\"") |
| 60 | + HelpExampleRpc("validateaddress", "\"1PSSGeFHDnKNxiEyFrD1wcEaHr9hrQDDWc\"") |
| 61 | ); |
| 62 | |
| 63 | CTxDestination dest = DecodeDestination(request.params[0].get_str()); |
| 64 | bool isValid = IsValidDestination(dest); |
| 65 | |
| 66 | UniValue ret(UniValue::VOBJ); |
| 67 | ret.pushKV("isvalid", isValid); |
| 68 | if (isValid) |
| 69 | { |
| 70 | |
| 71 | #ifdef ENABLE_WALLET |
| 72 | if (HasWallets() && IsDeprecatedRPCEnabled("validateaddress")) { |
| 73 | ret.pushKVs(getaddressinfo(request)); |
| 74 | } |
| 75 | #endif |
| 76 | if (ret["address"].isNull()) { |
| 77 | std::string currentAddress = EncodeDestination(dest); |
| 78 | ret.pushKV("address", currentAddress); |
| 79 | |
| 80 | CScript scriptPubKey = GetScriptForDestination(dest); |
| 81 | ret.pushKV("scriptPubKey", HexStr(scriptPubKey.begin(), scriptPubKey.end())); |
| 82 | |
| 83 | UniValue detail = DescribeAddress(dest); |
| 84 | ret.pushKVs(detail); |
| 85 | } |
| 86 | } |
| 87 | return ret; |
| 88 | } |
| 89 | |
| 90 | // Needed even with !ENABLE_WALLET, to pass (ignored) pointers around |
| 91 | class CWallet; |
nothing calls this directly
no test coverage detected