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