diff --git a/init.cpp b/init.cpp index 9c84dca..7da5131 100644 --- a/init.cpp +++ b/init.cpp @@ -418,7 +418,8 @@ bool AppInit2(int argc, char* argv[]) if (mapArgs.count("-paytxfee")) { - if (!ParseMoney(mapArgs["-paytxfee"], nTransactionFee)) + if (!ParseMoney(mapArgs["-paytxfee"], nTransactionFee) || + !ValidFee(nTransactionFee)) { wxMessageBox(_("Invalid amount for -paytxfee="), "Bitcoin"); return false; diff --git a/main.cpp b/main.cpp index a47f3a9..2f91a8a 100644 --- a/main.cpp +++ b/main.cpp @@ -3840,6 +3840,18 @@ bool SelectCoins(int64 nTargetValue, set& setCoinsRet) +bool ValidFee(int64 nAmount, bool fAllowZero) +{ + if (nAmount == 0 && fAllowZero) + return true; + if (nAmount < CENT) + return false; + if (nAmount > (5 * COIN)) + return false; + + return true; +} + bool CreateTransaction(CScript scriptPubKey, int64 nValue, CWalletTx& wtxNew, CReserveKey& reservekey, int64& nFeeRet) { diff --git a/main.h b/main.h index a7ef336..f249a08 100644 --- a/main.h +++ b/main.h @@ -92,7 +92,7 @@ void BitcoinMiner(); bool CheckProofOfWork(uint256 hash, unsigned int nBits); bool IsInitialBlockDownload(); string GetWarnings(string strFor); - +bool ValidFee(int64 nAmount, bool fAllowZero = true); diff --git a/rpc.cpp b/rpc.cpp index 1c6f228..c47108a 100644 --- a/rpc.cpp +++ b/rpc.cpp @@ -450,6 +450,28 @@ Value getaddressesbyaccount(const Array& params, bool fHelp) return ret; } +Value settxfee(const Array& params, bool fHelp) +{ + if (fHelp || params.size() < 1 || params.size() > 1) + throw runtime_error( + "settxfee \n" + " is a real and is rounded to the nearest 0.01"); + + // Amount + int64 nAmount = AmountFromValue(params[0]); + + // safety range + if (!ValidFee(nAmount)) + return false; + + static CCriticalSection cs; + CRITICAL_BLOCK(cs) + { + nTransactionFee = nAmount; // note, we still race with readers + } + return true; +} + Value sendtoaddress(const Array& params, bool fHelp) { if (fHelp || params.size() < 2 || params.size() > 4) @@ -1342,6 +1364,7 @@ pair pCallTable[] = make_pair("listtransactions", &listtransactions), make_pair("getwork", &getwork), make_pair("listaccounts", &listaccounts), + make_pair("settxfee", &settxfee), }; map mapCallTable(pCallTable, pCallTable + sizeof(pCallTable)/sizeof(pCallTable[0])); @@ -1970,6 +1993,7 @@ int CommandLineRPC(int argc, char *argv[]) if (strMethod == "setgenerate" && n > 0) ConvertTo(params[0]); if (strMethod == "setgenerate" && n > 1) ConvertTo(params[1]); if (strMethod == "sendtoaddress" && n > 1) ConvertTo(params[1]); + if (strMethod == "settxfee" && n > 0) ConvertTo(params[0]); if (strMethod == "getamountreceived" && n > 1) ConvertTo(params[1]); // deprecated if (strMethod == "getreceivedbyaddress" && n > 1) ConvertTo(params[1]); if (strMethod == "getreceivedbyaccount" && n > 1) ConvertTo(params[1]);