Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/rpcwallet.cpp
Show First 20 Lines • Show All 3,277 Lines • ▼ Show 20 Lines | for (CWallet *pwallet : GetWallets()) { | ||||
LOCK(pwallet->cs_wallet); | LOCK(pwallet->cs_wallet); | ||||
obj.push_back(pwallet->GetName()); | obj.push_back(pwallet->GetName()); | ||||
} | } | ||||
return obj; | return obj; | ||||
} | } | ||||
UniValue loadwallet(const Config &config, const JSONRPCRequest &request) { | |||||
if (request.fHelp || request.params.size() != 1) { | |||||
throw std::runtime_error( | |||||
"loadwallet \"filename\"\n" | |||||
"\nLoads a wallet from a wallet file or directory." | |||||
"\nNote that all wallet command-line options used when starting " | |||||
"bitcoind will be" | |||||
"\napplied to the new wallet (eg -zapwallettxes, upgradewallet, " | |||||
"rescan, etc).\n" | |||||
"\nArguments:\n" | |||||
"1. \"filename\" (string, required) The wallet directory or " | |||||
".dat file.\n" | |||||
"\nResult:\n" | |||||
"{\n" | |||||
" \"name\" : <wallet_name>, (string) The wallet name if " | |||||
"loaded successfully.\n" | |||||
" \"warning\" : <warning>, (string) Warning message if " | |||||
"wallet was not loaded cleanly.\n" | |||||
"}\n" | |||||
"\nExamples:\n" + | |||||
HelpExampleCli("loadwallet", "\"test.dat\"") + | |||||
HelpExampleRpc("loadwallet", "\"test.dat\"")); | |||||
} | |||||
const CChainParams &chainParams = config.GetChainParams(); | |||||
std::string wallet_file = request.params[0].get_str(); | |||||
std::string error; | |||||
fs::path wallet_path = fs::absolute(wallet_file, GetWalletDir()); | |||||
if (fs::symlink_status(wallet_path).type() == fs::file_not_found) { | |||||
throw JSONRPCError(RPC_WALLET_NOT_FOUND, | |||||
"Wallet " + wallet_file + " not found."); | |||||
} | |||||
std::string warning; | |||||
if (!CWallet::Verify(chainParams, wallet_file, false, error, warning)) { | |||||
throw JSONRPCError(RPC_WALLET_ERROR, | |||||
"Wallet file verification failed: " + error); | |||||
} | |||||
CWallet *const wallet = CWallet::CreateWalletFromFile( | |||||
chainParams, wallet_file, fs::absolute(wallet_file, GetWalletDir())); | |||||
if (!wallet) { | |||||
throw JSONRPCError(RPC_WALLET_ERROR, "Wallet loading 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) { | ||||
CWallet *const pwallet = GetWalletForJSONRPCRequest(request); | CWallet *const pwallet = GetWalletForJSONRPCRequest(request); | ||||
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | ||||
return NullUniValue; | return NullUniValue; | ||||
} | } | ||||
if (request.fHelp || request.params.size() != 0) { | if (request.fHelp || request.params.size() != 0) { | ||||
▲ Show 20 Lines • Show All 976 Lines • ▼ Show 20 Lines | static const ContextFreeRPCCommand commands[] = { | ||||
{ "wallet", "listlockunspent", listlockunspent, {} }, | { "wallet", "listlockunspent", listlockunspent, {} }, | ||||
{ "wallet", "listreceivedbylabel", listreceivedbylabel, {"minconf","include_empty","include_watchonly"} }, | { "wallet", "listreceivedbylabel", listreceivedbylabel, {"minconf","include_empty","include_watchonly"} }, | ||||
{ "wallet", "listreceivedbyaccount", listreceivedbylabel, {"minconf","include_empty","include_watchonly"} }, | { "wallet", "listreceivedbyaccount", listreceivedbylabel, {"minconf","include_empty","include_watchonly"} }, | ||||
{ "wallet", "listreceivedbyaddress", listreceivedbyaddress, {"minconf","include_empty","include_watchonly","address_filter"} }, | { "wallet", "listreceivedbyaddress", listreceivedbyaddress, {"minconf","include_empty","include_watchonly","address_filter"} }, | ||||
{ "wallet", "listsinceblock", listsinceblock, {"blockhash","target_confirmations","include_watchonly","include_removed"} }, | { "wallet", "listsinceblock", listsinceblock, {"blockhash","target_confirmations","include_watchonly","include_removed"} }, | ||||
{ "wallet", "listtransactions", listtransactions, {"account","count","skip","include_watchonly"} }, | { "wallet", "listtransactions", listtransactions, {"account","count","skip","include_watchonly"} }, | ||||
{ "wallet", "listunspent", listunspent, {"minconf","maxconf","addresses","include_unsafe","query_options"} }, | { "wallet", "listunspent", listunspent, {"minconf","maxconf","addresses","include_unsafe","query_options"} }, | ||||
{ "wallet", "listwallets", listwallets, {} }, | { "wallet", "listwallets", listwallets, {} }, | ||||
{ "wallet", "loadwallet", loadwallet, {"filename"} }, | |||||
{ "wallet", "lockunspent", lockunspent, {"unlock","transactions"} }, | { "wallet", "lockunspent", lockunspent, {"unlock","transactions"} }, | ||||
{ "wallet", "move", movecmd, {"fromaccount","toaccount","amount","minconf","comment"} }, | { "wallet", "move", movecmd, {"fromaccount","toaccount","amount","minconf","comment"} }, | ||||
{ "wallet", "rescanblockchain", rescanblockchain, {"start_height", "stop_height"} }, | { "wallet", "rescanblockchain", rescanblockchain, {"start_height", "stop_height"} }, | ||||
{ "wallet", "sendfrom", sendfrom, {"fromaccount","toaddress","amount","minconf","comment","comment_to"} }, | { "wallet", "sendfrom", sendfrom, {"fromaccount","toaddress","amount","minconf","comment","comment_to"} }, | ||||
{ "wallet", "sendmany", sendmany, {"fromaccount","amounts","minconf","comment","subtractfeefrom"} }, | { "wallet", "sendmany", sendmany, {"fromaccount","amounts","minconf","comment","subtractfeefrom"} }, | ||||
{ "wallet", "sendtoaddress", sendtoaddress, {"address","amount","comment","comment_to","subtractfeefromamount"} }, | { "wallet", "sendtoaddress", sendtoaddress, {"address","amount","comment","comment_to","subtractfeefromamount"} }, | ||||
{ "wallet", "setlabel", setlabel, {"address","label"} }, | { "wallet", "setlabel", setlabel, {"address","label"} }, | ||||
{ "wallet", "setaccount", setlabel, {"address","account"} }, | { "wallet", "setaccount", setlabel, {"address","account"} }, | ||||
Show All 15 Lines |