3333
3434using namespace std ;
3535
36+ CWallet* pwalletMain = NULL ;
3637/* * Transaction fee set by the user */
3738CFeeRate payTxFee (DEFAULT_TRANSACTION_FEE);
3839unsigned int nTxConfirmTarget = DEFAULT_TX_CONFIRM_TARGET;
@@ -364,8 +365,33 @@ void CWallet::Flush(bool shutdown)
364365 bitdb.Flush (shutdown);
365366}
366367
367- bool CWallet::Verify (const string& walletFile, string& warningString, string& errorString )
368+ bool static UIError (const std:: string &str )
368369{
370+ uiInterface.ThreadSafeMessageBox (str, " " , CClientUIInterface::MSG_ERROR);
371+ return false ;
372+ }
373+
374+ void static UIWarning (const std::string &str)
375+ {
376+ uiInterface.ThreadSafeMessageBox (str, " " , CClientUIInterface::MSG_WARNING);
377+ }
378+
379+ static std::string AmountErrMsg (const char * const optname, const std::string& strValue)
380+ {
381+ return strprintf (_ (" Invalid amount for -%s=<amount>: '%s'" ), optname, strValue);
382+ }
383+
384+ bool CWallet::Verify ()
385+ {
386+ std::string walletFile = GetArg (" -wallet" , DEFAULT_WALLET_DAT);
387+
388+ LogPrintf (" Using wallet %s\n " , walletFile);
389+ uiInterface.InitMessage (_ (" Verifying wallet..." ));
390+
391+ // Wallet file must be a plain filename without a directory
392+ if (walletFile != boost::filesystem::basename (walletFile) + boost::filesystem::extension (walletFile))
393+ return UIError (strprintf (_ (" Wallet %s resides outside data directory %s" ), walletFile, GetDataDir ().string ()));
394+
369395 if (!bitdb.Open (GetDataDir ()))
370396 {
371397 // try moving the database env out of the way
@@ -381,9 +407,7 @@ bool CWallet::Verify(const string& walletFile, string& warningString, string& er
381407 // try again
382408 if (!bitdb.Open (GetDataDir ())) {
383409 // if it still fails, it probably means we can't even create the database env
384- string msg = strprintf (_ (" Error initializing wallet database environment %s!" ), GetDataDir ());
385- errorString += msg;
386- return true ;
410+ return UIError (strprintf (_ (" Error initializing wallet database environment %s!" ), GetDataDir ()));
387411 }
388412 }
389413
@@ -399,14 +423,14 @@ bool CWallet::Verify(const string& walletFile, string& warningString, string& er
399423 CDBEnv::VerifyResult r = bitdb.Verify (walletFile, CWalletDB::Recover);
400424 if (r == CDBEnv::RECOVER_OK)
401425 {
402- warningString += strprintf (_ (" Warning: Wallet file corrupt, data salvaged!"
426+ UIWarning ( strprintf (_ (" Warning: Wallet file corrupt, data salvaged!"
403427 " Original %s saved as %s in %s; if"
404428 " your balance or transactions are incorrect you should"
405429 " restore from a backup." ),
406- walletFile, " wallet.{timestamp}.bak" , GetDataDir ());
430+ walletFile, " wallet.{timestamp}.bak" , GetDataDir ())) ;
407431 }
408432 if (r == CDBEnv::RECOVER_FAIL)
409- errorString += strprintf (_ (" %s corrupt, salvage failed" ), walletFile);
433+ return UIError ( strprintf (_ (" %s corrupt, salvage failed" ), walletFile) );
410434 }
411435
412436 return true ;
@@ -2992,20 +3016,20 @@ std::string CWallet::GetWalletHelpString(bool showDebug)
29923016 return strUsage;
29933017}
29943018
2995- CWallet* CWallet::InitLoadWallet (bool fDisableWallet , const std::string& strWalletFile, std::string& warningString, std::string& errorString )
3019+ bool CWallet::InitLoadWallet ()
29963020{
3021+ std::string walletFile = GetArg (" -wallet" , DEFAULT_WALLET_DAT);
3022+
29973023 // needed to restore wallet transaction meta data after -zapwallettxes
29983024 std::vector<CWalletTx> vWtx;
29993025
30003026 if (GetBoolArg (" -zapwallettxes" , false )) {
30013027 uiInterface.InitMessage (_ (" Zapping all transactions from wallet..." ));
30023028
3003- CWallet *tempWallet = new CWallet (strWalletFile );
3029+ CWallet *tempWallet = new CWallet (walletFile );
30043030 DBErrors nZapWalletRet = tempWallet->ZapWalletTx (vWtx);
30053031 if (nZapWalletRet != DB_LOAD_OK) {
3006- errorString = strprintf (_ (" Error loading %s: Wallet corrupted" ), strWalletFile);
3007- uiInterface.InitMessage (strprintf (_ (" Error loading %s: Wallet corrupted" ), strWalletFile));
3008- return NULL ;
3032+ return UIError (strprintf (_ (" Error loading %s: Wallet corrupted" ), walletFile));
30093033 }
30103034
30113035 delete tempWallet;
@@ -3016,32 +3040,27 @@ CWallet* CWallet::InitLoadWallet(bool fDisableWallet, const std::string& strWall
30163040
30173041 int64_t nStart = GetTimeMillis ();
30183042 bool fFirstRun = true ;
3019- CWallet *walletInstance = new CWallet (strWalletFile );
3043+ CWallet *walletInstance = new CWallet (walletFile );
30203044 DBErrors nLoadWalletRet = walletInstance->LoadWallet (fFirstRun );
30213045 if (nLoadWalletRet != DB_LOAD_OK)
30223046 {
30233047 if (nLoadWalletRet == DB_CORRUPT)
3024- errorString += strprintf (_ (" Error loading %s: Wallet corrupted" ), strWalletFile) + " \n " ;
3048+ return UIError ( strprintf (_ (" Error loading %s: Wallet corrupted" ), walletFile)) ;
30253049 else if (nLoadWalletRet == DB_NONCRITICAL_ERROR)
30263050 {
3027- warningString += strprintf (_ (" Error reading %s! All keys read correctly, but transaction data"
3051+ UIWarning ( strprintf (_ (" Error reading %s! All keys read correctly, but transaction data"
30283052 " or address book entries might be missing or incorrect." ),
3029- strWalletFile );
3053+ walletFile) );
30303054 }
30313055 else if (nLoadWalletRet == DB_TOO_NEW)
3032- errorString += strprintf (_ (" Error loading %s: Wallet requires newer version of %s" ),
3033- strWalletFile, _ (PACKAGE_NAME)) +
3034- " \n " ;
3056+ return UIError (strprintf (_ (" Error loading %s: Wallet requires newer version of %s" ),
3057+ walletFile, _ (PACKAGE_NAME)));
30353058 else if (nLoadWalletRet == DB_NEED_REWRITE)
30363059 {
3037- errorString += strprintf (_ (" Wallet needed to be rewritten: restart %s to complete" ), _ (PACKAGE_NAME)) + " \n " ;
3038- LogPrintf (" %s" , errorString);
3060+ return UIError (strprintf (_ (" Wallet needed to be rewritten: restart %s to complete" ), _ (PACKAGE_NAME)));
30393061 }
30403062 else
3041- errorString += strprintf (_ (" Error loading %s" ), strWalletFile) + " \n " ;
3042-
3043- if (!errorString.empty ())
3044- return NULL ;
3063+ return UIError (strprintf (_ (" Error loading %s" ), walletFile));
30453064 }
30463065
30473066 if (GetBoolArg (" -upgradewallet" , fFirstRun ))
@@ -3057,8 +3076,7 @@ CWallet* CWallet::InitLoadWallet(bool fDisableWallet, const std::string& strWall
30573076 LogPrintf (" Allowing wallet upgrade up to %i\n " , nMaxVersion);
30583077 if (nMaxVersion < walletInstance->GetVersion ())
30593078 {
3060- errorString += _ (" Cannot downgrade wallet" ) + " \n " ;
3061- return NULL ;
3079+ return UIError (_ (" Cannot downgrade wallet" ));
30623080 }
30633081 walletInstance->SetMaxVersion (nMaxVersion);
30643082 }
@@ -3072,10 +3090,7 @@ CWallet* CWallet::InitLoadWallet(bool fDisableWallet, const std::string& strWall
30723090 if (walletInstance->GetKeyFromPool (newDefaultKey)) {
30733091 walletInstance->SetDefaultKey (newDefaultKey);
30743092 if (!walletInstance->SetAddressBook (walletInstance->vchDefaultKey .GetID (), " " , " receive" ))
3075- {
3076- errorString += _ (" Cannot write default address" ) += " \n " ;
3077- return NULL ;
3078- }
3093+ return UIError (_ (" Cannot write default address" ) += " \n " );
30793094 }
30803095
30813096 walletInstance->SetBestChain (chainActive.GetLocator ());
@@ -3090,7 +3105,7 @@ CWallet* CWallet::InitLoadWallet(bool fDisableWallet, const std::string& strWall
30903105 pindexRescan = chainActive.Genesis ();
30913106 else
30923107 {
3093- CWalletDB walletdb (strWalletFile );
3108+ CWalletDB walletdb (walletFile );
30943109 CBlockLocator locator;
30953110 if (walletdb.ReadBestBlock (locator))
30963111 pindexRescan = FindForkInGlobalIndex (chainActive, locator);
@@ -3109,10 +3124,7 @@ CWallet* CWallet::InitLoadWallet(bool fDisableWallet, const std::string& strWall
31093124 block = block->pprev ;
31103125
31113126 if (pindexRescan != block)
3112- {
3113- errorString = _ (" Prune: last wallet synchronisation goes beyond pruned data. You need to -reindex (download the whole blockchain again in case of pruned node)" );
3114- return NULL ;
3115- }
3127+ return UIError (_ (" Prune: last wallet synchronisation goes beyond pruned data. You need to -reindex (download the whole blockchain again in case of pruned node)" ));
31163128 }
31173129
31183130 uiInterface.InitMessage (_ (" Rescanning..." ));
@@ -3126,7 +3138,7 @@ CWallet* CWallet::InitLoadWallet(bool fDisableWallet, const std::string& strWall
31263138 // Restore wallet transaction metadata after -zapwallettxes=1
31273139 if (GetBoolArg (" -zapwallettxes" , false ) && GetArg (" -zapwallettxes" , " 1" ) != " 2" )
31283140 {
3129- CWalletDB walletdb (strWalletFile );
3141+ CWalletDB walletdb (walletFile );
31303142
31313143 BOOST_FOREACH (const CWalletTx& wtxOld, vWtx)
31323144 {
@@ -3150,7 +3162,62 @@ CWallet* CWallet::InitLoadWallet(bool fDisableWallet, const std::string& strWall
31503162 }
31513163 walletInstance->SetBroadcastTransactions (GetBoolArg (" -walletbroadcast" , DEFAULT_WALLETBROADCAST));
31523164
3153- return walletInstance;
3165+ pwalletMain = walletInstance;
3166+ return true ;
3167+ }
3168+
3169+ bool CWallet::ParameterInteraction ()
3170+ {
3171+ if (mapArgs.count (" -mintxfee" ))
3172+ {
3173+ CAmount n = 0 ;
3174+ if (ParseMoney (mapArgs[" -mintxfee" ], n) && n > 0 )
3175+ CWallet::minTxFee = CFeeRate (n);
3176+ else
3177+ return UIError (AmountErrMsg (" mintxfee" , mapArgs[" -mintxfee" ]));
3178+ }
3179+ if (mapArgs.count (" -fallbackfee" ))
3180+ {
3181+ CAmount nFeePerK = 0 ;
3182+ if (!ParseMoney (mapArgs[" -fallbackfee" ], nFeePerK))
3183+ return UIError (strprintf (_ (" Invalid amount for -fallbackfee=<amount>: '%s'" ), mapArgs[" -fallbackfee" ]));
3184+ if (nFeePerK > HIGH_TX_FEE_PER_KB)
3185+ UIWarning (_ (" -fallbackfee is set very high! This is the transaction fee you may pay when fee estimates are not available." ));
3186+ CWallet::fallbackFee = CFeeRate (nFeePerK);
3187+ }
3188+ if (mapArgs.count (" -paytxfee" ))
3189+ {
3190+ CAmount nFeePerK = 0 ;
3191+ if (!ParseMoney (mapArgs[" -paytxfee" ], nFeePerK))
3192+ return UIError (AmountErrMsg (" paytxfee" , mapArgs[" -paytxfee" ]));
3193+ if (nFeePerK > HIGH_TX_FEE_PER_KB)
3194+ UIWarning (_ (" -paytxfee is set very high! This is the transaction fee you will pay if you send a transaction." ));
3195+ payTxFee = CFeeRate (nFeePerK, 1000 );
3196+ if (payTxFee < ::minRelayTxFee)
3197+ {
3198+ return UIError (strprintf (_ (" Invalid amount for -paytxfee=<amount>: '%s' (must be at least %s)" ),
3199+ mapArgs[" -paytxfee" ], ::minRelayTxFee.ToString ()));
3200+ }
3201+ }
3202+ if (mapArgs.count (" -maxtxfee" ))
3203+ {
3204+ CAmount nMaxFee = 0 ;
3205+ if (!ParseMoney (mapArgs[" -maxtxfee" ], nMaxFee))
3206+ return UIError (AmountErrMsg (" maxtxfee" , mapArgs[" -maxtxfee" ]));
3207+ if (nMaxFee > HIGH_MAX_TX_FEE)
3208+ UIWarning (_ (" -maxtxfee is set very high! Fees this large could be paid on a single transaction." ));
3209+ maxTxFee = nMaxFee;
3210+ if (CFeeRate (maxTxFee, 1000 ) < ::minRelayTxFee)
3211+ {
3212+ return UIError (strprintf (_ (" Invalid amount for -maxtxfee=<amount>: '%s' (must be at least the minrelay fee of %s to prevent stuck transactions)" ),
3213+ mapArgs[" -maxtxfee" ], ::minRelayTxFee.ToString ()));
3214+ }
3215+ }
3216+ nTxConfirmTarget = GetArg (" -txconfirmtarget" , DEFAULT_TX_CONFIRM_TARGET);
3217+ bSpendZeroConfChange = GetBoolArg (" -spendzeroconfchange" , DEFAULT_SPEND_ZEROCONF_CHANGE);
3218+ fSendFreeTransactions = GetBoolArg (" -sendfreetransactions" , DEFAULT_SEND_FREE_TRANSACTIONS);
3219+
3220+ return true ;
31543221}
31553222
31563223CKeyPool::CKeyPool ()
0 commit comments