@@ -3114,6 +3114,52 @@ UniValue loadwallet(const JSONRPCRequest& request)
3114
3114
return obj;
3115
3115
}
3116
3116
3117
+ UniValue createwallet (const JSONRPCRequest& request)
3118
+ {
3119
+ if (request.fHelp || request.params .size () != 1 )
3120
+ throw std::runtime_error (
3121
+ " createwallet \" wallet_name\"\n "
3122
+ " \n Creates and loads a new wallet.\n "
3123
+ " \n Arguments:\n "
3124
+ " 1. \" wallet_name\" (string, required) The name for the new wallet.\n "
3125
+ " \n Result:\n "
3126
+ " {\n "
3127
+ " \" name\" : <wallet_name>, (string) The wallet name if created successfully.\n "
3128
+ " \" warning\" : <warning>, (string) Warning message if wallet was not loaded cleanly.\n "
3129
+ " }\n "
3130
+ " \n Examples:\n "
3131
+ + HelpExampleCli (" createwallet" , " \" test.dat\" " )
3132
+ + HelpExampleRpc (" createwallet" , " \" test.dat\" " )
3133
+ );
3134
+ std::string wallet_name = request.params [0 ].get_str ();
3135
+ std::string error;
3136
+ std::string warning;
3137
+
3138
+ fs::path wallet_path = fs::absolute (wallet_name, GetWalletDir ());
3139
+ if (fs::symlink_status (wallet_path).type () != fs::file_not_found) {
3140
+ throw JSONRPCError (RPC_WALLET_ERROR, " Wallet " + wallet_name + " already exists." );
3141
+ }
3142
+
3143
+ // Wallet::Verify will check if we're trying to create a wallet with a duplication name.
3144
+ if (!CWallet::Verify (wallet_name, false , error, warning)) {
3145
+ throw JSONRPCError (RPC_WALLET_ERROR, " Wallet file verification failed: " + error);
3146
+ }
3147
+
3148
+ std::shared_ptr<CWallet> const wallet = CWallet::CreateWalletFromFile (wallet_name, fs::absolute (wallet_name, GetWalletDir ()));
3149
+ if (!wallet) {
3150
+ throw JSONRPCError (RPC_WALLET_ERROR, " Wallet creation failed." );
3151
+ }
3152
+ AddWallet (wallet);
3153
+
3154
+ wallet->postInitProcess ();
3155
+
3156
+ UniValue obj (UniValue::VOBJ);
3157
+ obj.pushKV (" name" , wallet->GetName ());
3158
+ obj.pushKV (" warning" , warning);
3159
+
3160
+ return obj;
3161
+ }
3162
+
3117
3163
static UniValue resendwallettransactions (const JSONRPCRequest& request)
3118
3164
{
3119
3165
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest (request);
@@ -4315,6 +4361,7 @@ static const CRPCCommand commands[] =
4315
4361
{ " hidden" , " addwitnessaddress" , &addwitnessaddress, {" address" ," p2sh" } },
4316
4362
{ " wallet" , " backupwallet" , &backupwallet, {" destination" } },
4317
4363
{ " wallet" , " bumpfee" , &bumpfee, {" txid" , " options" } },
4364
+ { " wallet" , " createwallet" , &createwallet, {" filename" } },
4318
4365
{ " wallet" , " dumpprivkey" , &dumpprivkey, {" address" } },
4319
4366
{ " wallet" , " dumpwallet" , &dumpwallet, {" filename" } },
4320
4367
{ " wallet" , " encryptwallet" , &encryptwallet, {" passphrase" } },
0 commit comments