Skip to content

Commit

Permalink
potentialstake RPC
Browse files Browse the repository at this point in the history
  • Loading branch information
presstab committed Feb 1, 2015
1 parent 131b3a5 commit 1586f0c
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/bitcoinrpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ static const CRPCCommand vRPCCommands[] =
{ "ccreset", &ccreset, false, false },
{ "ccsend", &ccsend, false, false },
{ "getweight", &getweight, false, false },
{ "getpotentialstake", &getpotentialstake, false, false },
{ "getconfs", &getconfs, false, false },
};

Expand Down
1 change: 1 addition & 0 deletions src/bitcoinrpc.h
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ extern json_spirit::Value cccustomchange(const json_spirit::Array& params, bool
extern json_spirit::Value ccreset(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value ccsend(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value getweight(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value getpotentialstake(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value getconfs(const json_spirit::Array& params, bool fHelp);

extern json_spirit::Value getrawtransaction(const json_spirit::Array& params, bool fHelp); // in rcprawtransaction.cpp
Expand Down
31 changes: 31 additions & 0 deletions src/rpcwallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2000,6 +2000,11 @@ Value getstaketx(const Array& params, bool fHelp)
//presstab HyperStake
Value getweight(const Array& params, bool fHelp)
{
if (fHelp)
throw runtime_error(
"getweight\n"
"This will return your total stake weight for confirmed outputs\n");

std::vector<COutput> vCoins;
pwalletMain->AvailableCoins(vCoins);

Expand All @@ -2018,6 +2023,32 @@ Value getweight(const Array& params, bool fHelp)
return (double)nWeightSum;
}

//presstab HyperStake
Value getpotentialstake(const Array& params, bool fHelp)
{
if (fHelp)
throw runtime_error(
"getpotentialstake\n"
"This will return your total potential stake for confirmed outputs\n"
"Potential stake is the amount your output reward is worth if it stakes right now");

std::vector<COutput> vCoins;
pwalletMain->AvailableCoins(vCoins);

double nRewardSum = 0;
BOOST_FOREACH(const COutput& out, vCoins)
{
int64 nHeight = nBestHeight - out.nDepth;
CBlockIndex* pindex = FindBlockByHeight(nHeight);
uint64 nAmount = out.tx->vout[out.i].nValue;
double dAge = double(GetTime() - pindex->nTime) / (60*60*24);
double nReward = 7.5 / 365 * dAge * (double)nAmount;
nReward = min(nReward / COIN, double(1000));
nRewardSum += nReward;
}
return nRewardSum;
}

// presstab HyperStake
Value setstakesplitthreshold(const Array& params, bool fHelp)
{
Expand Down

0 comments on commit 1586f0c

Please sign in to comment.