diff options
| author | Ross Nicoll <[email protected]> | 2015-06-25 11:28:31 +0100 |
|---|---|---|
| committer | Ross Nicoll <[email protected]> | 2019-04-03 05:16:26 +0000 |
| commit | 9b494d566caa8d3cd6193bbc80ddac10541b0168 (patch) | |
| tree | 1369169da3480374f31974fa118fd393478f5786 /src/dogecoin.cpp | |
| parent | Replace consensus values with Dogecoin equivalents (diff) | |
| download | discoin-9b494d566caa8d3cd6193bbc80ddac10541b0168.tar.xz discoin-9b494d566caa8d3cd6193bbc80ddac10541b0168.zip | |
Add Dogecoin block subsidy calculations.
Diffstat (limited to 'src/dogecoin.cpp')
| -rw-r--r-- | src/dogecoin.cpp | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/src/dogecoin.cpp b/src/dogecoin.cpp new file mode 100644 index 000000000..77a8a0093 --- /dev/null +++ b/src/dogecoin.cpp @@ -0,0 +1,39 @@ +// Copyright (c) 2015-2017 The Dogecoin Core developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#include <boost/random/uniform_int.hpp> +#include <boost/random/mersenne_twister.hpp> + +#include "dogecoin.h" + +int static generateMTRandom(unsigned int s, int range) +{ + boost::mt19937 gen(s); + boost::uniform_int<> dist(1, range); + return dist(gen); +} + +CAmount GetDogecoinBlockSubsidy(int nHeight, const Consensus::Params& consensusParams, uint256 prevHash) +{ + int halvings = nHeight / consensusParams.nSubsidyHalvingInterval; + + if (nHeight < 145000) // && !consensusParams.SimplifiedRewards()) + { + // Old-style rewards derived from the previous block hash + const std::string cseed_str = prevHash.ToString().substr(7, 7); + const char* cseed = cseed_str.c_str(); + char* endp = NULL; + long seed = strtol(cseed, &endp, 16); + CAmount maxReward = (1000000 >> halvings) - 1; + int rand = generateMTRandom(seed, maxReward); + + return (1 + rand) * COIN; + } else if (nHeight < (6 * consensusParams.nSubsidyHalvingInterval)) { + // New-style constant rewards for each halving interval + return (500000 * COIN) >> halvings; + } else { + // Constant inflation + return 10000 * COIN; + } +} |