Auto merge of #1059 - bitcartel:zc.v0.11.2.z5_getblocksubsidy, r=ebfull

Add getblocksubsidy RPC command to return block reward taking into account mining slow start

This PR adds a new RPC command to return the block reward as defined by function `GetBlockSubsidy`.

Usage:
`zcash-cli getblocksubsidy blockheight
`

The basis for this PR is that some users have been unaware of the mining slow start and they subsequently sought help to clarify if they were mining blocks correctly or if there was a bug in the reward schedule.
This commit is contained in:
zkbot 2016-07-17 16:19:39 +00:00
commit f30580744f
4 changed files with 40 additions and 1 deletions

View File

@ -95,7 +95,8 @@ static const CRPCConvertParam vRPCConvertParams[] =
{ "zcrawpour", 2 },
{ "zcrawpour", 3 },
{ "zcrawpour", 4 },
{ "zcbenchmark", 1 }
{ "zcbenchmark", 1 },
{ "getblocksubsidy", 0}
};
class CRPCConvertTable

View File

@ -766,3 +766,38 @@ Value estimatepriority(const Array& params, bool fHelp)
return mempool.estimatePriority(nBlocks);
}
Value getblocksubsidy(const Array& params, bool fHelp)
{
if (fHelp || params.size() != 1)
throw runtime_error(
"getblocksubsidy height\n"
"\nReturns block subsidy reward, taking into account the mining slow start and the founders reward, of block at index provided.\n"
"\nArguments:\n"
"1. height (numeric, required) The block height.\n"
"\nResult:\n"
"{\n"
" \"miner\" : x.xxx (numeric) The mining reward amount in ZEC.\n"
" \"founders\" : x.xxx (numeric) The founders reward amount in ZEC.\n"
"}\n"
"\nExamples:\n"
+ HelpExampleCli("getblocksubsidy", "1000")
+ HelpExampleRpc("getblockubsidy", "1000")
);
int nHeight = params[0].get_int();
LOCK(cs_main);
if (nHeight < 0 || nHeight > chainActive.Height())
throw JSONRPCError(RPC_INVALID_PARAMETER, "Block height out of range");
CAmount nReward = GetBlockSubsidy(nHeight, Params().GetConsensus());
CAmount nFoundersReward = 0;
if ((nHeight > 0) && (nHeight < Params().GetConsensus().nSubsidyHalvingInterval)) {
nFoundersReward = nReward/5;
nReward -= nFoundersReward;
}
Object result;
result.push_back(Pair("miner", ValueFromAmount(nReward)));
result.push_back(Pair("founders", ValueFromAmount(nFoundersReward)));
return result;
}

View File

@ -304,6 +304,7 @@ static const CRPCCommand vRPCCommands[] =
{ "mining", "getnetworkhashps", &getnetworkhashps, true },
{ "mining", "prioritisetransaction", &prioritisetransaction, true },
{ "mining", "submitblock", &submitblock, true },
{ "mining", "getblocksubsidy", &getblocksubsidy, true },
#ifdef ENABLE_WALLET
/* Coin generation */

View File

@ -240,6 +240,8 @@ extern json_spirit::Value getchaintips(const json_spirit::Array& params, bool fH
extern json_spirit::Value invalidateblock(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value reconsiderblock(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value getblocksubsidy(const json_spirit::Array& params, bool fHelp);
// in rest.cpp
extern bool HTTPReq_REST(AcceptedConnection *conn,
const std::string& strURI,