Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/rpcwallet.cpp
Show First 20 Lines • Show All 3,403 Lines • ▼ Show 20 Lines | UniValue loadwallet(const Config &config, const JSONRPCRequest &request) { | ||||
UniValue obj(UniValue::VOBJ); | UniValue obj(UniValue::VOBJ); | ||||
obj.pushKV("name", wallet->GetName()); | obj.pushKV("name", wallet->GetName()); | ||||
obj.pushKV("warning", warning); | obj.pushKV("warning", warning); | ||||
return obj; | return obj; | ||||
} | } | ||||
UniValue createwallet(const Config &config, const JSONRPCRequest &request) { | |||||
if (request.fHelp || request.params.size() != 1) { | |||||
throw std::runtime_error( | |||||
"createwallet \"wallet_name\"\n" | |||||
"\nCreates and loads a new wallet.\n" | |||||
"\nArguments:\n" | |||||
"1. \"wallet_name\" (string, required) The name for the new " | |||||
"wallet. If this is a path, the wallet will be created at the path " | |||||
"location.\n" | |||||
"\nResult:\n" | |||||
"{\n" | |||||
" \"name\" : <wallet_name>, (string) The wallet name if " | |||||
"created successfully. If the wallet was created using a full " | |||||
"path, the wallet_name will be the full path.\n" | |||||
" \"warning\" : <warning>, (string) Warning message if " | |||||
"wallet was not loaded cleanly.\n" | |||||
"}\n" | |||||
"\nExamples:\n" + | |||||
HelpExampleCli("createwallet", "\"testwallet\"") + | |||||
HelpExampleRpc("createwallet", "\"testwallet\"")); | |||||
} | |||||
const CChainParams &chainParams = config.GetChainParams(); | |||||
std::string wallet_name = request.params[0].get_str(); | |||||
std::string error; | |||||
std::string warning; | |||||
fs::path wallet_path = fs::absolute(wallet_name, GetWalletDir()); | |||||
if (fs::symlink_status(wallet_path).type() != fs::file_not_found) { | |||||
throw JSONRPCError(RPC_WALLET_ERROR, | |||||
"Wallet " + wallet_name + " already exists."); | |||||
} | |||||
// Wallet::Verify will check if we're trying to create a wallet with a | |||||
// duplicate name. | |||||
if (!CWallet::Verify(chainParams, wallet_name, false, error, warning)) { | |||||
throw JSONRPCError(RPC_WALLET_ERROR, | |||||
"Wallet file verification failed: " + error); | |||||
} | |||||
std::shared_ptr<CWallet> const wallet = CWallet::CreateWalletFromFile( | |||||
chainParams, wallet_name, fs::absolute(wallet_name, GetWalletDir())); | |||||
if (!wallet) { | |||||
throw JSONRPCError(RPC_WALLET_ERROR, "Wallet creation failed."); | |||||
} | |||||
AddWallet(wallet); | |||||
wallet->postInitProcess(); | |||||
UniValue obj(UniValue::VOBJ); | |||||
obj.pushKV("name", wallet->GetName()); | |||||
obj.pushKV("warning", warning); | |||||
return obj; | |||||
} | |||||
static UniValue resendwallettransactions(const Config &config, | static UniValue resendwallettransactions(const Config &config, | ||||
const JSONRPCRequest &request) { | 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(); | ||||
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | ||||
return NullUniValue; | return NullUniValue; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 1,036 Lines • ▼ Show 20 Lines | |||||
static const ContextFreeRPCCommand commands[] = { | static const ContextFreeRPCCommand commands[] = { | ||||
// category name actor (function) argNames | // category name actor (function) argNames | ||||
// ------------------- ------------------------ ---------------------- ---------- | // ------------------- ------------------------ ---------------------- ---------- | ||||
{ "rawtransactions", "fundrawtransaction", fundrawtransaction, {"hexstring","options"} }, | { "rawtransactions", "fundrawtransaction", fundrawtransaction, {"hexstring","options"} }, | ||||
{ "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", "encryptwallet", encryptwallet, {"passphrase"} }, | { "wallet", "encryptwallet", encryptwallet, {"passphrase"} }, | ||||
{ "wallet", "getaccountaddress", getlabeladdress, {"account"} }, | { "wallet", "getaccountaddress", getlabeladdress, {"account"} }, | ||||
{ "wallet", "getlabeladdress", getlabeladdress, {"label"} }, | { "wallet", "getlabeladdress", getlabeladdress, {"label"} }, | ||||
{ "wallet", "getaccount", getaccount, {"address"} }, | { "wallet", "getaccount", getaccount, {"address"} }, | ||||
{ "wallet", "getaddressesbyaccount", getaddressesbyaccount, {"account"} }, | { "wallet", "getaddressesbyaccount", getaddressesbyaccount, {"account"} }, | ||||
{ "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"} }, | ||||
▲ Show 20 Lines • Show All 43 Lines • Show Last 20 Lines |