Changeset View
Changeset View
Standalone View
Standalone View
src/rpc/misc.cpp
Show All 33 Lines | |||||
#endif | #endif | ||||
static UniValue validateaddress(const Config &config, | static UniValue validateaddress(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
if (request.fHelp || request.params.size() != 1) { | if (request.fHelp || request.params.size() != 1) { | ||||
throw std::runtime_error( | throw std::runtime_error( | ||||
"validateaddress \"address\"\n" | "validateaddress \"address\"\n" | ||||
"\nReturn information about the given bitcoin address.\n" | "\nReturn information about the given bitcoin address.\n" | ||||
"DEPRECATION WARNING: Parts of this command have been deprecated " | |||||
"and moved to getaddressinfo. Clients must\n" | |||||
"transition to using getaddressinfo to access this information " | |||||
"before upgrading to v0.20. The following deprecated\n" | |||||
"fields have moved to getaddressinfo and will only be shown here " | |||||
"with -deprecatedrpc=validateaddress: ismine, iswatchonly,\n" | |||||
"script, hex, pubkeys, sigsrequired, pubkey, addresses, embedded, " | |||||
"iscompressed, account, timestamp, hdkeypath, kdmasterkeyid.\n" | |||||
"\nArguments:\n" | "\nArguments:\n" | ||||
"1. \"address\" (string, required) The bitcoin " | "1. \"address\" (string, required) The bitcoin " | ||||
"address to validate\n" | "address to validate\n" | ||||
"\nResult:\n" | "\nResult:\n" | ||||
"{\n" | "{\n" | ||||
" \"isvalid\" : true|false, (boolean) If the address is " | " \"isvalid\" : true|false, (boolean) If the address is " | ||||
"valid or not. If not, this is the only property returned.\n" | "valid or not. If not, this is the only property returned.\n" | ||||
" \"address\" : \"address\", (string) The bitcoin address " | " \"address\" : \"address\", (string) The bitcoin address " | ||||
Show All 13 Lines | static UniValue validateaddress(const Config &config, | ||||
CTxDestination dest = | CTxDestination dest = | ||||
DecodeDestination(request.params[0].get_str(), config.GetChainParams()); | DecodeDestination(request.params[0].get_str(), config.GetChainParams()); | ||||
bool isValid = IsValidDestination(dest); | bool isValid = IsValidDestination(dest); | ||||
UniValue ret(UniValue::VOBJ); | UniValue ret(UniValue::VOBJ); | ||||
ret.pushKV("isvalid", isValid); | ret.pushKV("isvalid", isValid); | ||||
if (isValid) { | if (isValid) { | ||||
#ifdef ENABLE_WALLET | |||||
if (HasWallets() && IsDeprecatedRPCEnabled(gArgs, "validateaddress")) { | |||||
ret.pushKVs(getaddressinfo(config, request)); | |||||
} | |||||
#endif | |||||
if (ret["address"].isNull()) { | if (ret["address"].isNull()) { | ||||
std::string currentAddress = EncodeDestination(dest, config); | std::string currentAddress = EncodeDestination(dest, config); | ||||
ret.pushKV("address", currentAddress); | ret.pushKV("address", currentAddress); | ||||
CScript scriptPubKey = GetScriptForDestination(dest); | CScript scriptPubKey = GetScriptForDestination(dest); | ||||
ret.pushKV("scriptPubKey", | ret.pushKV("scriptPubKey", | ||||
HexStr(scriptPubKey.begin(), scriptPubKey.end())); | HexStr(scriptPubKey.begin(), scriptPubKey.end())); | ||||
Show All 11 Lines | static UniValue createmultisig(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
if (request.fHelp || request.params.size() < 2 || | if (request.fHelp || request.params.size() < 2 || | ||||
request.params.size() > 2) { | request.params.size() > 2) { | ||||
std::string msg = | std::string msg = | ||||
"createmultisig nrequired [\"key\",...]\n" | "createmultisig nrequired [\"key\",...]\n" | ||||
"\nCreates a multi-signature address with n signature of m keys " | "\nCreates a multi-signature address with n signature of m keys " | ||||
"required.\n" | "required.\n" | ||||
"It returns a json object with the address and redeemScript.\n" | "It returns a json object with the address and redeemScript.\n" | ||||
"DEPRECATION WARNING: Using addresses with createmultisig is " | |||||
"deprecated. Clients must\n" | |||||
"transition to using addmultisigaddress to create multisig " | |||||
"addresses with addresses known\n" | |||||
"to the wallet before upgrading to v0.20. To use the deprecated " | |||||
"functionality, start bitcoind with -deprecatedrpc=createmultisig\n" | |||||
"\nArguments:\n" | "\nArguments:\n" | ||||
"1. nrequired (numeric, required) The number of required " | "1. nrequired (numeric, required) The number of required " | ||||
"signatures out of the n keys or addresses.\n" | "signatures out of the n keys or addresses.\n" | ||||
"2. \"keys\" (string, required) A json array of hex-encoded " | "2. \"keys\" (string, required) A json array of hex-encoded " | ||||
"public keys\n" | "public keys\n" | ||||
" [\n" | " [\n" | ||||
" \"key\" (string) The hex-encoded public key\n" | " \"key\" (string) The hex-encoded public key\n" | ||||
" ,...\n" | " ,...\n" | ||||
Show All 32 Lines | static UniValue createmultisig(const Config &config, | ||||
// Get the public keys | // Get the public keys | ||||
const UniValue &keys = request.params[1].get_array(); | const UniValue &keys = request.params[1].get_array(); | ||||
std::vector<CPubKey> pubkeys; | std::vector<CPubKey> pubkeys; | ||||
for (size_t i = 0; i < keys.size(); ++i) { | for (size_t i = 0; i < keys.size(); ++i) { | ||||
if (IsHex(keys[i].get_str()) && (keys[i].get_str().length() == 66 || | if (IsHex(keys[i].get_str()) && (keys[i].get_str().length() == 66 || | ||||
keys[i].get_str().length() == 130)) { | keys[i].get_str().length() == 130)) { | ||||
pubkeys.push_back(HexToPubKey(keys[i].get_str())); | pubkeys.push_back(HexToPubKey(keys[i].get_str())); | ||||
} else { | } else { | ||||
#ifdef ENABLE_WALLET | |||||
CWallet *const pwallet = GetWalletForJSONRPCRequest(request); | |||||
if (IsDeprecatedRPCEnabled(gArgs, "createmultisig") && | |||||
EnsureWalletIsAvailable(pwallet, false)) { | |||||
pubkeys.push_back(AddrToPubKey(config.GetChainParams(), pwallet, | |||||
keys[i].get_str())); | |||||
} else | |||||
#endif | |||||
throw JSONRPCError( | throw JSONRPCError( | ||||
RPC_INVALID_ADDRESS_OR_KEY, | RPC_INVALID_ADDRESS_OR_KEY, | ||||
strprintf("Invalid public key: %s\nNote that from v0.19.6, " | strprintf("Invalid public key: %s\n", keys[i].get_str())); | ||||
"createmultisig no longer accepts addresses." | |||||
" Clients must transition to using " | |||||
"addmultisigaddress to create multisig addresses " | |||||
"with addresses known to the wallet before " | |||||
"upgrading to v0.20." | |||||
" To use the deprecated functionality, start " | |||||
"bitcoind with -deprecatedrpc=createmultisig", | |||||
keys[i].get_str())); | |||||
} | } | ||||
} | } | ||||
// Construct using pay-to-script-hash: | // Construct using pay-to-script-hash: | ||||
CScript inner = CreateMultisigRedeemscript(required, pubkeys); | CScript inner = CreateMultisigRedeemscript(required, pubkeys); | ||||
CScriptID innerID(inner); | CScriptID innerID(inner); | ||||
UniValue result(UniValue::VOBJ); | UniValue result(UniValue::VOBJ); | ||||
▲ Show 20 Lines • Show All 293 Lines • Show Last 20 Lines |