Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/rpcwallet.cpp
Show First 20 Lines • Show All 174 Lines • ▼ Show 20 Lines | if (request.fHelp || request.params.size() > 2) { | ||||
"the default label. The label does not need to exist, it will be " | "the default label. The label does not need to exist, it will be " | ||||
"created if there is no label by the given name.\n" | "created if there is no label by the given name.\n" | ||||
"\nResult:\n" | "\nResult:\n" | ||||
"\"address\" (string) The new bitcoin address\n" | "\"address\" (string) The new bitcoin address\n" | ||||
"\nExamples:\n" + | "\nExamples:\n" + | ||||
HelpExampleRpc("getnewaddress", "")); | HelpExampleRpc("getnewaddress", "")); | ||||
} | } | ||||
if (pwallet->IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS)) { | |||||
throw JSONRPCError(RPC_WALLET_ERROR, | |||||
"Error: Private keys are disabled for this wallet"); | |||||
} | |||||
LOCK2(cs_main, pwallet->cs_wallet); | LOCK2(cs_main, pwallet->cs_wallet); | ||||
// Parse the label first so we don't generate a key if there's an error | // Parse the label first so we don't generate a key if there's an error | ||||
std::string label; | std::string label; | ||||
if (!request.params[0].isNull()) { | if (!request.params[0].isNull()) { | ||||
label = LabelFromValue(request.params[0]); | label = LabelFromValue(request.params[0]); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 131 Lines • ▼ Show 20 Lines | if (request.fHelp || request.params.size() > 1) { | ||||
"This is for use with raw transactions, NOT normal use.\n" | "This is for use with raw transactions, NOT normal use.\n" | ||||
"\nResult:\n" | "\nResult:\n" | ||||
"\"address\" (string) The address\n" | "\"address\" (string) The address\n" | ||||
"\nExamples:\n" + | "\nExamples:\n" + | ||||
HelpExampleCli("getrawchangeaddress", "") + | HelpExampleCli("getrawchangeaddress", "") + | ||||
HelpExampleRpc("getrawchangeaddress", "")); | HelpExampleRpc("getrawchangeaddress", "")); | ||||
} | } | ||||
if (pwallet->IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS)) { | |||||
throw JSONRPCError(RPC_WALLET_ERROR, | |||||
"Error: Private keys are disabled for this wallet"); | |||||
} | |||||
LOCK2(cs_main, pwallet->cs_wallet); | LOCK2(cs_main, pwallet->cs_wallet); | ||||
if (!pwallet->IsLocked()) { | if (!pwallet->IsLocked()) { | ||||
pwallet->TopUpKeyPool(); | pwallet->TopUpKeyPool(); | ||||
} | } | ||||
OutputType output_type = | OutputType output_type = | ||||
pwallet->m_default_change_type != OutputType::CHANGE_AUTO | pwallet->m_default_change_type != OutputType::CHANGE_AUTO | ||||
▲ Show 20 Lines • Show All 2,649 Lines • ▼ Show 20 Lines | if (request.fHelp || request.params.size() > 1) { | ||||
"\nArguments\n" | "\nArguments\n" | ||||
"1. newsize (numeric, optional, default=100) " | "1. newsize (numeric, optional, default=100) " | ||||
"The new keypool size\n" | "The new keypool size\n" | ||||
"\nExamples:\n" + | "\nExamples:\n" + | ||||
HelpExampleCli("keypoolrefill", "") + | HelpExampleCli("keypoolrefill", "") + | ||||
HelpExampleRpc("keypoolrefill", "")); | HelpExampleRpc("keypoolrefill", "")); | ||||
} | } | ||||
if (pwallet->IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS)) { | |||||
throw JSONRPCError(RPC_WALLET_ERROR, | |||||
"Error: Private keys are disabled for this wallet"); | |||||
} | |||||
LOCK2(cs_main, pwallet->cs_wallet); | LOCK2(cs_main, pwallet->cs_wallet); | ||||
// 0 is interpreted by TopUpKeyPool() as the default keypool size given by | // 0 is interpreted by TopUpKeyPool() as the default keypool size given by | ||||
// -keypool | // -keypool | ||||
unsigned int kpSize = 0; | unsigned int kpSize = 0; | ||||
if (!request.params[0].isNull()) { | if (!request.params[0].isNull()) { | ||||
if (request.params[0].get_int() < 0) { | if (request.params[0].get_int() < 0) { | ||||
throw JSONRPCError(RPC_INVALID_PARAMETER, | throw JSONRPCError(RPC_INVALID_PARAMETER, | ||||
▲ Show 20 Lines • Show All 600 Lines • ▼ Show 20 Lines | if (request.fHelp || request.params.size() != 0) { | ||||
"fee configuration, set in " + | "fee configuration, set in " + | ||||
CURRENCY_UNIT + | CURRENCY_UNIT + | ||||
"/kB\n" | "/kB\n" | ||||
" \"hdseedid\": \"<hash160>\" (string, optional) the " | " \"hdseedid\": \"<hash160>\" (string, optional) the " | ||||
"Hash160 of the HD seed (only present when HD is enabled)\n" | "Hash160 of the HD seed (only present when HD is enabled)\n" | ||||
" \"hdmasterkeyid\": \"<hash160>\" (string, optional) alias " | " \"hdmasterkeyid\": \"<hash160>\" (string, optional) alias " | ||||
"for hdseedid retained for backwards-compatibility. Will be " | "for hdseedid retained for backwards-compatibility. Will be " | ||||
"removed in V0.21.\n" | "removed in V0.21.\n" | ||||
" \"private_keys_enabled\": true|false (boolean) false if " | |||||
"privatekeys are disabled for this wallet (enforced watch-only " | |||||
"wallet)\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 22 Lines | static UniValue getwalletinfo(const Config &config, | ||||
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 (!seed_id.IsNull()) { | if (!seed_id.IsNull()) { | ||||
obj.pushKV("hdseedid", seed_id.GetHex()); | obj.pushKV("hdseedid", seed_id.GetHex()); | ||||
obj.pushKV("hdmasterkeyid", seed_id.GetHex()); | obj.pushKV("hdmasterkeyid", seed_id.GetHex()); | ||||
} | } | ||||
obj.pushKV("private_keys_enabled", | |||||
!pwallet->IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS)); | |||||
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( | ||||
"listwallets\n" | "listwallets\n" | ||||
▲ Show 20 Lines • Show All 88 Lines • ▼ Show 20 Lines | static UniValue loadwallet(const Config &config, | ||||
obj.pushKV("name", wallet->GetName()); | obj.pushKV("name", wallet->GetName()); | ||||
obj.pushKV("warning", warning); | obj.pushKV("warning", warning); | ||||
return obj; | return obj; | ||||
} | } | ||||
static UniValue createwallet(const Config &config, | static UniValue createwallet(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
if (request.fHelp || request.params.size() != 1) { | if (request.fHelp || request.params.size() < 1 || | ||||
request.params.size() > 2) { | |||||
throw std::runtime_error( | throw std::runtime_error( | ||||
"createwallet \"wallet_name\"\n" | "createwallet \"wallet_name\" ( disable_private_keys )\n" | ||||
"\nCreates and loads a new wallet.\n" | "\nCreates and loads a new wallet.\n" | ||||
"\nArguments:\n" | "\nArguments:\n" | ||||
"1. \"wallet_name\" (string, required) The name for the new " | "1. \"wallet_name\" (string, required) The name for the new " | ||||
"wallet. If this is a path, the wallet will be created at the path " | "wallet. If this is a path, the wallet will be created at the path " | ||||
"location.\n" | "location.\n" | ||||
"2. disable_private_keys (boolean, optional, default: false) " | |||||
"Disable the possibility of private keys (only watchonlys are " | |||||
"possible in this mode).\n" | |||||
"\nResult:\n" | "\nResult:\n" | ||||
"{\n" | "{\n" | ||||
" \"name\" : <wallet_name>, (string) The wallet name if " | " \"name\" : <wallet_name>, (string) The wallet name if " | ||||
"created successfully. If the wallet was created using a full " | "created successfully. If the wallet was created using a full " | ||||
"path, the wallet_name will be the full path.\n" | "path, the wallet_name will be the full path.\n" | ||||
" \"warning\" : <warning>, (string) Warning message if " | " \"warning\" : <warning>, (string) Warning message if " | ||||
"wallet was not loaded cleanly.\n" | "wallet was not loaded cleanly.\n" | ||||
"}\n" | "}\n" | ||||
"\nExamples:\n" + | "\nExamples:\n" + | ||||
HelpExampleCli("createwallet", "\"testwallet\"") + | HelpExampleCli("createwallet", "\"testwallet\"") + | ||||
HelpExampleRpc("createwallet", "\"testwallet\"")); | HelpExampleRpc("createwallet", "\"testwallet\"")); | ||||
} | } | ||||
const CChainParams &chainParams = config.GetChainParams(); | const CChainParams &chainParams = config.GetChainParams(); | ||||
std::string wallet_name = request.params[0].get_str(); | std::string wallet_name = request.params[0].get_str(); | ||||
std::string error; | std::string error; | ||||
std::string warning; | std::string warning; | ||||
bool disable_privatekeys = false; | |||||
if (!request.params[1].isNull()) { | |||||
disable_privatekeys = request.params[1].get_bool(); | |||||
} | |||||
fs::path wallet_path = fs::absolute(wallet_name, GetWalletDir()); | fs::path wallet_path = fs::absolute(wallet_name, GetWalletDir()); | ||||
if (fs::symlink_status(wallet_path).type() != fs::file_not_found) { | if (fs::symlink_status(wallet_path).type() != fs::file_not_found) { | ||||
throw JSONRPCError(RPC_WALLET_ERROR, | throw JSONRPCError(RPC_WALLET_ERROR, | ||||
"Wallet " + wallet_name + " already exists."); | "Wallet " + wallet_name + " already exists."); | ||||
} | } | ||||
// Wallet::Verify will check if we're trying to create a wallet with a | // Wallet::Verify will check if we're trying to create a wallet with a | ||||
// duplicate name. | // duplicate name. | ||||
if (!CWallet::Verify(chainParams, wallet_name, false, error, warning)) { | if (!CWallet::Verify(chainParams, wallet_name, false, error, warning)) { | ||||
throw JSONRPCError(RPC_WALLET_ERROR, | throw JSONRPCError(RPC_WALLET_ERROR, | ||||
"Wallet file verification failed: " + error); | "Wallet file verification failed: " + error); | ||||
} | } | ||||
std::shared_ptr<CWallet> const wallet = CWallet::CreateWalletFromFile( | std::shared_ptr<CWallet> const wallet = CWallet::CreateWalletFromFile( | ||||
chainParams, wallet_name, fs::absolute(wallet_name, GetWalletDir())); | chainParams, wallet_name, fs::absolute(wallet_name, GetWalletDir()), | ||||
(disable_privatekeys ? uint64_t(WALLET_FLAG_DISABLE_PRIVATE_KEYS) : 0)); | |||||
if (!wallet) { | if (!wallet) { | ||||
throw JSONRPCError(RPC_WALLET_ERROR, "Wallet creation failed."); | throw JSONRPCError(RPC_WALLET_ERROR, "Wallet creation failed."); | ||||
} | } | ||||
AddWallet(wallet); | AddWallet(wallet); | ||||
wallet->postInitProcess(); | wallet->postInitProcess(); | ||||
UniValue obj(UniValue::VOBJ); | UniValue obj(UniValue::VOBJ); | ||||
▲ Show 20 Lines • Show All 1,644 Lines • ▼ Show 20 Lines | static const ContextFreeRPCCommand commands[] = { | ||||
// ------------------- ------------------------ ---------------------- ---------- | // ------------------- ------------------------ ---------------------- ---------- | ||||
{ "rawtransactions", "fundrawtransaction", fundrawtransaction, {"hexstring","options"} }, | { "rawtransactions", "fundrawtransaction", fundrawtransaction, {"hexstring","options"} }, | ||||
{ "wallet", "walletprocesspsbt", walletprocesspsbt, {"psbt","sign","sighashtype","bip32derivs"} }, | { "wallet", "walletprocesspsbt", walletprocesspsbt, {"psbt","sign","sighashtype","bip32derivs"} }, | ||||
{ "wallet", "walletcreatefundedpsbt", walletcreatefundedpsbt, {"inputs","outputs","locktime","options","bip32derivs"} }, | { "wallet", "walletcreatefundedpsbt", walletcreatefundedpsbt, {"inputs","outputs","locktime","options","bip32derivs"} }, | ||||
{ "hidden", "resendwallettransactions", resendwallettransactions, {} }, | { "hidden", "resendwallettransactions", resendwallettransactions, {} }, | ||||
{ "wallet", "abandontransaction", abandontransaction, {"txid"} }, | { "wallet", "abandontransaction", abandontransaction, {"txid"} }, | ||||
{ "wallet", "addmultisigaddress", addmultisigaddress, {"nrequired","keys","label|account"} }, | { "wallet", "addmultisigaddress", addmultisigaddress, {"nrequired","keys","label|account"} }, | ||||
{ "wallet", "backupwallet", backupwallet, {"destination"} }, | { "wallet", "backupwallet", backupwallet, {"destination"} }, | ||||
{ "wallet", "createwallet", createwallet, {"wallet_name"} }, | { "wallet", "createwallet", createwallet, {"wallet_name", "disable_private_keys"} }, | ||||
{ "wallet", "encryptwallet", encryptwallet, {"passphrase"} }, | { "wallet", "encryptwallet", encryptwallet, {"passphrase"} }, | ||||
{ "wallet", "getaddressinfo", getaddressinfo, {"address"} }, | { "wallet", "getaddressinfo", getaddressinfo, {"address"} }, | ||||
{ "wallet", "getbalance", getbalance, {"account","minconf","include_watchonly"} }, | { "wallet", "getbalance", getbalance, {"account","minconf","include_watchonly"} }, | ||||
{ "wallet", "getnewaddress", getnewaddress, {"label|account", "address_type"} }, | { "wallet", "getnewaddress", getnewaddress, {"label|account", "address_type"} }, | ||||
{ "wallet", "getrawchangeaddress", getrawchangeaddress, {"address_type"} }, | { "wallet", "getrawchangeaddress", getrawchangeaddress, {"address_type"} }, | ||||
{ "wallet", "getreceivedbyaddress", getreceivedbyaddress, {"address","minconf"} }, | { "wallet", "getreceivedbyaddress", getreceivedbyaddress, {"address","minconf"} }, | ||||
{ "wallet", "gettransaction", gettransaction, {"txid","include_watchonly"} }, | { "wallet", "gettransaction", gettransaction, {"txid","include_watchonly"} }, | ||||
{ "wallet", "getunconfirmedbalance", getunconfirmedbalance, {} }, | { "wallet", "getunconfirmedbalance", getunconfirmedbalance, {} }, | ||||
▲ Show 20 Lines • Show All 51 Lines • Show Last 20 Lines |