From 1b114e54c4c1b6665803706a5d11b7fedb5a6551 Mon Sep 17 00:00:00 2001 From: Simon Date: Mon, 27 Jun 2016 13:04:33 -0700 Subject: [PATCH 1/4] Add getblocksubsidy RPC command to return the block reward for a given block, taking into account the mining slow start. --- src/rpcclient.cpp | 3 ++- src/rpcmining.cpp | 24 ++++++++++++++++++++++++ src/rpcserver.cpp | 1 + src/rpcserver.h | 2 ++ 4 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/rpcclient.cpp b/src/rpcclient.cpp index fe7903ad0..d8fc89014 100644 --- a/src/rpcclient.cpp +++ b/src/rpcclient.cpp @@ -95,7 +95,8 @@ static const CRPCConvertParam vRPCConvertParams[] = { "zcrawpour", 2 }, { "zcrawpour", 3 }, { "zcrawpour", 4 }, - { "zcbenchmark", 1 } + { "zcbenchmark", 1 }, + { "getblocksubsidy", 0} }; class CRPCConvertTable diff --git a/src/rpcmining.cpp b/src/rpcmining.cpp index a8f400271..c7092db74 100644 --- a/src/rpcmining.cpp +++ b/src/rpcmining.cpp @@ -766,3 +766,27 @@ 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 index\n" + "\nReturns block subsidy reward, taking into account the mining slow start, of block at index provided.\n" + "\nArguments:\n" + "1. index (numeric, required) The block index\n" + "\nResult:\n" + "amount (numeric) The block reward amount in ZEC.\n" + "\nExamples:\n" + + HelpExampleCli("getblocksubsidy", "1000") + + HelpExampleRpc("getblockubsidy", "1000") + ); + + LOCK(cs_main); + int nHeight = params[0].get_int(); + if (nHeight < 0 || nHeight > chainActive.Height()) + throw JSONRPCError(RPC_INVALID_PARAMETER, "Block height out of range"); + + CAmount nReward = GetBlockSubsidy(nHeight, Params().GetConsensus()); + return ValueFromAmount(nReward); +} diff --git a/src/rpcserver.cpp b/src/rpcserver.cpp index e042db37f..528e2e0ee 100644 --- a/src/rpcserver.cpp +++ b/src/rpcserver.cpp @@ -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 */ diff --git a/src/rpcserver.h b/src/rpcserver.h index aa64e0252..843736098 100644 --- a/src/rpcserver.h +++ b/src/rpcserver.h @@ -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, From 1db13d50639d070ca5b89564e6b790b77279f03b Mon Sep 17 00:00:00 2001 From: Simon Date: Mon, 11 Jul 2016 21:53:09 -0700 Subject: [PATCH 2/4] Replace index with height in help message for getblocksubsidy RPC call. --- src/rpcmining.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/rpcmining.cpp b/src/rpcmining.cpp index c7092db74..0cbce438d 100644 --- a/src/rpcmining.cpp +++ b/src/rpcmining.cpp @@ -771,10 +771,10 @@ Value getblocksubsidy(const Array& params, bool fHelp) { if (fHelp || params.size() != 1) throw runtime_error( - "getblocksubsidy index\n" + "getblocksubsidy height\n" "\nReturns block subsidy reward, taking into account the mining slow start, of block at index provided.\n" "\nArguments:\n" - "1. index (numeric, required) The block index\n" + "1. height (numeric, required) The block height.\n" "\nResult:\n" "amount (numeric) The block reward amount in ZEC.\n" "\nExamples:\n" From 933bff472d7aa8d3b03c306bb2a33480f11d9dfc Mon Sep 17 00:00:00 2001 From: Simon Date: Mon, 11 Jul 2016 22:01:15 -0700 Subject: [PATCH 3/4] Narrow scope of lock. --- src/rpcmining.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rpcmining.cpp b/src/rpcmining.cpp index 0cbce438d..f41f26195 100644 --- a/src/rpcmining.cpp +++ b/src/rpcmining.cpp @@ -782,8 +782,8 @@ Value getblocksubsidy(const Array& params, bool fHelp) + HelpExampleRpc("getblockubsidy", "1000") ); - LOCK(cs_main); 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"); From ea26d328fcc3a72957af91eacdedb4303b2a7e62 Mon Sep 17 00:00:00 2001 From: Simon Date: Thu, 14 Jul 2016 13:05:32 -0700 Subject: [PATCH 4/4] Add founders reward to output. --- src/rpcmining.cpp | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/rpcmining.cpp b/src/rpcmining.cpp index f41f26195..82bbe0c12 100644 --- a/src/rpcmining.cpp +++ b/src/rpcmining.cpp @@ -772,11 +772,14 @@ 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, of block at index provided.\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" - "amount (numeric) The block reward amount in ZEC.\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") @@ -788,5 +791,13 @@ Value getblocksubsidy(const Array& params, bool fHelp) throw JSONRPCError(RPC_INVALID_PARAMETER, "Block height out of range"); CAmount nReward = GetBlockSubsidy(nHeight, Params().GetConsensus()); - return ValueFromAmount(nReward); + 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; }