@@ -41,21 +41,15 @@ static CScript StrHexToScriptWithDefault(std::string strScript, const CScript de
4141 return returnScript;
4242}
4343
44- static CBlock CreateGenesisBlock (const Consensus::Params& params, const std::string& networkID, const CScript& genesisOutputScript, uint32_t nTime, const CScript& scriptChallenge, int32_t nVersion, const CAmount& genesisReward, const uint32_t rewardShards, const CAsset& asset )
44+ static CBlock CreateGenesisBlock (const Consensus::Params& params, const std::string& networkID, uint32_t nTime, const CScript& scriptChallenge, int32_t nVersion)
4545{
46- // Shards must be evenly divisible
47- assert (MAX_MONEY % rewardShards == 0 );
4846 CMutableTransaction txNew;
4947 txNew.nVersion = 1 ;
5048 txNew.vin .resize (1 );
51- txNew.vout .resize (rewardShards);
5249 // Any consensus-related values that are command-line set can be added here for anti-footgun
5350 txNew.vin [0 ].scriptSig = CScript (CommitToArguments (params, networkID, scriptChallenge));
54- for (unsigned int i = 0 ; i < rewardShards; i++) {
55- txNew.vout [i].nValue = genesisReward/rewardShards;
56- txNew.vout [i].nAsset = asset;
57- txNew.vout [i].scriptPubKey = genesisOutputScript;
58- }
51+ txNew.vout .clear ();
52+ txNew.vout .push_back (CTxOut (CAsset (), 0 , CScript () << OP_RETURN));
5953
6054 CBlock genesis;
6155 genesis.nTime = nTime;
@@ -67,6 +61,41 @@ static CBlock CreateGenesisBlock(const Consensus::Params& params, const std::str
6761 return genesis;
6862}
6963
64+ /* * Add an issuance transaction to the genesis block. Typically used to pre-issue
65+ * the policyAsset of a blockchain. The genesis block is not actually validated,
66+ * so this transaction simply has to match issuance structure. */
67+ static void AppendInitialIssuance (CBlock& genesis_block, const COutPoint& prevout, const uint256& contract, const int64_t asset_outputs, const int64_t asset_values, const int64_t reissuance_outputs, const int64_t reissuance_values, const CScript& issuance_destination) {
68+
69+ uint256 entropy;
70+ GenerateAssetEntropy (entropy, prevout, contract);
71+
72+ CAsset asset;
73+ CalculateAsset (asset, entropy);
74+
75+ // Re-issuance of policyAsset is always unblinded
76+ CAsset reissuance;
77+ CalculateReissuanceToken (reissuance, entropy, false );
78+
79+ // Note: Genesis block isn't actually validated, outputs are entered into utxo db only
80+ CMutableTransaction txNew;
81+ txNew.nVersion = 1 ;
82+ txNew.vin .resize (1 );
83+ txNew.vin [0 ].prevout = prevout;
84+ txNew.vin [0 ].assetIssuance .assetEntropy = contract;
85+ txNew.vin [0 ].assetIssuance .nAmount = asset_values*asset_outputs;
86+ txNew.vin [0 ].assetIssuance .nInflationKeys = reissuance_values*reissuance_outputs;
87+
88+ for (unsigned int i = 0 ; i < asset_outputs; i++) {
89+ txNew.vout .push_back (CTxOut (asset, asset_values, issuance_destination));
90+ }
91+ for (unsigned int i = 0 ; i < reissuance_outputs; i++) {
92+ txNew.vout .push_back (CTxOut (reissuance, reissuance_values, issuance_destination));
93+ }
94+
95+ genesis_block.vtx .push_back (MakeTransactionRef (std::move (txNew)));
96+ genesis_block.hashMerkleRoot = BlockMerkleRoot (genesis_block);
97+ }
98+
7099void CChainParams::UpdateBIP9Parameters (Consensus::DeploymentPos d, int64_t nStartTime, int64_t nTimeout)
71100{
72101 consensus.vDeployments [d].nStartTime = nStartTime;
@@ -149,7 +178,7 @@ class CElementsParams : public CChainParams {
149178 CalculateAsset (consensus.pegged_asset , entropy);
150179
151180 CScript scriptDestination (CScript () << std::vector<unsigned char >(parentGenesisBlockHash.begin (), parentGenesisBlockHash.end ()) << OP_WITHDRAWPROOFVERIFY);
152- genesis = CreateGenesisBlock (consensus, strNetworkID, scriptDestination, 1231006505 , genesisChallengeScript, 1 , MAX_MONEY, 100 , consensus. pegged_asset );
181+ genesis = CreateGenesisBlock (consensus, strNetworkID, 1231006505 , genesisChallengeScript, 1 );
153182 consensus.hashGenesisBlock = genesis.GetHash ();
154183
155184 scriptCoinbaseDestination = CScript () << ParseHex (" 0229536c4c83789f59c30b93eb40d4abbd99b8dcc99ba8bd748f29e33c1d279e3c" ) << OP_CHECKSIG;
@@ -259,7 +288,8 @@ class CRegTestParams : public CChainParams {
259288 GenerateAssetEntropy (entropy, COutPoint (uint256 (commit), 0 ), parentGenesisBlockHash);
260289 CalculateAsset (consensus.pegged_asset , entropy);
261290
262- genesis = CreateGenesisBlock (consensus, strNetworkID, defaultRegtestScript, 1296688602 , genesisChallengeScript, 1 , MAX_MONEY, 100 , consensus.pegged_asset );
291+ genesis = CreateGenesisBlock (consensus, strNetworkID, 1296688602 , genesisChallengeScript, 1 );
292+ AppendInitialIssuance (genesis, COutPoint (uint256 (commit), 0 ), parentGenesisBlockHash, 100 , 21000000000000 , 0 , 0 , CScript () << OP_TRUE);
263293 consensus.hashGenesisBlock = genesis.GetHash ();
264294
265295
0 commit comments