@ -3114,6 +3114,52 @@ UniValue loadwallet(const JSONRPCRequest& request)
return obj ;
}
UniValue createwallet ( const JSONRPCRequest & request )
{
if ( request . fHelp | | request . params . size ( ) ! = 1 )
throw std : : runtime_error (
" createwallet \" wallet_name \" \n "
" \n Creates and loads a new wallet. \n "
" \n Arguments: \n "
" 1. \" wallet_name \" (string, required) The name for the new wallet. \n "
" \n Result: \n "
" { \n "
" \" name \" : <wallet_name>, (string) The wallet name if created successfully. \n "
" \" warning \" : <warning>, (string) Warning message if wallet was not loaded cleanly. \n "
" } \n "
" \n Examples: \n "
+ HelpExampleCli ( " createwallet " , " \" test.dat \" " )
+ HelpExampleRpc ( " createwallet " , " \" test.dat \" " )
) ;
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 duplication name.
if ( ! CWallet : : Verify ( wallet_name , false , error , warning ) ) {
throw JSONRPCError ( RPC_WALLET_ERROR , " Wallet file verification failed: " + error ) ;
}
std : : shared_ptr < CWallet > const wallet = CWallet : : CreateWalletFromFile ( 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 JSONRPCRequest & request )
{
std : : shared_ptr < CWallet > const wallet = GetWalletForJSONRPCRequest ( request ) ;
@ -4315,6 +4361,7 @@ static const CRPCCommand commands[] =
{ " hidden " , " addwitnessaddress " , & addwitnessaddress , { " address " , " p2sh " } } ,
{ " wallet " , " backupwallet " , & backupwallet , { " destination " } } ,
{ " wallet " , " bumpfee " , & bumpfee , { " txid " , " options " } } ,
{ " wallet " , " createwallet " , & createwallet , { " filename " } } ,
{ " wallet " , " dumpprivkey " , & dumpprivkey , { " address " } } ,
{ " wallet " , " dumpwallet " , & dumpwallet , { " filename " } } ,
{ " wallet " , " encryptwallet " , & encryptwallet , { " passphrase " } } ,