@ -161,7 +161,7 @@ void CWallet::DeriveNewChildKey(CKeyMetadata& metadata, CKey& secret, bool inter
secret = childKey . key ;
secret = childKey . key ;
metadata . hdMasterKeyID = hdChain . masterKeyID ;
metadata . hdMasterKeyID = hdChain . masterKeyID ;
// update the chain model in the database
// update the chain model in the database
if ( ! CWalletDB ( strWalletFile ) . WriteHDChain ( hdChain ) )
if ( ! CWalletDB ( * dbw ) . WriteHDChain ( hdChain ) )
throw std : : runtime_error ( std : : string ( __func__ ) + " : Writing HD chain model failed " ) ;
throw std : : runtime_error ( std : : string ( __func__ ) + " : Writing HD chain model failed " ) ;
}
}
@ -183,7 +183,7 @@ bool CWallet::AddKeyPubKey(const CKey& secret, const CPubKey &pubkey)
if ( ! fFileBacked )
if ( ! fFileBacked )
return true ;
return true ;
if ( ! IsCrypted ( ) ) {
if ( ! IsCrypted ( ) ) {
return CWalletDB ( strWalletFile ) . WriteKey ( pubkey ,
return CWalletDB ( * dbw ) . WriteKey ( pubkey ,
secret . GetPrivKey ( ) ,
secret . GetPrivKey ( ) ,
mapKeyMetadata [ pubkey . GetID ( ) ] ) ;
mapKeyMetadata [ pubkey . GetID ( ) ] ) ;
}
}
@ -204,7 +204,7 @@ bool CWallet::AddCryptedKey(const CPubKey &vchPubKey,
vchCryptedSecret ,
vchCryptedSecret ,
mapKeyMetadata [ vchPubKey . GetID ( ) ] ) ;
mapKeyMetadata [ vchPubKey . GetID ( ) ] ) ;
else
else
return CWalletDB ( strWalletFile ) . WriteCryptedKey ( vchPubKey ,
return CWalletDB ( * dbw ) . WriteCryptedKey ( vchPubKey ,
vchCryptedSecret ,
vchCryptedSecret ,
mapKeyMetadata [ vchPubKey . GetID ( ) ] ) ;
mapKeyMetadata [ vchPubKey . GetID ( ) ] ) ;
}
}
@ -242,7 +242,7 @@ bool CWallet::AddCScript(const CScript& redeemScript)
return false ;
return false ;
if ( ! fFileBacked )
if ( ! fFileBacked )
return true ;
return true ;
return CWalletDB ( strWalletFile ) . WriteCScript ( Hash160 ( redeemScript ) , redeemScript ) ;
return CWalletDB ( * dbw ) . WriteCScript ( Hash160 ( redeemScript ) , redeemScript ) ;
}
}
bool CWallet : : LoadCScript ( const CScript & redeemScript )
bool CWallet : : LoadCScript ( const CScript & redeemScript )
@ -270,7 +270,7 @@ bool CWallet::AddWatchOnly(const CScript& dest)
NotifyWatchonlyChanged ( true ) ;
NotifyWatchonlyChanged ( true ) ;
if ( ! fFileBacked )
if ( ! fFileBacked )
return true ;
return true ;
return CWalletDB ( strWalletFile ) . WriteWatchOnly ( dest , meta ) ;
return CWalletDB ( * dbw ) . WriteWatchOnly ( dest , meta ) ;
}
}
bool CWallet : : AddWatchOnly ( const CScript & dest , int64_t nCreateTime )
bool CWallet : : AddWatchOnly ( const CScript & dest , int64_t nCreateTime )
@ -287,7 +287,7 @@ bool CWallet::RemoveWatchOnly(const CScript &dest)
if ( ! HaveWatchOnly ( ) )
if ( ! HaveWatchOnly ( ) )
NotifyWatchonlyChanged ( false ) ;
NotifyWatchonlyChanged ( false ) ;
if ( fFileBacked )
if ( fFileBacked )
if ( ! CWalletDB ( strWalletFile ) . EraseWatchOnly ( dest ) )
if ( ! CWalletDB ( * dbw ) . EraseWatchOnly ( dest ) )
return false ;
return false ;
return true ;
return true ;
@ -353,7 +353,7 @@ bool CWallet::ChangeWalletPassphrase(const SecureString& strOldWalletPassphrase,
return false ;
return false ;
if ( ! crypter . Encrypt ( _vMasterKey , pMasterKey . second . vchCryptedKey ) )
if ( ! crypter . Encrypt ( _vMasterKey , pMasterKey . second . vchCryptedKey ) )
return false ;
return false ;
CWalletDB ( strWalletFile ) . WriteMasterKey ( pMasterKey . first , pMasterKey . second ) ;
CWalletDB ( * dbw ) . WriteMasterKey ( pMasterKey . first , pMasterKey . second ) ;
if ( fWasLocked )
if ( fWasLocked )
Lock ( ) ;
Lock ( ) ;
return true ;
return true ;
@ -366,7 +366,7 @@ bool CWallet::ChangeWalletPassphrase(const SecureString& strOldWalletPassphrase,
void CWallet : : SetBestChain ( const CBlockLocator & loc )
void CWallet : : SetBestChain ( const CBlockLocator & loc )
{
{
CWalletDB walletdb ( strWalletFile ) ;
CWalletDB walletdb ( * dbw ) ;
walletdb . WriteBestBlock ( loc ) ;
walletdb . WriteBestBlock ( loc ) ;
}
}
@ -387,7 +387,7 @@ bool CWallet::SetMinVersion(enum WalletFeature nVersion, CWalletDB* pwalletdbIn,
if ( fFileBacked )
if ( fFileBacked )
{
{
CWalletDB * pwalletdb = pwalletdbIn ? pwalletdbIn : new CWalletDB ( strWalletFile ) ;
CWalletDB * pwalletdb = pwalletdbIn ? pwalletdbIn : new CWalletDB ( * dbw ) ;
if ( nWalletVersion > 40000 )
if ( nWalletVersion > 40000 )
pwalletdb - > WriteMinVersion ( nWalletVersion ) ;
pwalletdb - > WriteMinVersion ( nWalletVersion ) ;
if ( ! pwalletdbIn )
if ( ! pwalletdbIn )
@ -597,7 +597,7 @@ bool CWallet::EncryptWallet(const SecureString& strWalletPassphrase)
if ( fFileBacked )
if ( fFileBacked )
{
{
assert ( ! pwalletdbEncryption ) ;
assert ( ! pwalletdbEncryption ) ;
pwalletdbEncryption = new CWalletDB ( strWalletFile ) ;
pwalletdbEncryption = new CWalletDB ( * dbw ) ;
if ( ! pwalletdbEncryption - > TxnBegin ( ) ) {
if ( ! pwalletdbEncryption - > TxnBegin ( ) ) {
delete pwalletdbEncryption ;
delete pwalletdbEncryption ;
pwalletdbEncryption = NULL ;
pwalletdbEncryption = NULL ;
@ -651,7 +651,7 @@ bool CWallet::EncryptWallet(const SecureString& strWalletPassphrase)
// Need to completely rewrite the wallet file; if we don't, bdb might keep
// Need to completely rewrite the wallet file; if we don't, bdb might keep
// bits of the unencrypted private key in slack space in the database file.
// bits of the unencrypted private key in slack space in the database file.
CDB : : Rewrite ( strWalletFile ) ;
dbw - > Rewrite ( ) ;
}
}
NotifyStatusChanged ( this ) ;
NotifyStatusChanged ( this ) ;
@ -662,7 +662,7 @@ bool CWallet::EncryptWallet(const SecureString& strWalletPassphrase)
DBErrors CWallet : : ReorderTransactions ( )
DBErrors CWallet : : ReorderTransactions ( )
{
{
LOCK ( cs_wallet ) ;
LOCK ( cs_wallet ) ;
CWalletDB walletdb ( strWalletFile ) ;
CWalletDB walletdb ( * dbw ) ;
// Old wallets didn't have any defined order for transactions
// Old wallets didn't have any defined order for transactions
// Probably a bad idea to change the output of this
// Probably a bad idea to change the output of this
@ -743,14 +743,14 @@ int64_t CWallet::IncOrderPosNext(CWalletDB *pwalletdb)
if ( pwalletdb ) {
if ( pwalletdb ) {
pwalletdb - > WriteOrderPosNext ( nOrderPosNext ) ;
pwalletdb - > WriteOrderPosNext ( nOrderPosNext ) ;
} else {
} else {
CWalletDB ( strWalletFile ) . WriteOrderPosNext ( nOrderPosNext ) ;
CWalletDB ( * dbw ) . WriteOrderPosNext ( nOrderPosNext ) ;
}
}
return nRet ;
return nRet ;
}
}
bool CWallet : : AccountMove ( std : : string strFrom , std : : string strTo , CAmount nAmount , std : : string strComment )
bool CWallet : : AccountMove ( std : : string strFrom , std : : string strTo , CAmount nAmount , std : : string strComment )
{
{
CWalletDB walletdb ( strWalletFile ) ;
CWalletDB walletdb ( * dbw ) ;
if ( ! walletdb . TxnBegin ( ) )
if ( ! walletdb . TxnBegin ( ) )
return false ;
return false ;
@ -784,7 +784,7 @@ bool CWallet::AccountMove(std::string strFrom, std::string strTo, CAmount nAmoun
bool CWallet : : GetAccountPubkey ( CPubKey & pubKey , std : : string strAccount , bool bForceNew )
bool CWallet : : GetAccountPubkey ( CPubKey & pubKey , std : : string strAccount , bool bForceNew )
{
{
CWalletDB walletdb ( strWalletFile ) ;
CWalletDB walletdb ( * dbw ) ;
CAccount account ;
CAccount account ;
walletdb . ReadAccount ( strAccount , account ) ;
walletdb . ReadAccount ( strAccount , account ) ;
@ -845,7 +845,7 @@ bool CWallet::MarkReplaced(const uint256& originalHash, const uint256& newHash)
wtx . mapValue [ " replaced_by_txid " ] = newHash . ToString ( ) ;
wtx . mapValue [ " replaced_by_txid " ] = newHash . ToString ( ) ;
CWalletDB walletdb ( strWalletFile , " r+ " ) ;
CWalletDB walletdb ( * dbw , " r+ " ) ;
bool success = true ;
bool success = true ;
if ( ! walletdb . WriteTx ( wtx ) ) {
if ( ! walletdb . WriteTx ( wtx ) ) {
@ -862,7 +862,7 @@ bool CWallet::AddToWallet(const CWalletTx& wtxIn, bool fFlushOnClose)
{
{
LOCK ( cs_wallet ) ;
LOCK ( cs_wallet ) ;
CWalletDB walletdb ( strWalletFile , " r+ " , fFlushOnClose ) ;
CWalletDB walletdb ( * dbw , " r+ " , fFlushOnClose ) ;
uint256 hash = wtxIn . GetHash ( ) ;
uint256 hash = wtxIn . GetHash ( ) ;
@ -1006,7 +1006,7 @@ bool CWallet::AbandonTransaction(const uint256& hashTx)
{
{
LOCK2 ( cs_main , cs_wallet ) ;
LOCK2 ( cs_main , cs_wallet ) ;
CWalletDB walletdb ( strWalletFile , " r+ " ) ;
CWalletDB walletdb ( * dbw , " r+ " ) ;
std : : set < uint256 > todo ;
std : : set < uint256 > todo ;
std : : set < uint256 > done ;
std : : set < uint256 > done ;
@ -1078,7 +1078,7 @@ void CWallet::MarkConflicted(const uint256& hashBlock, const uint256& hashTx)
return ;
return ;
// Do not flush the wallet here for performance reasons
// Do not flush the wallet here for performance reasons
CWalletDB walletdb ( strWalletFile , " r+ " , false ) ;
CWalletDB walletdb ( * dbw , " r+ " , false ) ;
std : : set < uint256 > todo ;
std : : set < uint256 > todo ;
std : : set < uint256 > done ;
std : : set < uint256 > done ;
@ -1361,7 +1361,7 @@ bool CWallet::SetHDMasterKey(const CPubKey& pubkey, CHDChain *possibleOldChain)
bool CWallet : : SetHDChain ( const CHDChain & chain , bool memonly )
bool CWallet : : SetHDChain ( const CHDChain & chain , bool memonly )
{
{
LOCK ( cs_wallet ) ;
LOCK ( cs_wallet ) ;
if ( ! memonly & & ! CWalletDB ( strWalletFile ) . WriteHDChain ( chain ) )
if ( ! memonly & & ! CWalletDB ( * dbw ) . WriteHDChain ( chain ) )
throw std : : runtime_error ( std : : string ( __func__ ) + " : writing chain failed " ) ;
throw std : : runtime_error ( std : : string ( __func__ ) + " : writing chain failed " ) ;
hdChain = chain ;
hdChain = chain ;
@ -2758,13 +2758,13 @@ bool CWallet::CommitTransaction(CWalletTx& wtxNew, CReserveKey& reservekey, CCon
}
}
void CWallet : : ListAccountCreditDebit ( const std : : string & strAccount , std : : list < CAccountingEntry > & entries ) {
void CWallet : : ListAccountCreditDebit ( const std : : string & strAccount , std : : list < CAccountingEntry > & entries ) {
CWalletDB walletdb ( strWalletFile ) ;
CWalletDB walletdb ( * dbw ) ;
return walletdb . ListAccountCreditDebit ( strAccount , entries ) ;
return walletdb . ListAccountCreditDebit ( strAccount , entries ) ;
}
}
bool CWallet : : AddAccountingEntry ( const CAccountingEntry & acentry )
bool CWallet : : AddAccountingEntry ( const CAccountingEntry & acentry )
{
{
CWalletDB walletdb ( strWalletFile ) ;
CWalletDB walletdb ( * dbw ) ;
return AddAccountingEntry ( acentry , & walletdb ) ;
return AddAccountingEntry ( acentry , & walletdb ) ;
}
}
@ -2819,10 +2819,10 @@ DBErrors CWallet::LoadWallet(bool& fFirstRunRet)
if ( ! fFileBacked )
if ( ! fFileBacked )
return DB_LOAD_OK ;
return DB_LOAD_OK ;
fFirstRunRet = false ;
fFirstRunRet = false ;
DBErrors nLoadWalletRet = CWalletDB ( strWalletFile , " cr+ " ) . LoadWallet ( this ) ;
DBErrors nLoadWalletRet = CWalletDB ( * dbw , " cr+ " ) . LoadWallet ( this ) ;
if ( nLoadWalletRet = = DB_NEED_REWRITE )
if ( nLoadWalletRet = = DB_NEED_REWRITE )
{
{
if ( CDB : : Rewrite ( strWalletFile , " \x04 pool " ) )
if ( dbw - > Rewrite ( " \x04 pool " ) )
{
{
LOCK ( cs_wallet ) ;
LOCK ( cs_wallet ) ;
setKeyPool . clear ( ) ;
setKeyPool . clear ( ) ;
@ -2847,13 +2847,13 @@ DBErrors CWallet::ZapSelectTx(std::vector<uint256>& vHashIn, std::vector<uint256
return DB_LOAD_OK ;
return DB_LOAD_OK ;
AssertLockHeld ( cs_wallet ) ; // mapWallet
AssertLockHeld ( cs_wallet ) ; // mapWallet
vchDefaultKey = CPubKey ( ) ;
vchDefaultKey = CPubKey ( ) ;
DBErrors nZapSelectTxRet = CWalletDB ( strWalletFile , " cr+ " ) . ZapSelectTx ( vHashIn , vHashOut ) ;
DBErrors nZapSelectTxRet = CWalletDB ( * dbw , " cr+ " ) . ZapSelectTx ( vHashIn , vHashOut ) ;
for ( uint256 hash : vHashOut )
for ( uint256 hash : vHashOut )
mapWallet . erase ( hash ) ;
mapWallet . erase ( hash ) ;
if ( nZapSelectTxRet = = DB_NEED_REWRITE )
if ( nZapSelectTxRet = = DB_NEED_REWRITE )
{
{
if ( CDB : : Rewrite ( strWalletFile , " \x04 pool " ) )
if ( dbw - > Rewrite ( " \x04 pool " ) )
{
{
setKeyPool . clear ( ) ;
setKeyPool . clear ( ) ;
// Note: can't top-up keypool here, because wallet is locked.
// Note: can't top-up keypool here, because wallet is locked.
@ -2876,10 +2876,10 @@ DBErrors CWallet::ZapWalletTx(std::vector<CWalletTx>& vWtx)
if ( ! fFileBacked )
if ( ! fFileBacked )
return DB_LOAD_OK ;
return DB_LOAD_OK ;
vchDefaultKey = CPubKey ( ) ;
vchDefaultKey = CPubKey ( ) ;
DBErrors nZapWalletTxRet = CWalletDB ( strWalletFile , " cr+ " ) . ZapWalletTx ( vWtx ) ;
DBErrors nZapWalletTxRet = CWalletDB ( * dbw , " cr+ " ) . ZapWalletTx ( vWtx ) ;
if ( nZapWalletTxRet = = DB_NEED_REWRITE )
if ( nZapWalletTxRet = = DB_NEED_REWRITE )
{
{
if ( CDB : : Rewrite ( strWalletFile , " \x04 pool " ) )
if ( dbw - > Rewrite ( " \x04 pool " ) )
{
{
LOCK ( cs_wallet ) ;
LOCK ( cs_wallet ) ;
setKeyPool . clear ( ) ;
setKeyPool . clear ( ) ;
@ -2911,9 +2911,9 @@ bool CWallet::SetAddressBook(const CTxDestination& address, const std::string& s
strPurpose , ( fUpdated ? CT_UPDATED : CT_NEW ) ) ;
strPurpose , ( fUpdated ? CT_UPDATED : CT_NEW ) ) ;
if ( ! fFileBacked )
if ( ! fFileBacked )
return false ;
return false ;
if ( ! strPurpose . empty ( ) & & ! CWalletDB ( strWalletFile ) . WritePurpose ( CBitcoinAddress ( address ) . ToString ( ) , strPurpose ) )
if ( ! strPurpose . empty ( ) & & ! CWalletDB ( * dbw ) . WritePurpose ( CBitcoinAddress ( address ) . ToString ( ) , strPurpose ) )
return false ;
return false ;
return CWalletDB ( strWalletFile ) . WriteName ( CBitcoinAddress ( address ) . ToString ( ) , strName ) ;
return CWalletDB ( * dbw ) . WriteName ( CBitcoinAddress ( address ) . ToString ( ) , strName ) ;
}
}
bool CWallet : : DelAddressBook ( const CTxDestination & address )
bool CWallet : : DelAddressBook ( const CTxDestination & address )
@ -2927,7 +2927,7 @@ bool CWallet::DelAddressBook(const CTxDestination& address)
std : : string strAddress = CBitcoinAddress ( address ) . ToString ( ) ;
std : : string strAddress = CBitcoinAddress ( address ) . ToString ( ) ;
BOOST_FOREACH ( const PAIRTYPE ( std : : string , std : : string ) & item , mapAddressBook [ address ] . destdata )
BOOST_FOREACH ( const PAIRTYPE ( std : : string , std : : string ) & item , mapAddressBook [ address ] . destdata )
{
{
CWalletDB ( strWalletFile ) . EraseDestData ( strAddress , item . first ) ;
CWalletDB ( * dbw ) . EraseDestData ( strAddress , item . first ) ;
}
}
}
}
mapAddressBook . erase ( address ) ;
mapAddressBook . erase ( address ) ;
@ -2937,15 +2937,15 @@ bool CWallet::DelAddressBook(const CTxDestination& address)
if ( ! fFileBacked )
if ( ! fFileBacked )
return false ;
return false ;
CWalletDB ( strWalletFile ) . ErasePurpose ( CBitcoinAddress ( address ) . ToString ( ) ) ;
CWalletDB ( * dbw ) . ErasePurpose ( CBitcoinAddress ( address ) . ToString ( ) ) ;
return CWalletDB ( strWalletFile ) . EraseName ( CBitcoinAddress ( address ) . ToString ( ) ) ;
return CWalletDB ( * dbw ) . EraseName ( CBitcoinAddress ( address ) . ToString ( ) ) ;
}
}
bool CWallet : : SetDefaultKey ( const CPubKey & vchPubKey )
bool CWallet : : SetDefaultKey ( const CPubKey & vchPubKey )
{
{
if ( fFileBacked )
if ( fFileBacked )
{
{
if ( ! CWalletDB ( strWalletFile ) . WriteDefaultKey ( vchPubKey ) )
if ( ! CWalletDB ( * dbw ) . WriteDefaultKey ( vchPubKey ) )
return false ;
return false ;
}
}
vchDefaultKey = vchPubKey ;
vchDefaultKey = vchPubKey ;
@ -2960,7 +2960,7 @@ bool CWallet::NewKeyPool()
{
{
{
{
LOCK ( cs_wallet ) ;
LOCK ( cs_wallet ) ;
CWalletDB walletdb ( strWalletFile ) ;
CWalletDB walletdb ( * dbw ) ;
BOOST_FOREACH ( int64_t nIndex , setKeyPool )
BOOST_FOREACH ( int64_t nIndex , setKeyPool )
walletdb . ErasePool ( nIndex ) ;
walletdb . ErasePool ( nIndex ) ;
setKeyPool . clear ( ) ;
setKeyPool . clear ( ) ;
@ -2981,7 +2981,7 @@ size_t CWallet::KeypoolCountExternalKeys()
if ( ! IsHDEnabled ( ) | | ! CanSupportFeature ( FEATURE_HD_SPLIT ) )
if ( ! IsHDEnabled ( ) | | ! CanSupportFeature ( FEATURE_HD_SPLIT ) )
return setKeyPool . size ( ) ;
return setKeyPool . size ( ) ;
CWalletDB walletdb ( strWalletFile ) ;
CWalletDB walletdb ( * dbw ) ;
// count amount of external keys
// count amount of external keys
size_t amountE = 0 ;
size_t amountE = 0 ;
@ -3024,7 +3024,7 @@ bool CWallet::TopUpKeyPool(unsigned int kpSize)
missingInternal = 0 ;
missingInternal = 0 ;
}
}
bool internal = false ;
bool internal = false ;
CWalletDB walletdb ( strWalletFile ) ;
CWalletDB walletdb ( * dbw ) ;
for ( int64_t i = missingInternal + missingExternal ; i - - ; )
for ( int64_t i = missingInternal + missingExternal ; i - - ; )
{
{
int64_t nEnd = 1 ;
int64_t nEnd = 1 ;
@ -3055,7 +3055,7 @@ void CWallet::ReserveKeyFromKeyPool(int64_t& nIndex, CKeyPool& keypool, bool int
if ( setKeyPool . empty ( ) )
if ( setKeyPool . empty ( ) )
return ;
return ;
CWalletDB walletdb ( strWalletFile ) ;
CWalletDB walletdb ( * dbw ) ;
// try to find a key that matches the internal/external filter
// try to find a key that matches the internal/external filter
for ( const int64_t & id : setKeyPool )
for ( const int64_t & id : setKeyPool )
@ -3083,7 +3083,7 @@ void CWallet::KeepKey(int64_t nIndex)
// Remove from key pool
// Remove from key pool
if ( fFileBacked )
if ( fFileBacked )
{
{
CWalletDB walletdb ( strWalletFile ) ;
CWalletDB walletdb ( * dbw ) ;
walletdb . ErasePool ( nIndex ) ;
walletdb . ErasePool ( nIndex ) ;
}
}
LogPrintf ( " keypool keep %d \n " , nIndex ) ;
LogPrintf ( " keypool keep %d \n " , nIndex ) ;
@ -3127,7 +3127,7 @@ int64_t CWallet::GetOldestKeyPoolTime()
return GetTime ( ) ;
return GetTime ( ) ;
CKeyPool keypool ;
CKeyPool keypool ;
CWalletDB walletdb ( strWalletFile ) ;
CWalletDB walletdb ( * dbw ) ;
if ( IsHDEnabled ( ) & & CanSupportFeature ( FEATURE_HD_SPLIT ) )
if ( IsHDEnabled ( ) & & CanSupportFeature ( FEATURE_HD_SPLIT ) )
{
{
@ -3295,7 +3295,7 @@ std::set< std::set<CTxDestination> > CWallet::GetAddressGroupings()
CAmount CWallet : : GetAccountBalance ( const std : : string & strAccount , int nMinDepth , const isminefilter & filter )
CAmount CWallet : : GetAccountBalance ( const std : : string & strAccount , int nMinDepth , const isminefilter & filter )
{
{
CWalletDB walletdb ( strWalletFile ) ;
CWalletDB walletdb ( * dbw ) ;
return GetAccountBalance ( walletdb , strAccount , nMinDepth , filter ) ;
return GetAccountBalance ( walletdb , strAccount , nMinDepth , filter ) ;
}
}
@ -3375,7 +3375,7 @@ void CWallet::GetAllReserveKeys(std::set<CKeyID>& setAddress) const
{
{
setAddress . clear ( ) ;
setAddress . clear ( ) ;
CWalletDB walletdb ( strWalletFile ) ;
CWalletDB walletdb ( * dbw ) ;
LOCK2 ( cs_main , cs_wallet ) ;
LOCK2 ( cs_main , cs_wallet ) ;
BOOST_FOREACH ( const int64_t & id , setKeyPool )
BOOST_FOREACH ( const int64_t & id , setKeyPool )
@ -3599,7 +3599,7 @@ bool CWallet::AddDestData(const CTxDestination &dest, const std::string &key, co
mapAddressBook [ dest ] . destdata . insert ( std : : make_pair ( key , value ) ) ;
mapAddressBook [ dest ] . destdata . insert ( std : : make_pair ( key , value ) ) ;
if ( ! fFileBacked )
if ( ! fFileBacked )
return true ;
return true ;
return CWalletDB ( strWalletFile ) . WriteDestData ( CBitcoinAddress ( dest ) . ToString ( ) , key , value ) ;
return CWalletDB ( * dbw ) . WriteDestData ( CBitcoinAddress ( dest ) . ToString ( ) , key , value ) ;
}
}
bool CWallet : : EraseDestData ( const CTxDestination & dest , const std : : string & key )
bool CWallet : : EraseDestData ( const CTxDestination & dest , const std : : string & key )
@ -3608,7 +3608,7 @@ bool CWallet::EraseDestData(const CTxDestination &dest, const std::string &key)
return false ;
return false ;
if ( ! fFileBacked )
if ( ! fFileBacked )
return true ;
return true ;
return CWalletDB ( strWalletFile ) . EraseDestData ( CBitcoinAddress ( dest ) . ToString ( ) , key ) ;
return CWalletDB ( * dbw ) . EraseDestData ( CBitcoinAddress ( dest ) . ToString ( ) , key ) ;
}
}
bool CWallet : : LoadDestData ( const CTxDestination & dest , const std : : string & key , const std : : string & value )
bool CWallet : : LoadDestData ( const CTxDestination & dest , const std : : string & key , const std : : string & value )
@ -3678,7 +3678,8 @@ CWallet* CWallet::CreateWalletFromFile(const std::string walletFile)
if ( GetBoolArg ( " -zapwallettxes " , false ) ) {
if ( GetBoolArg ( " -zapwallettxes " , false ) ) {
uiInterface . InitMessage ( _ ( " Zapping all transactions from wallet... " ) ) ;
uiInterface . InitMessage ( _ ( " Zapping all transactions from wallet... " ) ) ;
CWallet * tempWallet = new CWallet ( walletFile ) ;
std : : unique_ptr < CWalletDBWrapper > dbw ( new CWalletDBWrapper ( & bitdb , walletFile ) ) ;
CWallet * tempWallet = new CWallet ( std : : move ( dbw ) ) ;
DBErrors nZapWalletRet = tempWallet - > ZapWalletTx ( vWtx ) ;
DBErrors nZapWalletRet = tempWallet - > ZapWalletTx ( vWtx ) ;
if ( nZapWalletRet ! = DB_LOAD_OK ) {
if ( nZapWalletRet ! = DB_LOAD_OK ) {
InitError ( strprintf ( _ ( " Error loading %s: Wallet corrupted " ) , walletFile ) ) ;
InitError ( strprintf ( _ ( " Error loading %s: Wallet corrupted " ) , walletFile ) ) ;
@ -3693,7 +3694,8 @@ CWallet* CWallet::CreateWalletFromFile(const std::string walletFile)
int64_t nStart = GetTimeMillis ( ) ;
int64_t nStart = GetTimeMillis ( ) ;
bool fFirstRun = true ;
bool fFirstRun = true ;
CWallet * walletInstance = new CWallet ( walletFile ) ;
std : : unique_ptr < CWalletDBWrapper > dbw ( new CWalletDBWrapper ( & bitdb , walletFile ) ) ;
CWallet * walletInstance = new CWallet ( std : : move ( dbw ) ) ;
DBErrors nLoadWalletRet = walletInstance - > LoadWallet ( fFirstRun ) ;
DBErrors nLoadWalletRet = walletInstance - > LoadWallet ( fFirstRun ) ;
if ( nLoadWalletRet ! = DB_LOAD_OK )
if ( nLoadWalletRet ! = DB_LOAD_OK )
{
{
@ -3784,7 +3786,7 @@ CWallet* CWallet::CreateWalletFromFile(const std::string walletFile)
CBlockIndex * pindexRescan = chainActive . Genesis ( ) ;
CBlockIndex * pindexRescan = chainActive . Genesis ( ) ;
if ( ! GetBoolArg ( " -rescan " , false ) )
if ( ! GetBoolArg ( " -rescan " , false ) )
{
{
CWalletDB walletdb ( walletFile ) ;
CWalletDB walletdb ( * walletInstance - > dbw ) ;
CBlockLocator locator ;
CBlockLocator locator ;
if ( walletdb . ReadBestBlock ( locator ) )
if ( walletdb . ReadBestBlock ( locator ) )
pindexRescan = FindForkInGlobalIndex ( chainActive , locator ) ;
pindexRescan = FindForkInGlobalIndex ( chainActive , locator ) ;
@ -3817,7 +3819,7 @@ CWallet* CWallet::CreateWalletFromFile(const std::string walletFile)
// Restore wallet transaction metadata after -zapwallettxes=1
// Restore wallet transaction metadata after -zapwallettxes=1
if ( GetBoolArg ( " -zapwallettxes " , false ) & & GetArg ( " -zapwallettxes " , " 1 " ) ! = " 2 " )
if ( GetBoolArg ( " -zapwallettxes " , false ) & & GetArg ( " -zapwallettxes " , " 1 " ) ! = " 2 " )
{
{
CWalletDB walletdb ( walletFile ) ;
CWalletDB walletdb ( * walletInstance - > dbw ) ;
BOOST_FOREACH ( const CWalletTx & wtxOld , vWtx )
BOOST_FOREACH ( const CWalletTx & wtxOld , vWtx )
{
{
@ -3979,36 +3981,7 @@ bool CWallet::BackupWallet(const std::string& strDest)
{
{
if ( ! fFileBacked )
if ( ! fFileBacked )
return false ;
return false ;
while ( true )
return dbw - > Backup ( strDest ) ;
{
{
LOCK ( bitdb . cs_db ) ;
if ( ! bitdb . mapFileUseCount . count ( strWalletFile ) | | bitdb . mapFileUseCount [ strWalletFile ] = = 0 )
{
// Flush log data to the dat file
bitdb . CloseDb ( strWalletFile ) ;
bitdb . CheckpointLSN ( strWalletFile ) ;
bitdb . mapFileUseCount . erase ( strWalletFile ) ;
// Copy wallet file
fs : : path pathSrc = GetDataDir ( ) / strWalletFile ;
fs : : path pathDest ( strDest ) ;
if ( fs : : is_directory ( pathDest ) )
pathDest / = strWalletFile ;
try {
fs : : copy_file ( pathSrc , pathDest , fs : : copy_option : : overwrite_if_exists ) ;
LogPrintf ( " copied %s to %s \n " , strWalletFile , pathDest . string ( ) ) ;
return true ;
} catch ( const fs : : filesystem_error & e ) {
LogPrintf ( " error copying %s to %s - %s \n " , strWalletFile , pathDest . string ( ) , e . what ( ) ) ;
return false ;
}
}
}
MilliSleep ( 100 ) ;
}
return false ;
}
}
CKeyPool : : CKeyPool ( )
CKeyPool : : CKeyPool ( )