19
19
20
20
#include " chainparamsseeds.h"
21
21
22
+ static const uint32_t MAX_GENESIS_OUTPUTS = 500 ;
23
+
22
24
// Safer for users if they load incorrect parameters via arguments.
23
25
static std::vector<unsigned char > CommitToArguments (const Consensus::Params& params, const std::string& networkID)
24
26
{
@@ -43,20 +45,38 @@ static CScript StrHexToScriptWithDefault(std::string strScript, const CScript de
43
45
return returnScript;
44
46
}
45
47
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)
47
60
{
48
- // Shards must be evenly divisible
49
- assert (MAX_MONEY % rewardShards == 0 );
50
61
CMutableTransaction txNew;
51
62
txNew.nVersion = 1 ;
52
63
txNew.vin .resize (1 );
53
- txNew.vout .resize (rewardShards);
54
64
// Any consensus-related values that are command-line set can be added here for anti-footgun
55
65
txNew.vin [0 ].scriptSig = CScript (CommitToArguments (params, networkID));
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
+ }
60
80
}
61
81
62
82
CBlock genesis;
@@ -151,7 +171,10 @@ class CElementsParams : public CChainParams {
151
171
CalculateAsset (consensus.pegged_asset , entropy);
152
172
153
173
CScript scriptDestination (CScript () << std::vector<unsigned char >(parentGenesisBlockHash.begin (), parentGenesisBlockHash.end ()) << OP_WITHDRAWPROOFVERIFY);
154
- genesis = CreateGenesisBlock (consensus, strNetworkID, scriptDestination, 1231006505 , 1 , MAX_MONEY, 100 , consensus.pegged_asset );
174
+ const std::vector<GenesisReward> genesisRewards = {
175
+ GenesisReward (MAX_MONEY, scriptDestination, consensus.pegged_asset , 100 ),
176
+ };
177
+ genesis = CreateGenesisBlock (consensus, strNetworkID, 1231006505 , 1 , genesisRewards);
155
178
consensus.hashGenesisBlock = genesis.GetHash ();
156
179
157
180
scriptCoinbaseDestination = CScript () << ParseHex (" 0229536c4c83789f59c30b93eb40d4abbd99b8dcc99ba8bd748f29e33c1d279e3c" ) << OP_CHECKSIG;
@@ -260,7 +283,10 @@ class CRegTestParams : public CChainParams {
260
283
GenerateAssetEntropy (entropy, COutPoint (uint256 (commit), 0 ), parentGenesisBlockHash);
261
284
CalculateAsset (consensus.pegged_asset , entropy);
262
285
263
- genesis = CreateGenesisBlock (consensus, strNetworkID, defaultRegtestScript, 1296688602 , 1 , MAX_MONEY, 100 , consensus.pegged_asset );
286
+ const std::vector<GenesisReward> genesisRewards = {
287
+ GenesisReward (MAX_MONEY, defaultRegtestScript, consensus.pegged_asset , 100 ),
288
+ };
289
+ genesis = CreateGenesisBlock (consensus, strNetworkID, 1296688602 , 1 , genesisRewards);
264
290
consensus.hashGenesisBlock = genesis.GetHash ();
265
291
266
292
0 commit comments