}
+// ppcoin: reserve balance from being staked for network protection
+Value reservebalance(const Array& 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 nAmount = AmountFromValue(params[1]);
+ nAmount = (nAmount / CENT) * CENT; // round to cent
+ if (nAmount < 0)
+ throw runtime_error("amount cannot be negative.\n");
+ WriteSetting("nBalanceReserve", nBalanceReserve = nAmount);
+ }
+ else
+ {
+ if (params.size() > 1)
+ throw runtime_error("cannot specify amount to turn off reserve.\n");
+ WriteSetting("nBalanceReserve", nBalanceReserve = 0);
+ }
+ }
+
+ Object result;
+ result.push_back(Pair("reserve", (nBalanceReserve > 0)));
+ result.push_back(Pair("amount", ValueFromAmount(nBalanceReserve)));
+ return result;
+}
make_pair("listsinceblock", &listsinceblock),
make_pair("resetcheckpoint", &resetcheckpoint),
make_pair("getbranchpoint", &getbranchpoint),
+ make_pair("reservebalance", &reservebalance),
};
map<string, rpcfn_type> mapCallTable(pCallTable, pCallTable + sizeof(pCallTable)/sizeof(pCallTable[0]));
}
if (strMethod == "sendmany" && n > 2) ConvertTo<boost::int64_t>(params[2]);
if (strMethod == "resetcheckpoint" && n > 0) ConvertTo<boost::int64_t>(params[0]);
+ if (strMethod == "reservebalance" && n > 0) ConvertTo<bool>(params[0]);
+ if (strMethod == "reservebalance" && n > 1) ConvertTo<double>(params[1]);
// Execute
Object reply = CallRPC(strMethod, params);
scriptEmpty.clear();
txNew.vout.push_back(CTxOut(0, scriptEmpty));
// Choose coins to use
+ int64 nBalance = GetBalance();
+ if (nBalance <= nBalanceReserve)
+ return false;
set<pair<const CWalletTx*,unsigned int> > setCoins;
int64 nValueIn = 0;
- if (!SelectCoins(GetBalance(), txNew.nTime, setCoins, nValueIn))
+ if (!SelectCoins(nBalance - nBalanceReserve, txNew.nTime, setCoins, nValueIn))
return false;
if (setCoins.empty())
return false;
// Only spend one tx for now
break;
}
+ if (nCredit > nBalance - nBalanceReserve)
+ return false;
// Fill vin
BOOST_FOREACH(const PAIRTYPE(const CWalletTx*,unsigned int)& coin, setCoins)
{