@ -23,6 +23,7 @@
# include "timedata.h"
# include "timedata.h"
# include "txmempool.h"
# include "txmempool.h"
# include "util.h"
# include "util.h"
# include "ui_interface.h"
# include "utilmoneystr.h"
# include "utilmoneystr.h"
# include <assert.h>
# include <assert.h>
@ -365,22 +366,6 @@ void CWallet::Flush(bool shutdown)
bitdb . Flush ( shutdown ) ;
bitdb . Flush ( shutdown ) ;
}
}
bool static UIError ( const std : : string & str )
{
uiInterface . ThreadSafeMessageBox ( str , " " , CClientUIInterface : : MSG_ERROR ) ;
return false ;
}
void static UIWarning ( const std : : string & str )
{
uiInterface . ThreadSafeMessageBox ( str , " " , CClientUIInterface : : MSG_WARNING ) ;
}
static std : : string AmountErrMsg ( const char * const optname , const std : : string & strValue )
{
return strprintf ( _ ( " Invalid amount for -%s=<amount>: '%s' " ) , optname , strValue ) ;
}
bool CWallet : : Verify ( )
bool CWallet : : Verify ( )
{
{
std : : string walletFile = GetArg ( " -wallet " , DEFAULT_WALLET_DAT ) ;
std : : string walletFile = GetArg ( " -wallet " , DEFAULT_WALLET_DAT ) ;
@ -390,7 +375,7 @@ bool CWallet::Verify()
// Wallet file must be a plain filename without a directory
// Wallet file must be a plain filename without a directory
if ( walletFile ! = boost : : filesystem : : basename ( walletFile ) + boost : : filesystem : : extension ( walletFile ) )
if ( walletFile ! = boost : : filesystem : : basename ( walletFile ) + boost : : filesystem : : extension ( walletFile ) )
return U IError( strprintf ( _ ( " Wallet %s resides outside data directory %s " ) , walletFile , GetDataDir ( ) . string ( ) ) ) ;
return Init Error ( strprintf ( _ ( " Wallet %s resides outside data directory %s " ) , walletFile , GetDataDir ( ) . string ( ) ) ) ;
if ( ! bitdb . Open ( GetDataDir ( ) ) )
if ( ! bitdb . Open ( GetDataDir ( ) ) )
{
{
@ -407,7 +392,7 @@ bool CWallet::Verify()
// try again
// try again
if ( ! bitdb . Open ( GetDataDir ( ) ) ) {
if ( ! bitdb . Open ( GetDataDir ( ) ) ) {
// if it still fails, it probably means we can't even create the database env
// if it still fails, it probably means we can't even create the database env
return U IError( strprintf ( _ ( " Error initializing wallet database environment %s! " ) , GetDataDir ( ) ) ) ;
return Init Error ( strprintf ( _ ( " Error initializing wallet database environment %s! " ) , GetDataDir ( ) ) ) ;
}
}
}
}
@ -423,14 +408,14 @@ bool CWallet::Verify()
CDBEnv : : VerifyResult r = bitdb . Verify ( walletFile , CWalletDB : : Recover ) ;
CDBEnv : : VerifyResult r = bitdb . Verify ( walletFile , CWalletDB : : Recover ) ;
if ( r = = CDBEnv : : RECOVER_OK )
if ( r = = CDBEnv : : RECOVER_OK )
{
{
U IWarning( strprintf ( _ ( " Warning: Wallet file corrupt, data salvaged! "
Init Warning ( strprintf ( _ ( " Warning: Wallet file corrupt, data salvaged! "
" Original %s saved as %s in %s; if "
" Original %s saved as %s in %s; if "
" your balance or transactions are incorrect you should "
" your balance or transactions are incorrect you should "
" restore from a backup. " ) ,
" restore from a backup. " ) ,
walletFile , " wallet.{timestamp}.bak " , GetDataDir ( ) ) ) ;
walletFile , " wallet.{timestamp}.bak " , GetDataDir ( ) ) ) ;
}
}
if ( r = = CDBEnv : : RECOVER_FAIL )
if ( r = = CDBEnv : : RECOVER_FAIL )
return U IError( strprintf ( _ ( " %s corrupt, salvage failed " ) , walletFile ) ) ;
return Init Error ( strprintf ( _ ( " %s corrupt, salvage failed " ) , walletFile ) ) ;
}
}
return true ;
return true ;
@ -3055,7 +3040,7 @@ bool CWallet::InitLoadWallet()
CWallet * tempWallet = new CWallet ( walletFile ) ;
CWallet * tempWallet = new CWallet ( walletFile ) ;
DBErrors nZapWalletRet = tempWallet - > ZapWalletTx ( vWtx ) ;
DBErrors nZapWalletRet = tempWallet - > ZapWalletTx ( vWtx ) ;
if ( nZapWalletRet ! = DB_LOAD_OK ) {
if ( nZapWalletRet ! = DB_LOAD_OK ) {
return U IError( strprintf ( _ ( " Error loading %s: Wallet corrupted " ) , walletFile ) ) ;
return Init Error ( strprintf ( _ ( " Error loading %s: Wallet corrupted " ) , walletFile ) ) ;
}
}
delete tempWallet ;
delete tempWallet ;
@ -3071,22 +3056,22 @@ bool CWallet::InitLoadWallet()
if ( nLoadWalletRet ! = DB_LOAD_OK )
if ( nLoadWalletRet ! = DB_LOAD_OK )
{
{
if ( nLoadWalletRet = = DB_CORRUPT )
if ( nLoadWalletRet = = DB_CORRUPT )
return U IError( strprintf ( _ ( " Error loading %s: Wallet corrupted " ) , walletFile ) ) ;
return Init Error ( strprintf ( _ ( " Error loading %s: Wallet corrupted " ) , walletFile ) ) ;
else if ( nLoadWalletRet = = DB_NONCRITICAL_ERROR )
else if ( nLoadWalletRet = = DB_NONCRITICAL_ERROR )
{
{
U IWarning( strprintf ( _ ( " Error reading %s! All keys read correctly, but transaction data "
Init Warning ( strprintf ( _ ( " Error reading %s! All keys read correctly, but transaction data "
" or address book entries might be missing or incorrect. " ) ,
" or address book entries might be missing or incorrect. " ) ,
walletFile ) ) ;
walletFile ) ) ;
}
}
else if ( nLoadWalletRet = = DB_TOO_NEW )
else if ( nLoadWalletRet = = DB_TOO_NEW )
return U IError( strprintf ( _ ( " Error loading %s: Wallet requires newer version of %s " ) ,
return Init Error ( strprintf ( _ ( " Error loading %s: Wallet requires newer version of %s " ) ,
walletFile , _ ( PACKAGE_NAME ) ) ) ;
walletFile , _ ( PACKAGE_NAME ) ) ) ;
else if ( nLoadWalletRet = = DB_NEED_REWRITE )
else if ( nLoadWalletRet = = DB_NEED_REWRITE )
{
{
return U IError( strprintf ( _ ( " Wallet needed to be rewritten: restart %s to complete " ) , _ ( PACKAGE_NAME ) ) ) ;
return Init Error ( strprintf ( _ ( " Wallet needed to be rewritten: restart %s to complete " ) , _ ( PACKAGE_NAME ) ) ) ;
}
}
else
else
return U IError( strprintf ( _ ( " Error loading %s " ) , walletFile ) ) ;
return Init Error ( strprintf ( _ ( " Error loading %s " ) , walletFile ) ) ;
}
}
if ( GetBoolArg ( " -upgradewallet " , fFirstRun ) )
if ( GetBoolArg ( " -upgradewallet " , fFirstRun ) )
@ -3102,7 +3087,7 @@ bool CWallet::InitLoadWallet()
LogPrintf ( " Allowing wallet upgrade up to %i \n " , nMaxVersion ) ;
LogPrintf ( " Allowing wallet upgrade up to %i \n " , nMaxVersion ) ;
if ( nMaxVersion < walletInstance - > GetVersion ( ) )
if ( nMaxVersion < walletInstance - > GetVersion ( ) )
{
{
return U IError( _ ( " Cannot downgrade wallet " ) ) ;
return Init Error ( _ ( " Cannot downgrade wallet " ) ) ;
}
}
walletInstance - > SetMaxVersion ( nMaxVersion ) ;
walletInstance - > SetMaxVersion ( nMaxVersion ) ;
}
}
@ -3116,7 +3101,7 @@ bool CWallet::InitLoadWallet()
if ( walletInstance - > GetKeyFromPool ( newDefaultKey ) ) {
if ( walletInstance - > GetKeyFromPool ( newDefaultKey ) ) {
walletInstance - > SetDefaultKey ( newDefaultKey ) ;
walletInstance - > SetDefaultKey ( newDefaultKey ) ;
if ( ! walletInstance - > SetAddressBook ( walletInstance - > vchDefaultKey . GetID ( ) , " " , " receive " ) )
if ( ! walletInstance - > SetAddressBook ( walletInstance - > vchDefaultKey . GetID ( ) , " " , " receive " ) )
return U IError( _ ( " Cannot write default address " ) + = " \n " ) ;
return Init Error ( _ ( " Cannot write default address " ) + = " \n " ) ;
}
}
walletInstance - > SetBestChain ( chainActive . GetLocator ( ) ) ;
walletInstance - > SetBestChain ( chainActive . GetLocator ( ) ) ;
@ -3150,7 +3135,7 @@ bool CWallet::InitLoadWallet()
block = block - > pprev ;
block = block - > pprev ;
if ( pindexRescan ! = block )
if ( pindexRescan ! = block )
return U IError( _ ( " Prune: last wallet synchronisation goes beyond pruned data. You need to -reindex (download the whole blockchain again in case of pruned node) " )) ;
return Init Error ( _ ( " Prune: last wallet synchronisation goes beyond pruned data. You need to -reindex (download the whole blockchain again in case of pruned node) " )) ;
}
}
uiInterface . InitMessage ( _ ( " Rescanning... " ) ) ;
uiInterface . InitMessage ( _ ( " Rescanning... " ) ) ;
@ -3200,28 +3185,28 @@ bool CWallet::ParameterInteraction()
if ( ParseMoney ( mapArgs [ " -mintxfee " ] , n ) & & n > 0 )
if ( ParseMoney ( mapArgs [ " -mintxfee " ] , n ) & & n > 0 )
CWallet : : minTxFee = CFeeRate ( n ) ;
CWallet : : minTxFee = CFeeRate ( n ) ;
else
else
return U IError( AmountErrMsg ( " mintxfee " , mapArgs [ " -mintxfee " ] ) ) ;
return Init Error ( AmountErrMsg ( " mintxfee " , mapArgs [ " -mintxfee " ] ) ) ;
}
}
if ( mapArgs . count ( " -fallbackfee " ) )
if ( mapArgs . count ( " -fallbackfee " ) )
{
{
CAmount nFeePerK = 0 ;
CAmount nFeePerK = 0 ;
if ( ! ParseMoney ( mapArgs [ " -fallbackfee " ] , nFeePerK ) )
if ( ! ParseMoney ( mapArgs [ " -fallbackfee " ] , nFeePerK ) )
return U IError( strprintf ( _ ( " Invalid amount for -fallbackfee=<amount>: '%s' " ) , mapArgs [ " -fallbackfee " ] ) ) ;
return Init Error ( strprintf ( _ ( " Invalid amount for -fallbackfee=<amount>: '%s' " ) , mapArgs [ " -fallbackfee " ] ) ) ;
if ( nFeePerK > HIGH_TX_FEE_PER_KB )
if ( nFeePerK > HIGH_TX_FEE_PER_KB )
U IWarning( _ ( " -fallbackfee is set very high! This is the transaction fee you may pay when fee estimates are not available. " ) ) ;
Init Warning ( _ ( " -fallbackfee is set very high! This is the transaction fee you may pay when fee estimates are not available. " ) ) ;
CWallet : : fallbackFee = CFeeRate ( nFeePerK ) ;
CWallet : : fallbackFee = CFeeRate ( nFeePerK ) ;
}
}
if ( mapArgs . count ( " -paytxfee " ) )
if ( mapArgs . count ( " -paytxfee " ) )
{
{
CAmount nFeePerK = 0 ;
CAmount nFeePerK = 0 ;
if ( ! ParseMoney ( mapArgs [ " -paytxfee " ] , nFeePerK ) )
if ( ! ParseMoney ( mapArgs [ " -paytxfee " ] , nFeePerK ) )
return U IError( AmountErrMsg ( " paytxfee " , mapArgs [ " -paytxfee " ] ) ) ;
return Init Error ( AmountErrMsg ( " paytxfee " , mapArgs [ " -paytxfee " ] ) ) ;
if ( nFeePerK > HIGH_TX_FEE_PER_KB )
if ( nFeePerK > HIGH_TX_FEE_PER_KB )
U IWarning( _ ( " -paytxfee is set very high! This is the transaction fee you will pay if you send a transaction. " ) ) ;
Init Warning ( _ ( " -paytxfee is set very high! This is the transaction fee you will pay if you send a transaction. " ) ) ;
payTxFee = CFeeRate ( nFeePerK , 1000 ) ;
payTxFee = CFeeRate ( nFeePerK , 1000 ) ;
if ( payTxFee < : : minRelayTxFee )
if ( payTxFee < : : minRelayTxFee )
{
{
return U IError( strprintf ( _ ( " Invalid amount for -paytxfee=<amount>: '%s' (must be at least %s) " ) ,
return Init Error ( strprintf ( _ ( " Invalid amount for -paytxfee=<amount>: '%s' (must be at least %s) " ) ,
mapArgs [ " -paytxfee " ] , : : minRelayTxFee . ToString ( ) ) ) ;
mapArgs [ " -paytxfee " ] , : : minRelayTxFee . ToString ( ) ) ) ;
}
}
}
}
@ -3229,13 +3214,13 @@ bool CWallet::ParameterInteraction()
{
{
CAmount nMaxFee = 0 ;
CAmount nMaxFee = 0 ;
if ( ! ParseMoney ( mapArgs [ " -maxtxfee " ] , nMaxFee ) )
if ( ! ParseMoney ( mapArgs [ " -maxtxfee " ] , nMaxFee ) )
return U IError( AmountErrMsg ( " maxtxfee " , mapArgs [ " -maxtxfee " ] ) ) ;
return Init Error ( AmountErrMsg ( " maxtxfee " , mapArgs [ " -maxtxfee " ] ) ) ;
if ( nMaxFee > HIGH_MAX_TX_FEE )
if ( nMaxFee > HIGH_MAX_TX_FEE )
U IWarning( _ ( " -maxtxfee is set very high! Fees this large could be paid on a single transaction. " ) ) ;
Init Warning ( _ ( " -maxtxfee is set very high! Fees this large could be paid on a single transaction. " ) ) ;
maxTxFee = nMaxFee ;
maxTxFee = nMaxFee ;
if ( CFeeRate ( maxTxFee , 1000 ) < : : minRelayTxFee )
if ( CFeeRate ( maxTxFee , 1000 ) < : : minRelayTxFee )
{
{
return U IError( strprintf ( _ ( " Invalid amount for -maxtxfee=<amount>: '%s' (must be at least the minrelay fee of %s to prevent stuck transactions) " ) ,
return Init Error ( strprintf ( _ ( " Invalid amount for -maxtxfee=<amount>: '%s' (must be at least the minrelay fee of %s to prevent stuck transactions) " ) ,
mapArgs [ " -maxtxfee " ] , : : minRelayTxFee . ToString ( ) ) ) ;
mapArgs [ " -maxtxfee " ] , : : minRelayTxFee . ToString ( ) ) ) ;
}
}
}
}