@@ -2994,6 +2994,53 @@ static UniValue listwallets(const JSONRPCRequest& request)
2994
2994
return obj;
2995
2995
}
2996
2996
2997
+ UniValue loadwallet (const JSONRPCRequest& request)
2998
+ {
2999
+ if (request.fHelp || request.params .size () != 1 )
3000
+ throw std::runtime_error (
3001
+ " loadwallet \" filename\"\n "
3002
+ " \n Loads a wallet from a wallet file or directory."
3003
+ " \n Note that all wallet command-line options used when starting bitcoind will be"
3004
+ " \n applied to the new wallet (eg -zapwallettxes, upgradewallet, rescan, etc).\n "
3005
+ " \n Arguments:\n "
3006
+ " 1. \" filename\" (string, required) The wallet directory or .dat file.\n "
3007
+ " \n Result:\n "
3008
+ " {\n "
3009
+ " \" name\" : <wallet_name>, (string) The wallet name if loaded successfully.\n "
3010
+ " \" warning\" : <warning>, (string) Warning message if wallet was not loaded cleanly.\n "
3011
+ " }\n "
3012
+ " \n Examples:\n "
3013
+ + HelpExampleCli (" loadwallet" , " \" test.dat\" " )
3014
+ + HelpExampleRpc (" loadwallet" , " \" test.dat\" " )
3015
+ );
3016
+ std::string wallet_file = request.params [0 ].get_str ();
3017
+ std::string error;
3018
+
3019
+ fs::path wallet_path = fs::absolute (wallet_file, GetWalletDir ());
3020
+ if (fs::symlink_status (wallet_path).type () == fs::file_not_found) {
3021
+ throw JSONRPCError (RPC_WALLET_NOT_FOUND, " Wallet " + wallet_file + " not found." );
3022
+ }
3023
+
3024
+ std::string warning;
3025
+ if (!CWallet::Verify (wallet_file, false , error, warning)) {
3026
+ throw JSONRPCError (RPC_WALLET_ERROR, " Wallet file verification failed: " + error);
3027
+ }
3028
+
3029
+ CWallet * const wallet = CWallet::CreateWalletFromFile (wallet_file, fs::absolute (wallet_file, GetWalletDir ()));
3030
+ if (!wallet) {
3031
+ throw JSONRPCError (RPC_WALLET_ERROR, " Wallet loading failed." );
3032
+ }
3033
+ AddWallet (wallet);
3034
+
3035
+ wallet->postInitProcess ();
3036
+
3037
+ UniValue obj (UniValue::VOBJ);
3038
+ obj.pushKV (" name" , wallet->GetName ());
3039
+ obj.pushKV (" warning" , warning);
3040
+
3041
+ return obj;
3042
+ }
3043
+
2997
3044
static UniValue resendwallettransactions (const JSONRPCRequest& request)
2998
3045
{
2999
3046
CWallet * const pwallet = GetWalletForJSONRPCRequest (request);
@@ -4197,6 +4244,7 @@ static const CRPCCommand commands[] =
4197
4244
{ " wallet" , " listtransactions" , &listtransactions, {" account|dummy" ," count" ," skip" ," include_watchonly" } },
4198
4245
{ " wallet" , " listunspent" , &listunspent, {" minconf" ," maxconf" ," addresses" ," include_unsafe" ," query_options" } },
4199
4246
{ " wallet" , " listwallets" , &listwallets, {} },
4247
+ { " wallet" , " loadwallet" , &loadwallet, {" filename" } },
4200
4248
{ " wallet" , " lockunspent" , &lockunspent, {" unlock" ," transactions" } },
4201
4249
{ " wallet" , " sendfrom" , &sendfrom, {" fromaccount" ," toaddress" ," amount" ," minconf" ," comment" ," comment_to" } },
4202
4250
{ " wallet" , " sendmany" , &sendmany, {" fromaccount|dummy" ," amounts" ," minconf" ," comment" ," subtractfeefrom" ," replaceable" ," conf_target" ," estimate_mode" } },
0 commit comments