1919
2020#include " chainparamsseeds.h"
2121
22+ static const uint32_t MAX_GENESIS_OUTPUTS = 500 ;
23+
2224// Safer for users if they load incorrect parameters via arguments.
2325static std::vector<unsigned char > CommitToArguments (const Consensus::Params& params, const std::string& networkID)
2426{
@@ -43,20 +45,38 @@ static CScript StrHexToScriptWithDefault(std::string strScript, const CScript de
4345 return returnScript;
4446}
4547
46- static CBlock CreateGenesisBlock (const Consensus::Params& params, const std::string& networkID, const CScript& genesisOutputScript, uint32_t nTime, int32_t nVersion, const CAmount& genesisReward, const uint32_t rewardShards, const CAsset& genesisAsset)
48+ struct GenesisReward
49+ {
50+ const CAmount nTotalAmount;
51+ const CScript outputScript;
52+ const CAsset asset;
53+ const uint32_t nShards;
54+
55+ GenesisReward (const CAmount& nTotalAmountIn, const CScript& outputScriptIn, const CAsset& assetIn, const uint32_t nShardsIn=1 ) :
56+ nTotalAmount (nTotalAmountIn), outputScript(outputScriptIn), asset(assetIn), nShards(nShardsIn) {};
57+ };
58+
59+ static CBlock CreateGenesisBlock (const Consensus::Params& params, const std::string& networkID, uint32_t nTime, int32_t nVersion, const std::vector<GenesisReward>& genesisRewards)
4760{
48- // Shards must be evenly divisible
49- assert (MAX_MONEY % rewardShards == 0 );
5061 CMutableTransaction txNew;
5162 txNew.nVersion = 1 ;
5263 txNew.vin .resize (1 );
5364 // Any consensus-related values that are command-line set can be added here for anti-footgun
5465 txNew.vin [0 ].scriptSig = CScript (CommitToArguments (params, networkID));
55- txNew.vout .resize (rewardShards);
56- for (unsigned int i = 0 ; i < rewardShards; i++) {
57- txNew.vout [i].nValue = genesisReward/rewardShards;
58- txNew.vout [i].nAsset = genesisAsset;
59- txNew.vout [i].scriptPubKey = genesisOutputScript;
66+
67+ unsigned int totalOutputs = 0 ;
68+ for (GenesisReward gReward : genesisRewards) totalOutputs += gReward .nShards ;
69+ assert (totalOutputs <= MAX_GENESIS_OUTPUTS);
70+ txNew.vout .resize (totalOutputs);
71+
72+ for (GenesisReward gReward : genesisRewards) {
73+ for (unsigned int i = 0 ; i < gReward .nShards ; i++) {
74+ // Shards must be evenly divisible
75+ assert (gReward .nTotalAmount % gReward .nShards == 0 );
76+ txNew.vout [i].nValue = gReward .nTotalAmount / gReward .nShards ;
77+ txNew.vout [i].nAsset = gReward .asset ;
78+ txNew.vout [i].scriptPubKey = gReward .outputScript ;
79+ }
6080 }
6181
6282 CBlock genesis;
@@ -139,7 +159,10 @@ class CElementsParams : public CChainParams {
139159
140160 parentGenesisBlockHash = uint256S (" 000000000933ea01ad0ee984209779baaec3ced90fa3f408719526f8d77f4943" );
141161 CScript scriptDestination (CScript () << std::vector<unsigned char >(parentGenesisBlockHash.begin (), parentGenesisBlockHash.end ()) << OP_WITHDRAWPROOFVERIFY);
142- genesis = CreateGenesisBlock (consensus, strNetworkID, scriptDestination, 1231006505 , 1 , MAX_MONEY, 100 , BITCOINID);
162+ const std::vector<GenesisReward> genesisRewards = {
163+ GenesisReward (MAX_MONEY, scriptDestination, BITCOINID, 100 ),
164+ };
165+ genesis = CreateGenesisBlock (consensus, strNetworkID, 1231006505 , 1 , genesisRewards);
143166 consensus.hashGenesisBlock = genesis.GetHash ();
144167
145168 scriptCoinbaseDestination = CScript () << ParseHex (" 0229536c4c83789f59c30b93eb40d4abbd99b8dcc99ba8bd748f29e33c1d279e3c" ) << OP_CHECKSIG;
@@ -241,7 +264,10 @@ class CRegTestParams : public CChainParams {
241264 nDefaultPort = 7042 ;
242265 nPruneAfterHeight = 1000 ;
243266
244- genesis = CreateGenesisBlock (consensus, strNetworkID, defaultRegtestScript, 1296688602 , 1 , MAX_MONEY, 100 , BITCOINID);
267+ const std::vector<GenesisReward> genesisRewards = {
268+ GenesisReward (MAX_MONEY, consensus.fedpegScript , BITCOINID, 100 ),
269+ };
270+ genesis = CreateGenesisBlock (consensus, strNetworkID, 1296688602 , 1 , genesisRewards);
245271 consensus.hashGenesisBlock = genesis.GetHash ();
246272
247273 parentGenesisBlockHash = uint256S (" 0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206" );
0 commit comments