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", "")); | ||||
} | } | ||||
// Belt and suspenders check for disabled private keys | |||||
if (pwallet->IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS)) { | if (pwallet->IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS)) { | ||||
throw JSONRPCError(RPC_WALLET_ERROR, | throw JSONRPCError(RPC_WALLET_ERROR, | ||||
"Error: Private keys are disabled for this wallet"); | "Error: Private keys are disabled for this wallet"); | ||||
} | } | ||||
LOCK(pwallet->cs_wallet); | LOCK(pwallet->cs_wallet); | ||||
if (!pwallet->CanGetAddresses()) { | |||||
throw JSONRPCError(RPC_WALLET_ERROR, | |||||
"Error: This wallet has no available keys"); | |||||
} | |||||
// 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]); | ||||
} | } | ||||
OutputType output_type = pwallet->m_default_address_type; | OutputType output_type = pwallet->m_default_address_type; | ||||
if (!request.params[1].isNull()) { | if (!request.params[1].isNull()) { | ||||
▲ Show 20 Lines • Show All 104 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", "")); | ||||
} | } | ||||
// Belt and suspenders check for disabled private keys | |||||
if (pwallet->IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS)) { | if (pwallet->IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS)) { | ||||
throw JSONRPCError(RPC_WALLET_ERROR, | throw JSONRPCError(RPC_WALLET_ERROR, | ||||
"Error: Private keys are disabled for this wallet"); | "Error: Private keys are disabled for this wallet"); | ||||
} | } | ||||
LOCK(pwallet->cs_wallet); | LOCK(pwallet->cs_wallet); | ||||
if (!pwallet->CanGetAddresses(true)) { | |||||
throw JSONRPCError(RPC_WALLET_ERROR, | |||||
"Error: This wallet has no available keys"); | |||||
} | |||||
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 | ||||
? pwallet->m_default_change_type | ? pwallet->m_default_change_type | ||||
: pwallet->m_default_address_type; | : pwallet->m_default_address_type; | ||||
▲ Show 20 Lines • Show All 3,451 Lines • ▼ Show 20 Lines | static UniValue loadwallet(const Config &config, | ||||
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) { | request.params.size() > 3) { | ||||
throw std::runtime_error( | throw std::runtime_error( | ||||
"createwallet \"wallet_name\" ( disable_private_keys )\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) " | "2. disable_private_keys (boolean, optional, default: false) " | ||||
"Disable the possibility of private keys (only watchonlys are " | "Disable the possibility of private keys (only watchonlys are " | ||||
"possible in this mode).\n" | "possible in this mode).\n" | ||||
"3. blank (boolean, optional, default: false) Create a blank " | |||||
"wallet. A blank wallet has no keys or HD seed. One can be set " | |||||
"using sethdseed.\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 error; | std::string error; | ||||
std::string warning; | std::string warning; | ||||
bool disable_privatekeys = false; | uint64_t flags = 0; | ||||
if (!request.params[1].isNull()) { | if (!request.params[1].isNull() && request.params[1].get_bool()) { | ||||
disable_privatekeys = request.params[1].get_bool(); | flags |= WALLET_FLAG_DISABLE_PRIVATE_KEYS; | ||||
} | |||||
if (!request.params[2].isNull() && request.params[2].get_bool()) { | |||||
flags |= WALLET_FLAG_BLANK_WALLET; | |||||
} | } | ||||
WalletLocation location(request.params[0].get_str()); | WalletLocation location(request.params[0].get_str()); | ||||
if (location.Exists()) { | if (location.Exists()) { | ||||
throw JSONRPCError(RPC_WALLET_ERROR, | throw JSONRPCError(RPC_WALLET_ERROR, | ||||
"Wallet " + location.GetName() + " already exists."); | "Wallet " + location.GetName() + " 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, location, false, error, warning)) { | if (!CWallet::Verify(chainParams, location, 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 = | ||||
chainParams, location, | CWallet::CreateWalletFromFile(chainParams, location, flags); | ||||
(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,216 Lines • ▼ Show 20 Lines | if (pwallet->IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS)) { | ||||
throw JSONRPCError( | throw JSONRPCError( | ||||
RPC_WALLET_ERROR, | RPC_WALLET_ERROR, | ||||
"Cannot set a HD seed to a wallet with private keys disabled"); | "Cannot set a HD seed to a wallet with private keys disabled"); | ||||
} | } | ||||
LOCK2(cs_main, pwallet->cs_wallet); | LOCK2(cs_main, pwallet->cs_wallet); | ||||
// Do not do anything to non-HD wallets | // Do not do anything to non-HD wallets | ||||
if (!pwallet->IsHDEnabled()) { | if (!pwallet->CanSupportFeature(FEATURE_HD)) { | ||||
throw JSONRPCError( | throw JSONRPCError( | ||||
RPC_WALLET_ERROR, | RPC_WALLET_ERROR, | ||||
"Cannot set a HD seed on a non-HD wallet. Start with " | "Cannot set a HD seed on a non-HD wallet. Start with " | ||||
"-upgradewallet in order to upgrade a non-HD wallet to HD"); | "-upgradewallet in order to upgrade a non-HD wallet to HD"); | ||||
} | } | ||||
EnsureWalletIsUnlocked(pwallet); | EnsureWalletIsUnlocked(pwallet); | ||||
▲ Show 20 Lines • Show All 330 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", "disable_private_keys"} }, | { "wallet", "createwallet", createwallet, {"wallet_name", "disable_private_keys", "blank"} }, | ||||
{ "wallet", "encryptwallet", encryptwallet, {"passphrase"} }, | { "wallet", "encryptwallet", encryptwallet, {"passphrase"} }, | ||||
{ "wallet", "getaddressinfo", getaddressinfo, {"address"} }, | { "wallet", "getaddressinfo", getaddressinfo, {"address"} }, | ||||
{ "wallet", "getbalance", getbalance, {"account|dummy","minconf","include_watchonly"} }, | { "wallet", "getbalance", getbalance, {"account|dummy","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 50 Lines • Show Last 20 Lines |