Skip to content

Commit

Permalink
setstakesplitthreshold RPC call (default 1000)
Browse files Browse the repository at this point in the history
  • Loading branch information
presstab committed Nov 8, 2014
1 parent 0943630 commit 33529f1
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 53 deletions.
5 changes: 2 additions & 3 deletions src/bitcoinrpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ static const CRPCCommand vRPCCommands[] =
{ "getaccount", &getaccount, false, false },
{ "getaddressesbyaccount", &getaddressesbyaccount, true, false },
{ "sendtoaddress", &sendtoaddress, false, false },
//{ "splitblock", &splitblock, false, false },
{ "setstakesplitthreshold", &setstakesplitthreshold, false, false },
{ "getreceivedbyaddress", &getreceivedbyaddress, false, false },
{ "getreceivedbyaccount", &getreceivedbyaccount, false, false },
{ "listreceivedbyaddress", &listreceivedbyaddress, false, false },
Expand Down Expand Up @@ -1157,8 +1157,6 @@ Array RPCConvertValues(const std::string &strMethod, const std::vector<std::stri
if (strMethod == "setgenerate" && n > 0) ConvertTo<bool>(params[0]);
if (strMethod == "setgenerate" && n > 1) ConvertTo<boost::int64_t>(params[1]);
if (strMethod == "sendtoaddress" && n > 1) ConvertTo<double>(params[1]);
//if (strMethod == "splitblock" && n > 1) ConvertTo<double>(params[1]);
//if (strMethod == "splitblock" && n > 1) ConvertTo<double>(params[2]);
if (strMethod == "settxfee" && n > 0) ConvertTo<double>(params[0]);
if (strMethod == "getaddednodeinfo" && n > 0) ConvertTo<bool>(params[0]);
if (strMethod == "getreceivedbyaddress" && n > 1) ConvertTo<boost::int64_t>(params[1]);
Expand Down Expand Up @@ -1203,6 +1201,7 @@ Array RPCConvertValues(const std::string &strMethod, const std::vector<std::stri
if (strMethod == "stakeforcharity" && n > 1) ConvertTo<int>(params[1]);
if (strMethod == "stakeforcharity" && n > 3) ConvertTo<double>(params[3]);
if (strMethod == "stakeforcharity" && n > 4) ConvertTo<double>(params[4]);
if (strMethod == "setstakesplitthreshold" && n > 0) ConvertTo<int>(params[0]);

return params;
}
Expand Down
1 change: 1 addition & 0 deletions src/bitcoinrpc.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ extern json_spirit::Value validatepubkey(const json_spirit::Array& params, bool
extern json_spirit::Value getnewpubkey(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value getnetworkhashps(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value stakeforcharity(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value setstakesplitthreshold(const json_spirit::Array& params, bool fHelp);

extern json_spirit::Value getrawtransaction(const json_spirit::Array& params, bool fHelp); // in rcprawtransaction.cpp
extern json_spirit::Value listunspent(const json_spirit::Array& params, bool fHelp);
Expand Down
69 changes: 21 additions & 48 deletions src/rpcwallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -543,54 +543,6 @@ Value sendtoaddress(const Array& params, bool fHelp)
return wtx.GetHash().GetHex();
}


/*Value splitblock(const Array& params, bool fHelp)
{
if (fHelp || params.size() < 3 || params.size() > 3)
throw runtime_error(
"splitblock <HyperStakeaddress> <amount> <howmanyblocks>\n"
"<amount> is a real and is rounded to the nearest 0.000001"
+ HelpRequiringPassphrase());
CBitcoinAddress address(params[0].get_str());
if (!address.IsValid())
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid HyperStake address");
// Amount
double dAmount = params[1].get_real();
double dBlocks = params[2].get_real();
dAmount = dAmount / dBlocks;
int64 nAmount = AmountFromValue(dAmount * COIN);
if (nAmount < MIN_TXOUT_AMOUNT)
throw JSONRPCError(-101, "Send amount too small");
// Wallet transaction
vector<CBitcoinAddress> vecAddress; //vector containing the single address that will be sent to
for(int nIndex = 0; nIndex < dBlocks; ++nIndex)
{
vecAddress.push_back (address.Get());
}
//if (pwalletMain->IsLocked())
// throw JSONRPCError(RPC_WALLET_UNLOCK_NEEDED, "Error: Please enter the wallet passphrase with walletpassphrase first.");
for(int nIndex = 0; nIndex < dBlocks; ++nIndex)
{
CWalletTx wtx;
string strError = pwalletMain->SendMoneyToDestination(address.Get(), nAmount, wtx);
if (strError != "")
throw JSONRPCError(RPC_WALLET_ERROR, strError);
}
return nAmount;
}*/


Value listaddressgroupings(const Array& params, bool fHelp)
{
if (fHelp)
Expand Down Expand Up @@ -2121,3 +2073,24 @@ Value makekeypair(const Array& params, bool fHelp)
result.push_back(Pair("PublicKey", HexStr(key.GetPubKey().Raw())));
return result;
}

// presstab HyperStake
Value setstakesplitthreshold(const Array& params, bool fHelp)
{
if (fHelp || params.size() > 1)
throw runtime_error(
"setstakesplitthreshold <1 - 999,999>\n"
"This will set the output size of your stakes to never be below this number\n");
uint64 nStakeSplitThreshold = params[0].get_int();
if (pwalletMain->IsLocked())
throw JSONRPCError(RPC_WALLET_UNLOCK_NEEDED, "Error: Unlock wallet to use this feature");
if (nStakeSplitThreshold > 999999)
return "out of range - setting split threshold failed";
else
{
Object result;
pwalletMain->nStakeSplitThreshold = nStakeSplitThreshold;
result.push_back(Pair("split stake threshold set to ", nStakeSplitThreshold));
return result;
}
}
4 changes: 2 additions & 2 deletions src/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1710,10 +1710,10 @@ bool CWallet::CreateCoinStake(const CKeyStore& keystore, unsigned int nBits, int

vwtxPrev.push_back(pcoin.first);
txNew.vout.push_back(CTxOut(0, scriptPubKeyOut));
uint64 nTotalSize = pcoin.first->vout[pcoin.second].nValue * ((txNew.nTime - block.GetBlockTime()) / (60*60*24)) * (7.5/365);
uint64 nTotalSize = pcoin.first->vout[pcoin.second].nValue * (1+((txNew.nTime - block.GetBlockTime()) / (60*60*24)) * (7.5/365));


if ((block.GetBlockTime() + nStakeSplitAge > txNew.nTime) && ((nTotalSize / 2) > (1000 * COIN)))
if ((block.GetBlockTime() + nStakeSplitAge > txNew.nTime) && ((nTotalSize / 2) > (nStakeSplitThreshold * COIN)))
txNew.vout.push_back(CTxOut(0, scriptPubKeyOut)); //split stake

if (fDebug && GetBoolArg("-printcoinstake"))
Expand Down
3 changes: 3 additions & 0 deletions src/wallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ class CWallet : public CCryptoKeyStore
int64 nAmountSelected;
std::string strBestAddress;
bool fCombine;
uint64 nStakeSplitThreshold;

std::set<int64> setKeyPool;

Expand Down Expand Up @@ -122,6 +123,7 @@ class CWallet : public CCryptoKeyStore
nAmountSelected = 0;
strBestAddress = "";
fCombine = false;
nStakeSplitThreshold = 1000;
}
CWallet(std::string strWalletFileIn)
{
Expand All @@ -143,6 +145,7 @@ class CWallet : public CCryptoKeyStore
nAmountSelected = 0;
strBestAddress = "";
fCombine = false;
nStakeSplitThreshold = 1000;
}

std::map<uint256, CWalletTx> mapWallet;
Expand Down

0 comments on commit 33529f1

Please sign in to comment.