Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/rpcwallet.cpp
Show First 20 Lines • Show All 3,271 Lines • ▼ Show 20 Lines | if (request.fHelp || request.params.size() != 0) { | ||||
"keys are used)\n" | "keys are used)\n" | ||||
" \"unlocked_until\": ttt, (numeric) the timestamp in " | " \"unlocked_until\": ttt, (numeric) the timestamp in " | ||||
"seconds since epoch (midnight Jan 1 1970 GMT) that the wallet is " | "seconds since epoch (midnight Jan 1 1970 GMT) that the wallet is " | ||||
"unlocked for transfers, or 0 if the wallet is locked\n" | "unlocked for transfers, or 0 if the wallet is locked\n" | ||||
" \"paytxfee\": x.xxxx, (numeric) the transaction " | " \"paytxfee\": x.xxxx, (numeric) the transaction " | ||||
"fee configuration, set in " + | "fee configuration, set in " + | ||||
CURRENCY_UNIT + | CURRENCY_UNIT + | ||||
"/kB\n" | "/kB\n" | ||||
" \"hdmasterkeyid\": \"<hash160>\" (string, optional) the " | " \"hdseedid\": \"<hash160>\" (string, optional) the " | ||||
"Hash160 of the HD master pubkey (only present when HD is " | "Hash160 of the HD seed (only present when HD is enabled)\n" | ||||
"enabled)\n" | |||||
"}\n" | "}\n" | ||||
"\nExamples:\n" + | "\nExamples:\n" + | ||||
HelpExampleCli("getwalletinfo", "") + | HelpExampleCli("getwalletinfo", "") + | ||||
HelpExampleRpc("getwalletinfo", "")); | HelpExampleRpc("getwalletinfo", "")); | ||||
} | } | ||||
// Make sure the results are valid at least up to the most recent block | // Make sure the results are valid at least up to the most recent block | ||||
// the user could have gotten from another RPC command prior to now | // the user could have gotten from another RPC command prior to now | ||||
Show All 9 Lines | static UniValue getwalletinfo(const Config &config, | ||||
obj.pushKV("balance", ValueFromAmount(pwallet->GetBalance())); | obj.pushKV("balance", ValueFromAmount(pwallet->GetBalance())); | ||||
obj.pushKV("unconfirmed_balance", | obj.pushKV("unconfirmed_balance", | ||||
ValueFromAmount(pwallet->GetUnconfirmedBalance())); | ValueFromAmount(pwallet->GetUnconfirmedBalance())); | ||||
obj.pushKV("immature_balance", | obj.pushKV("immature_balance", | ||||
ValueFromAmount(pwallet->GetImmatureBalance())); | ValueFromAmount(pwallet->GetImmatureBalance())); | ||||
obj.pushKV("txcount", (int)pwallet->mapWallet.size()); | obj.pushKV("txcount", (int)pwallet->mapWallet.size()); | ||||
obj.pushKV("keypoololdest", pwallet->GetOldestKeyPoolTime()); | obj.pushKV("keypoololdest", pwallet->GetOldestKeyPoolTime()); | ||||
obj.pushKV("keypoolsize", (int64_t)kpExternalSize); | obj.pushKV("keypoolsize", (int64_t)kpExternalSize); | ||||
CKeyID masterKeyID = pwallet->GetHDChain().masterKeyID; | CKeyID seed_id = pwallet->GetHDChain().seed_id; | ||||
if (!masterKeyID.IsNull() && pwallet->CanSupportFeature(FEATURE_HD_SPLIT)) { | if (!seed_id.IsNull() && pwallet->CanSupportFeature(FEATURE_HD_SPLIT)) { | ||||
obj.pushKV("keypoolsize_hd_internal", | obj.pushKV("keypoolsize_hd_internal", | ||||
int64_t(pwallet->GetKeyPoolSize() - kpExternalSize)); | int64_t(pwallet->GetKeyPoolSize() - kpExternalSize)); | ||||
} | } | ||||
if (pwallet->IsCrypted()) { | if (pwallet->IsCrypted()) { | ||||
obj.pushKV("unlocked_until", pwallet->nRelockTime); | obj.pushKV("unlocked_until", pwallet->nRelockTime); | ||||
} | } | ||||
obj.pushKV("paytxfee", ValueFromAmount(pwallet->m_pay_tx_fee.GetFeePerK())); | obj.pushKV("paytxfee", ValueFromAmount(pwallet->m_pay_tx_fee.GetFeePerK())); | ||||
if (!masterKeyID.IsNull()) { | if (!seed_id.IsNull()) { | ||||
obj.pushKV("hdmasterkeyid", masterKeyID.GetHex()); | obj.pushKV("hdseedid", seed_id.GetHex()); | ||||
} | } | ||||
return obj; | return obj; | ||||
} | } | ||||
static UniValue listwallets(const Config &config, | static UniValue listwallets(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
if (request.fHelp || request.params.size() != 0) { | if (request.fHelp || request.params.size() != 0) { | ||||
throw std::runtime_error( | throw std::runtime_error( | ||||
▲ Show 20 Lines • Show All 956 Lines • ▼ Show 20 Lines | if (request.fHelp || request.params.size() != 1) { | ||||
"is \"multisig\")\n" | "is \"multisig\")\n" | ||||
" \"pubkey\" : \"publickeyhex\", (string, optional) The hex " | " \"pubkey\" : \"publickeyhex\", (string, optional) The hex " | ||||
"value of the raw public key, for single-key addresses (possibly " | "value of the raw public key, for single-key addresses (possibly " | ||||
"embedded in P2SH or P2WSH)\n" | "embedded in P2SH or P2WSH)\n" | ||||
" \"embedded\" : {...}, (object, optional) Information " | " \"embedded\" : {...}, (object, optional) Information " | ||||
"about the address embedded in P2SH or P2WSH, if relevant and " | "about the address embedded in P2SH or P2WSH, if relevant and " | ||||
"known. It includes all getaddressinfo output fields for the " | "known. It includes all getaddressinfo output fields for the " | ||||
"embedded address, excluding metadata (\"timestamp\", " | "embedded address, excluding metadata (\"timestamp\", " | ||||
"\"hdkeypath\", \"hdmasterkeyid\") and relation to the wallet " | "\"hdkeypath\", \"hdseedid\") and relation to the wallet " | ||||
"(\"ismine\", \"iswatchonly\", \"account\").\n" | "(\"ismine\", \"iswatchonly\", \"account\").\n" | ||||
" \"iscompressed\" : true|false, (boolean) If the address is " | " \"iscompressed\" : true|false, (boolean) If the address is " | ||||
"compressed\n" | "compressed\n" | ||||
" \"account\" : \"account\" (string) The account " | " \"account\" : \"account\" (string) The account " | ||||
"associated with the address, \"\" is the default account\n" | "associated with the address, \"\" is the default account\n" | ||||
" \"timestamp\" : timestamp, (number, optional) The creation " | " \"timestamp\" : timestamp, (number, optional) The creation " | ||||
"time of the key if available in seconds since epoch (Jan 1 1970 " | "time of the key if available in seconds since epoch (Jan 1 1970 " | ||||
"GMT)\n" | "GMT)\n" | ||||
" \"hdkeypath\" : \"keypath\" (string, optional) The HD " | " \"hdkeypath\" : \"keypath\" (string, optional) The HD " | ||||
"keypath if the key is HD and available\n" | "keypath if the key is HD and available\n" | ||||
" \"hdmasterkeyid\" : \"<hash160>\" (string, optional) The " | " \"hdseedid\" : \"<hash160>\" (string, optional) The " | ||||
"Hash160 of the HD master pubkey\n" | "Hash160 of the HD master pubkey\n" | ||||
"}\n" | "}\n" | ||||
"\nExamples:\n" + | "\nExamples:\n" + | ||||
HelpExampleCli("getaddressinfo", | HelpExampleCli("getaddressinfo", | ||||
"\"1PSSGeFHDnKNxiEyFrD1wcEaHr9hrQDDWc\"") + | "\"1PSSGeFHDnKNxiEyFrD1wcEaHr9hrQDDWc\"") + | ||||
HelpExampleRpc("getaddressinfo", | HelpExampleRpc("getaddressinfo", | ||||
"\"1PSSGeFHDnKNxiEyFrD1wcEaHr9hrQDDWc\"")); | "\"1PSSGeFHDnKNxiEyFrD1wcEaHr9hrQDDWc\"")); | ||||
} | } | ||||
Show All 37 Lines | if (!meta) { | ||||
if (it != pwallet->m_script_metadata.end()) { | if (it != pwallet->m_script_metadata.end()) { | ||||
meta = &it->second; | meta = &it->second; | ||||
} | } | ||||
} | } | ||||
if (meta) { | if (meta) { | ||||
ret.pushKV("timestamp", meta->nCreateTime); | ret.pushKV("timestamp", meta->nCreateTime); | ||||
if (!meta->hdKeypath.empty()) { | if (!meta->hdKeypath.empty()) { | ||||
ret.pushKV("hdkeypath", meta->hdKeypath); | ret.pushKV("hdkeypath", meta->hdKeypath); | ||||
ret.pushKV("hdmasterkeyid", meta->hdMasterKeyID.GetHex()); | ret.pushKV("hdseedid", meta->hd_seed_id.GetHex()); | ||||
} | } | ||||
} | } | ||||
return ret; | return ret; | ||||
} | } | ||||
static UniValue sethdseed(const Config &config, const JSONRPCRequest &request) { | static UniValue sethdseed(const Config &config, const JSONRPCRequest &request) { | ||||
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | ||||
CWallet *const pwallet = wallet.get(); | CWallet *const pwallet = wallet.get(); | ||||
Show All 24 Lines | if (request.fHelp || request.params.size() > 2) { | ||||
"enabled) from the existing\n" | "enabled) from the existing\n" | ||||
" keypool will be used until it has " | " keypool will be used until it has " | ||||
"been depleted.\n" | "been depleted.\n" | ||||
"2. \"seed\" (string, optional) The WIF private key " | "2. \"seed\" (string, optional) The WIF private key " | ||||
"to use as the new HD seed; if not provided a random seed will be " | "to use as the new HD seed; if not provided a random seed will be " | ||||
"used.\n" | "used.\n" | ||||
" The seed value can be retrieved " | " The seed value can be retrieved " | ||||
"using the dumpwallet command. It is the private key marked " | "using the dumpwallet command. It is the private key marked " | ||||
"hdmaster=1\n" | "hdseed=1\n" | ||||
"\nExamples:\n" + | "\nExamples:\n" + | ||||
HelpExampleCli("sethdseed", "") + | HelpExampleCli("sethdseed", "") + | ||||
HelpExampleCli("sethdseed", "false") + | HelpExampleCli("sethdseed", "false") + | ||||
HelpExampleCli("sethdseed", "true \"wifkey\"") + | HelpExampleCli("sethdseed", "true \"wifkey\"") + | ||||
HelpExampleRpc("sethdseed", "true, \"wifkey\"")); | HelpExampleRpc("sethdseed", "true, \"wifkey\"")); | ||||
} | } | ||||
if (IsInitialBlockDownload()) { | if (IsInitialBlockDownload()) { | ||||
Show All 16 Lines | static UniValue sethdseed(const Config &config, const JSONRPCRequest &request) { | ||||
bool flush_key_pool = true; | bool flush_key_pool = true; | ||||
if (!request.params[0].isNull()) { | if (!request.params[0].isNull()) { | ||||
flush_key_pool = request.params[0].get_bool(); | flush_key_pool = request.params[0].get_bool(); | ||||
} | } | ||||
CPubKey master_pub_key; | CPubKey master_pub_key; | ||||
if (request.params[1].isNull()) { | if (request.params[1].isNull()) { | ||||
master_pub_key = pwallet->GenerateNewHDMasterKey(); | master_pub_key = pwallet->GenerateNewSeed(); | ||||
} else { | } else { | ||||
CKey key = DecodeSecret(request.params[1].get_str()); | CKey key = DecodeSecret(request.params[1].get_str()); | ||||
if (!key.IsValid()) { | if (!key.IsValid()) { | ||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, | throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, | ||||
"Invalid private key"); | "Invalid private key"); | ||||
} | } | ||||
if (HaveKey(*pwallet, key)) { | if (HaveKey(*pwallet, key)) { | ||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, | throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, | ||||
"Already have this key (either as an HD seed or " | "Already have this key (either as an HD seed or " | ||||
"as a loose private key)"); | "as a loose private key)"); | ||||
} | } | ||||
master_pub_key = pwallet->DeriveNewMasterHDKey(key); | master_pub_key = pwallet->DeriveNewSeed(key); | ||||
} | } | ||||
pwallet->SetHDMasterKey(master_pub_key); | pwallet->SetHDSeed(master_pub_key); | ||||
if (flush_key_pool) { | if (flush_key_pool) { | ||||
pwallet->NewKeyPool(); | pwallet->NewKeyPool(); | ||||
} | } | ||||
return NullUniValue; | return NullUniValue; | ||||
} | } | ||||
// clang-format off | // clang-format off | ||||
static const ContextFreeRPCCommand commands[] = { | static const ContextFreeRPCCommand commands[] = { | ||||
// category name actor (function) argNames | // category name actor (function) argNames | ||||
▲ Show 20 Lines • Show All 57 Lines • Show Last 20 Lines |