@@ -362,12 +362,6 @@ void CWallet::LoadScriptMetadata(const CScriptID& script_id, const CKeyMetadata&
362362 m_script_metadata[script_id] = meta;
363363}
364364
365- // Writes a keymetadata for a public key. overwrite specifies whether to overwrite an existing metadata for that key if there exists one.
366- bool CWallet::WriteKeyMetadata (const CKeyMetadata& meta, const CPubKey& pubkey, const bool overwrite)
367- {
368- return WalletBatch (*database).WriteKeyMetadata (meta, pubkey, overwrite);
369- }
370-
371365void CWallet::UpgradeKeyMetadata ()
372366{
373367 AssertLockHeld (cs_wallet);
@@ -432,10 +426,16 @@ void CWallet::UpdateTimeFirstKey(int64_t nCreateTime)
432426}
433427
434428bool CWallet::AddCScript (const CScript& redeemScript)
429+ {
430+ WalletBatch batch (*database);
431+ return AddCScriptWithDB (batch, redeemScript);
432+ }
433+
434+ bool CWallet::AddCScriptWithDB (WalletBatch& batch, const CScript& redeemScript)
435435{
436436 if (!CCryptoKeyStore::AddCScript (redeemScript))
437437 return false ;
438- if (WalletBatch (*database) .WriteCScript (Hash160 (redeemScript), redeemScript)) {
438+ if (batch .WriteCScript (Hash160 (redeemScript), redeemScript)) {
439439 UnsetWalletFlag (WALLET_FLAG_BLANK_WALLET);
440440 return true ;
441441 }
@@ -457,20 +457,32 @@ bool CWallet::LoadCScript(const CScript& redeemScript)
457457 return CCryptoKeyStore::AddCScript (redeemScript);
458458}
459459
460- bool CWallet::AddWatchOnly ( const CScript& dest)
460+ bool CWallet::AddWatchOnlyWithDB (WalletBatch &batch, const CScript& dest)
461461{
462462 if (!CCryptoKeyStore::AddWatchOnly (dest))
463463 return false ;
464464 const CKeyMetadata& meta = m_script_metadata[CScriptID (dest)];
465465 UpdateTimeFirstKey (meta.nCreateTime );
466466 NotifyWatchonlyChanged (true );
467- if (WalletBatch (*database) .WriteWatchOnly (dest, meta)) {
467+ if (batch .WriteWatchOnly (dest, meta)) {
468468 UnsetWalletFlag (WALLET_FLAG_BLANK_WALLET);
469469 return true ;
470470 }
471471 return false ;
472472}
473473
474+ bool CWallet::AddWatchOnlyWithDB (WalletBatch &batch, const CScript& dest, int64_t create_time)
475+ {
476+ m_script_metadata[CScriptID (dest)].nCreateTime = create_time;
477+ return AddWatchOnlyWithDB (batch, dest);
478+ }
479+
480+ bool CWallet::AddWatchOnly (const CScript& dest)
481+ {
482+ WalletBatch batch (*database);
483+ return AddWatchOnlyWithDB (batch, dest);
484+ }
485+
474486bool CWallet::AddWatchOnly (const CScript& dest, int64_t nCreateTime)
475487{
476488 m_script_metadata[CScriptID (dest)].nCreateTime = nCreateTime;
@@ -4469,12 +4481,12 @@ bool CWallet::GetKeyOrigin(const CKeyID& keyID, KeyOriginInfo& info) const
44694481 return true ;
44704482}
44714483
4472- bool CWallet::AddKeyOrigin ( const CPubKey& pubkey, const KeyOriginInfo& info)
4484+ bool CWallet::AddKeyOriginWithDB (WalletBatch& batch, const CPubKey& pubkey, const KeyOriginInfo& info)
44734485{
44744486 LOCK (cs_wallet);
44754487 std::copy (info.fingerprint , info.fingerprint + 4 , mapKeyMetadata[pubkey.GetID ()].key_origin .fingerprint );
44764488 mapKeyMetadata[pubkey.GetID ()].key_origin .path = info.path ;
44774489 mapKeyMetadata[pubkey.GetID ()].has_key_origin = true ;
44784490 mapKeyMetadata[pubkey.GetID ()].hdKeypath = WriteHDKeypath (info.path );
4479- return WriteKeyMetadata (mapKeyMetadata[pubkey.GetID ()], pubkey, true );
4491+ return batch. WriteKeyMetadata (mapKeyMetadata[pubkey.GetID ()], pubkey, true );
44804492}
0 commit comments