@ -362,12 +362,6 @@ void CWallet::LoadScriptMetadata(const CScriptID& script_id, const CKeyMetadata&
m_script_metadata [ script_id ] = meta ;
}
// Writes a keymetadata for a public key. overwrite specifies whether to overwrite an existing metadata for that key if there exists one.
bool CWallet : : WriteKeyMetadata ( const CKeyMetadata & meta , const CPubKey & pubkey , const bool overwrite )
{
return WalletBatch ( * database ) . WriteKeyMetadata ( meta , pubkey , overwrite ) ;
}
void CWallet : : UpgradeKeyMetadata ( )
{
AssertLockHeld ( cs_wallet ) ;
@ -432,10 +426,16 @@ void CWallet::UpdateTimeFirstKey(int64_t nCreateTime)
}
bool CWallet : : AddCScript ( const CScript & redeemScript )
{
WalletBatch batch ( * database ) ;
return AddCScriptWithDB ( batch , redeemScript ) ;
}
bool CWallet : : AddCScriptWithDB ( WalletBatch & batch , const CScript & redeemScript )
{
if ( ! CCryptoKeyStore : : AddCScript ( redeemScript ) )
return false ;
if ( WalletBatch ( * database ) . WriteCScript ( Hash160 ( redeemScript ) , redeemScript ) ) {
if ( batch . WriteCScript ( Hash160 ( redeemScript ) , redeemScript ) ) {
UnsetWalletFlag ( WALLET_FLAG_BLANK_WALLET ) ;
return true ;
}
@ -457,20 +457,32 @@ bool CWallet::LoadCScript(const CScript& redeemScript)
return CCryptoKeyStore : : AddCScript ( redeemScript ) ;
}
bool CWallet : : AddWatchOnly ( const CScript & dest )
bool CWallet : : AddWatchOnly WithDB ( WalletBatch & batch , const CScript & dest )
{
if ( ! CCryptoKeyStore : : AddWatchOnly ( dest ) )
return false ;
const CKeyMetadata & meta = m_script_metadata [ CScriptID ( dest ) ] ;
UpdateTimeFirstKey ( meta . nCreateTime ) ;
NotifyWatchonlyChanged ( true ) ;
if ( WalletBatch( * database ) . WriteWatchOnly ( dest , meta ) ) {
if ( batch . WriteWatchOnly ( dest , meta ) ) {
UnsetWalletFlag ( WALLET_FLAG_BLANK_WALLET ) ;
return true ;
}
return false ;
}
bool CWallet : : AddWatchOnlyWithDB ( WalletBatch & batch , const CScript & dest , int64_t create_time )
{
m_script_metadata [ CScriptID ( dest ) ] . nCreateTime = create_time ;
return AddWatchOnlyWithDB ( batch , dest ) ;
}
bool CWallet : : AddWatchOnly ( const CScript & dest )
{
WalletBatch batch ( * database ) ;
return AddWatchOnlyWithDB ( batch , dest ) ;
}
bool CWallet : : AddWatchOnly ( const CScript & dest , int64_t nCreateTime )
{
m_script_metadata [ CScriptID ( dest ) ] . nCreateTime = nCreateTime ;
@ -4469,12 +4481,12 @@ bool CWallet::GetKeyOrigin(const CKeyID& keyID, KeyOriginInfo& info) const
return true ;
}
bool CWallet : : AddKeyOrigin ( const CPubKey & pubkey , const KeyOriginInfo & info )
bool CWallet : : AddKeyOrigin WithDB ( WalletBatch & batch , const CPubKey & pubkey , const KeyOriginInfo & info )
{
LOCK ( cs_wallet ) ;
std : : copy ( info . fingerprint , info . fingerprint + 4 , mapKeyMetadata [ pubkey . GetID ( ) ] . key_origin . fingerprint ) ;
mapKeyMetadata [ pubkey . GetID ( ) ] . key_origin . path = info . path ;
mapKeyMetadata [ pubkey . GetID ( ) ] . has_key_origin = true ;
mapKeyMetadata [ pubkey . GetID ( ) ] . hdKeypath = WriteHDKeypath ( info . path ) ;
return WriteKeyMetadata( mapKeyMetadata [ pubkey . GetID ( ) ] , pubkey , true ) ;
return batch . WriteKeyMetadata( mapKeyMetadata [ pubkey . GetID ( ) ] , pubkey , true ) ;
}