@@ -2677,17 +2677,12 @@ static UniValue createwallet(const JSONRPCRequest& request)
2677
2677
},
2678
2678
}.Check (request);
2679
2679
2680
- std::string error;
2681
- std::string warning;
2682
-
2683
2680
uint64_t flags = 0 ;
2684
2681
if (!request.params [1 ].isNull () && request.params [1 ].get_bool ()) {
2685
2682
flags |= WALLET_FLAG_DISABLE_PRIVATE_KEYS;
2686
2683
}
2687
2684
2688
- bool create_blank = false ; // Indicate that the wallet is actually supposed to be blank and not just blank to make it encrypted
2689
2685
if (!request.params [2 ].isNull () && request.params [2 ].get_bool ()) {
2690
- create_blank = true ;
2691
2686
flags |= WALLET_FLAG_BLANK_WALLET;
2692
2687
}
2693
2688
SecureString passphrase;
@@ -2698,55 +2693,24 @@ static UniValue createwallet(const JSONRPCRequest& request)
2698
2693
// Empty string is invalid
2699
2694
throw JSONRPCError (RPC_WALLET_ENCRYPTION_FAILED, " Cannot encrypt a wallet with a blank password" );
2700
2695
}
2701
- // Born encrypted wallets need to be blank first so that wallet creation doesn't make any unencrypted keys
2702
- flags |= WALLET_FLAG_BLANK_WALLET;
2703
2696
}
2704
2697
2705
2698
if (!request.params [4 ].isNull () && request.params [4 ].get_bool ()) {
2706
2699
flags |= WALLET_FLAG_AVOID_REUSE;
2707
2700
}
2708
2701
2709
- WalletLocation location (request.params [0 ].get_str ());
2710
- if (location.Exists ()) {
2711
- throw JSONRPCError (RPC_WALLET_ERROR, " Wallet " + location.GetName () + " already exists." );
2712
- }
2713
-
2714
- // Wallet::Verify will check if we're trying to create a wallet with a duplication name.
2715
- if (!CWallet::Verify (*g_rpc_interfaces->chain , location, false , error, warning)) {
2716
- throw JSONRPCError (RPC_WALLET_ERROR, " Wallet file verification failed: " + error);
2717
- }
2718
-
2719
- std::shared_ptr<CWallet> const wallet = CWallet::CreateWalletFromFile (*g_rpc_interfaces->chain , location, flags);
2720
- if (!wallet) {
2721
- throw JSONRPCError (RPC_WALLET_ERROR, " Wallet creation failed." );
2722
- }
2723
-
2724
- // Encrypt the wallet if there's a passphrase
2725
- if (!passphrase.empty () && !(flags & WALLET_FLAG_DISABLE_PRIVATE_KEYS)) {
2726
- if (!wallet->EncryptWallet (passphrase)) {
2727
- throw JSONRPCError (RPC_WALLET_ENCRYPTION_FAILED, " Error: Wallet created but failed to encrypt." );
2728
- }
2729
-
2730
- if (!create_blank) {
2731
- // Unlock the wallet
2732
- if (!wallet->Unlock (passphrase)) {
2733
- throw JSONRPCError (RPC_WALLET_ENCRYPTION_FAILED, " Error: Wallet was encrypted but could not be unlocked" );
2734
- }
2735
-
2736
- // Set a seed for the wallet
2737
- CPubKey master_pub_key = wallet->GenerateNewSeed ();
2738
- wallet->SetHDSeed (master_pub_key);
2739
- wallet->NewKeyPool ();
2740
-
2741
- // Relock the wallet
2742
- wallet->Lock ();
2743
- }
2702
+ std::string error;
2703
+ std::string warning;
2704
+ WalletCreationStatus status;
2705
+ std::shared_ptr<CWallet> wallet = CreateWallet (*g_rpc_interfaces->chain , request.params [0 ].get_str (), error, warning, status, passphrase, flags);
2706
+ if (status == WalletCreationStatus::CREATION_FAILED) {
2707
+ throw JSONRPCError (RPC_WALLET_ERROR, error);
2708
+ } else if (status == WalletCreationStatus::ENCRYPTION_FAILED) {
2709
+ throw JSONRPCError (RPC_WALLET_ENCRYPTION_FAILED, error);
2710
+ } else if (status != WalletCreationStatus::SUCCESS) {
2711
+ throw JSONRPCError (RPC_WALLET_ERROR, " Wallet creation failed" );
2744
2712
}
2745
2713
2746
- AddWallet (wallet);
2747
-
2748
- wallet->postInitProcess ();
2749
-
2750
2714
UniValue obj (UniValue::VOBJ);
2751
2715
obj.pushKV (" name" , wallet->GetName ());
2752
2716
obj.pushKV (" warning" , warning);
0 commit comments