@@ -1261,8 +1261,9 @@ static UniValue ProcessImport(CWallet * const pwallet, const UniValue& data, con
12611261
12621262 // All good, time to import
12631263 pwallet->MarkDirty ();
1264+ WalletBatch batch (pwallet->GetDBHandle ());
12641265 for (const auto & entry : import_data.import_scripts ) {
1265- if (!pwallet->HaveCScript (CScriptID (entry)) && !pwallet->AddCScript ( entry)) {
1266+ if (!pwallet->HaveCScript (CScriptID (entry)) && !pwallet->AddCScriptWithDB (batch, entry)) {
12661267 throw JSONRPCError (RPC_WALLET_ERROR, " Error adding script to wallet" );
12671268 }
12681269 }
@@ -1273,13 +1274,13 @@ static UniValue ProcessImport(CWallet * const pwallet, const UniValue& data, con
12731274 assert (key.VerifyPubKey (pubkey));
12741275 pwallet->mapKeyMetadata [id].nCreateTime = timestamp;
12751276 // If the private key is not present in the wallet, insert it.
1276- if (!pwallet->HaveKey (id) && !pwallet->AddKeyPubKey ( key, pubkey)) {
1277+ if (!pwallet->HaveKey (id) && !pwallet->AddKeyPubKeyWithDB (batch, key, pubkey)) {
12771278 throw JSONRPCError (RPC_WALLET_ERROR, " Error adding key to wallet" );
12781279 }
12791280 pwallet->UpdateTimeFirstKey (timestamp);
12801281 }
12811282 for (const auto & entry : import_data.key_origins ) {
1282- pwallet->AddKeyOrigin ( entry.second .first , entry.second .second );
1283+ pwallet->AddKeyOriginWithDB (batch, entry.second .first , entry.second .second );
12831284 }
12841285 for (const CKeyID& id : ordered_pubkeys) {
12851286 auto entry = pubkey_map.find (id);
@@ -1288,20 +1289,20 @@ static UniValue ProcessImport(CWallet * const pwallet, const UniValue& data, con
12881289 }
12891290 const CPubKey& pubkey = entry->second ;
12901291 CPubKey temp;
1291- if (!pwallet->GetPubKey (id, temp) && !pwallet->AddWatchOnly ( GetScriptForRawPubKey (pubkey), timestamp)) {
1292+ if (!pwallet->GetPubKey (id, temp) && !pwallet->AddWatchOnlyWithDB (batch, GetScriptForRawPubKey (pubkey), timestamp)) {
12921293 throw JSONRPCError (RPC_WALLET_ERROR, " Error adding address to wallet" );
12931294 }
12941295 pwallet->mapKeyMetadata [id].nCreateTime = timestamp;
12951296
12961297 // Add to keypool only works with pubkeys
12971298 if (add_keypool) {
1298- pwallet->AddKeypoolPubkey (pubkey, internal);
1299+ pwallet->AddKeypoolPubkeyWithDB (pubkey, internal, batch );
12991300 }
13001301 }
13011302
13021303 for (const CScript& script : script_pub_keys) {
13031304 if (!have_solving_data || !::IsMine (*pwallet, script)) { // Always call AddWatchOnly for non-solvable watch-only, so that watch timestamp gets updated
1304- if (!pwallet->AddWatchOnly ( script, timestamp)) {
1305+ if (!pwallet->AddWatchOnlyWithDB (batch, script, timestamp)) {
13051306 throw JSONRPCError (RPC_WALLET_ERROR, " Error adding address to wallet" );
13061307 }
13071308 }
0 commit comments