diff options
| author | Ross Nicoll <[email protected]> | 2015-06-25 11:28:31 +0100 |
|---|---|---|
| committer | Ross Nicoll <[email protected]> | 2018-09-19 19:21:49 +0100 |
| commit | 8c0468c2d227e484f36ff24e3e420ad84312203a (patch) | |
| tree | 04a65bbfdc89d768341faa7a5a011482dec53402 /src/dogecoin.cpp | |
| parent | Replace consensus values with Dogecoin equivalents (diff) | |
| download | discoin-8c0468c2d227e484f36ff24e3e420ad84312203a.tar.xz discoin-8c0468c2d227e484f36ff24e3e420ad84312203a.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..72a9f3cc5 --- /dev/null +++ b/src/dogecoin.cpp @@ -0,0 +1,39 @@ +// Copyright (c) 2015 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; + } +} |