Add RPC call reservebalance

This commit is contained in:
lateminer
2018-10-12 21:02:30 +03:00
parent e9886e3f1b
commit da2c4ec6c9
4 changed files with 59 additions and 15 deletions

View File

@@ -465,6 +465,12 @@ std::string HelpMessage(HelpMessageMode mode)
strUsage += HelpMessageOpt("-rpcservertimeout=<n>", strprintf("Timeout during HTTP requests (default: %d)", DEFAULT_HTTP_SERVER_TIMEOUT));
}
#ifdef ENABLE_WALLET
strUsage += HelpMessageGroup(_("Staking options:"));
strUsage += HelpMessageOpt("-staking=<n>", strprintf(_("Enable staking functionality (0-1, default: %u)"), 1));
strUsage += HelpMessageOpt("-reservebalance=<amount>", _("Keep the specified amount of coins available for spending at all times (default: 0)"));
#endif
return strUsage;
}
@@ -710,19 +716,6 @@ void InitParameterInteraction()
LogPrintf("%s: parameter interaction: -externalip set -> setting -discover=0\n", __func__);
}
#ifdef ENABLE_WALLET
if (mapArgs.count("-reservebalance")) // ppcoin: reserve balance amount
{
if (SoftSetBoolArg("-reservebalance", false))
{
LogPrintf("Invalid amount for -reservebalance=<amount>");
}
ParseMoney(mapArgs["-reservebalance"], nReserveBalance);
}
#endif
if (GetBoolArg("-salvagewallet", false)) {
// Rewrite just private keys: rescan to find transactions
if (SoftSetBoolArg("-rescan", true))
@@ -1171,6 +1164,15 @@ bool AppInit2(Config& config, boost::thread_group& threadGroup, CScheduler& sche
}
}
#ifdef ENABLE_WALLET
if (mapArgs.count("-reservebalance")) {
if (!ParseMoney(GetArg("-reservebalance", ""), nReserveBalance)) {
InitError(_("Invalid amount for -reservebalance=<amount>"));
return false;
}
}
#endif
BOOST_FOREACH(const std::string& strDest, mapMultiArgs["-seednode"])
AddOneShot(strDest);

View File

@@ -56,7 +56,7 @@ static const CRPCConvertParam vRPCConvertParams[] =
{ "listaccounts", 0 },
{ "listaccounts", 1 },
{ "walletpassphrase", 1 },
{ "walletpassphrase", 2 },
{ "walletpassphrase", 2 },
{ "getblocktemplate", 0 },
{ "listsinceblock", 1 },
{ "listsinceblock", 2 },
@@ -102,6 +102,8 @@ static const CRPCConvertParam vRPCConvertParams[] =
{ "prioritisetransaction", 2 },
{ "setban", 2 },
{ "setban", 3 },
{ "reservebalance", 0},
{ "reservebalance", 1},
};
class CRPCConvertTable

View File

@@ -2095,6 +2095,43 @@ UniValue encryptwallet(const UniValue& params, bool fHelp)
return "wallet encrypted; Blackcoin server stopping, restart to run with encrypted wallet. The keypool has been flushed and a new HD seed was generated (if you are using HD). You need to make a new backup.";
}
UniValue reservebalance(const UniValue& params, bool fHelp)
{
if (fHelp || params.size() > 2)
throw runtime_error(
"reservebalance [<reserve> [amount]]\n"
"<reserve> is true or false to turn balance reserve on or off.\n"
"<amount> is a real and rounded to cent.\n"
"Set reserve amount not participating in network protection.\n"
"If no parameters provided current setting is printed.\n");
if (params.size() > 0)
{
bool fReserve = params[0].get_bool();
if (fReserve)
{
if (params.size() == 1)
throw runtime_error("must provide amount to reserve balance.\n");
int64_t nAmount = AmountFromValue(params[1]);
nAmount = (nAmount / CENT) * CENT; // round to cent
if (nAmount < 0)
throw runtime_error("amount cannot be negative.\n");
nReserveBalance = nAmount;
}
else
{
if (params.size() > 1)
throw runtime_error("cannot specify amount to turn off reserve.\n");
nReserveBalance = 0;
}
}
UniValue result(UniValue::VOBJ);
result.push_back(Pair("reserve", (nReserveBalance > 0)));
result.push_back(Pair("amount", ValueFromAmount(nReserveBalance)));
return result;
}
UniValue lockunspent(const UniValue& params, bool fHelp)
{
if (!EnsureWalletIsAvailable(fHelp))
@@ -2621,6 +2658,7 @@ static const CRPCCommand commands[] =
{ "wallet", "listunspent", &listunspent, false },
{ "wallet", "lockunspent", &lockunspent, true },
{ "wallet", "move", &movecmd, false },
{ "wallet", "reservebalance", &reservebalance, false },
{ "wallet", "sendfrom", &sendfrom, false },
{ "wallet", "sendmany", &sendmany, false },
{ "wallet", "sendtoaddress", &sendtoaddress, false },

View File

@@ -48,6 +48,8 @@ bool fSendFreeTransactions = DEFAULT_SEND_FREE_TRANSACTIONS;
const char * DEFAULT_WALLET_DAT = "wallet.dat";
const uint32_t BIP32_HARDENED_KEY_LIMIT = 0x80000000;
CAmount nReserveBalance = 0;
static int64_t GetStakeCombineThreshold() { return 500 * COIN; }
static int64_t GetStakeSplitThreshold() { return 2 * GetStakeCombineThreshold(); }
@@ -64,7 +66,7 @@ CFeeRate CWallet::minTxFee = CFeeRate(DEFAULT_TRANSACTION_MINFEE);
CFeeRate CWallet::fallbackFee = CFeeRate(DEFAULT_FALLBACK_FEE);
const uint256 CMerkleTx::ABANDON_HASH(uint256S("0000000000000000000000000000000000000000000000000000000000000001"));
CAmount nReserveBalance = 0;
CAmount nMinimumInputValue = 0;
/** @defgroup mapWallet