@ -3114,9 +3114,11 @@ DBErrors CWallet::LoadWallet(bool& fFirstRunRet)
}
}
}
}
// This wallet is in its first run if all of these are empty
fFirstRunRet = mapKeys . empty ( ) & & mapCryptedKeys . empty ( ) & & mapWatchKeys . empty ( ) & & setWatchOnly . empty ( ) & & mapScripts . empty ( ) ;
if ( nLoadWalletRet ! = DB_LOAD_OK )
if ( nLoadWalletRet ! = DB_LOAD_OK )
return nLoadWalletRet ;
return nLoadWalletRet ;
fFirstRunRet = ! vchDefaultKey . IsValid ( ) ;
uiInterface . LoadWallet ( this ) ;
uiInterface . LoadWallet ( this ) ;
@ -3126,7 +3128,6 @@ DBErrors CWallet::LoadWallet(bool& fFirstRunRet)
DBErrors CWallet : : ZapSelectTx ( std : : vector < uint256 > & vHashIn , std : : vector < uint256 > & vHashOut )
DBErrors CWallet : : ZapSelectTx ( std : : vector < uint256 > & vHashIn , std : : vector < uint256 > & vHashOut )
{
{
AssertLockHeld ( cs_wallet ) ; // mapWallet
AssertLockHeld ( cs_wallet ) ; // mapWallet
vchDefaultKey = CPubKey ( ) ;
DBErrors nZapSelectTxRet = CWalletDB ( * dbw , " 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 ) ;
@ -3155,7 +3156,6 @@ DBErrors CWallet::ZapSelectTx(std::vector<uint256>& vHashIn, std::vector<uint256
DBErrors CWallet : : ZapWalletTx ( std : : vector < CWalletTx > & vWtx )
DBErrors CWallet : : ZapWalletTx ( std : : vector < CWalletTx > & vWtx )
{
{
vchDefaultKey = CPubKey ( ) ;
DBErrors nZapWalletTxRet = CWalletDB ( * dbw , " cr+ " ) . ZapWalletTx ( vWtx ) ;
DBErrors nZapWalletTxRet = CWalletDB ( * dbw , " cr+ " ) . ZapWalletTx ( vWtx ) ;
if ( nZapWalletTxRet = = DB_NEED_REWRITE )
if ( nZapWalletTxRet = = DB_NEED_REWRITE )
{
{
@ -3231,14 +3231,6 @@ const std::string& CWallet::GetAccountName(const CScript& scriptPubKey) const
return DEFAULT_ACCOUNT_NAME ;
return DEFAULT_ACCOUNT_NAME ;
}
}
bool CWallet : : SetDefaultKey ( const CPubKey & vchPubKey )
{
if ( ! CWalletDB ( * dbw ) . WriteDefaultKey ( vchPubKey ) )
return false ;
vchDefaultKey = vchPubKey ;
return true ;
}
/**
/**
* Mark old keypool keys as used ,
* Mark old keypool keys as used ,
* and generate all new keys
* and generate all new keys
@ -4014,13 +4006,11 @@ CWallet* CWallet::CreateWalletFromFile(const std::string walletFile)
if ( ! walletInstance - > SetHDMasterKey ( masterPubKey ) )
if ( ! walletInstance - > SetHDMasterKey ( masterPubKey ) )
throw std : : runtime_error ( std : : string ( __func__ ) + " : Storing master key failed " ) ;
throw std : : runtime_error ( std : : string ( __func__ ) + " : Storing master key failed " ) ;
}
}
CPubKey newDefaultKey ;
if ( walletInstance - > GetKeyFromPool ( newDefaultKey , false ) ) {
// Top up the keypool
walletInstance - > SetDefaultKey ( newDefaultKey ) ;
if ( ! walletInstance - > TopUpKeyPool ( ) ) {
if ( ! walletInstance - > SetAddressBook ( walletInstance - > vchDefaultKey . GetID ( ) , " " , " receive " ) ) {
InitError ( _ ( " Unable to generate initial keys " ) + = " \n " ) ;
InitError ( _ ( " Cannot write default address " ) + = " \n " ) ;
return NULL ;
return nullptr ;
}
}
}
walletInstance - > SetBestChain ( chainActive . GetLocator ( ) ) ;
walletInstance - > SetBestChain ( chainActive . GetLocator ( ) ) ;