44// file COPYING or http://www.opensource.org/licenses/mit-license.php.
55
66#include < chainparams.h>
7- #include < consensus/merkle.h>
87
98#include < chainparamsseeds.h>
9+ #include < consensus/merkle.h>
10+ #include < hash.h>
1011#include < tinyformat.h>
1112#include < util.h>
1213#include < utilstrencodings.h>
1718#include < boost/algorithm/string/classification.hpp>
1819#include < boost/algorithm/string/split.hpp>
1920
20- static CBlock CreateGenesisBlock (const char * pszTimestamp , const CScript& genesisOutputScript, uint32_t nTime, uint32_t nNonce, uint32_t nBits, int32_t nVersion, const CAmount& genesisReward)
21+ static CBlock CreateGenesisBlock (const CScript& coinbase_sig , const CScript& genesisOutputScript, uint32_t nTime, uint32_t nNonce, uint32_t nBits, int32_t nVersion, const CAmount& genesisReward)
2122{
2223 CMutableTransaction txNew;
2324 txNew.nVersion = 1 ;
2425 txNew.vin .resize (1 );
2526 txNew.vout .resize (1 );
26- txNew.vin [0 ].scriptSig = CScript () << 486604799 << CScriptNum ( 4 ) << std::vector< unsigned char >(( const unsigned char *)pszTimestamp, ( const unsigned char *)pszTimestamp + strlen (pszTimestamp)) ;
27+ txNew.vin [0 ].scriptSig = coinbase_sig ;
2728 txNew.vout [0 ].nValue = genesisReward;
2829 txNew.vout [0 ].scriptPubKey = genesisOutputScript;
2930
@@ -38,6 +39,12 @@ static CBlock CreateGenesisBlock(const char* pszTimestamp, const CScript& genesi
3839 return genesis;
3940}
4041
42+ static CBlock CreateGenesisBlock (const char * pszTimestamp, const CScript& genesisOutputScript, uint32_t nTime, uint32_t nNonce, uint32_t nBits, int32_t nVersion, const CAmount& genesisReward)
43+ {
44+ CScript coinbase_sig = CScript () << 486604799 << CScriptNum (4 ) << std::vector<unsigned char >((const unsigned char *)pszTimestamp, (const unsigned char *)pszTimestamp + strlen (pszTimestamp));
45+ return CreateGenesisBlock (coinbase_sig, genesisOutputScript, nTime, nNonce, nBits, nVersion, genesisReward);
46+ }
47+
4148/* *
4249 * Build the genesis block. Note that the output of its generation
4350 * transaction cannot be spent since it did not originally exist in the
@@ -403,6 +410,7 @@ class CCustomParams : public CRegTestParams {
403410 {
404411 UpdateVersionBitsParametersFromArgs (args);
405412
413+ consensus.genesis_style = args.GetArg (" -con_genesis_style" , " default_style" );
406414 consensus.nSubsidyHalvingInterval = args.GetArg (" -con_nsubsidyhalvinginterval" , consensus.nSubsidyHalvingInterval );
407415 consensus.BIP16Exception = uint256S (args.GetArg (" -con_bip16exception" , " 0x0" ));
408416 consensus.BIP34Height = args.GetArg (" -con_bip34height" , consensus.BIP34Height );
@@ -457,12 +465,30 @@ class CCustomParams : public CRegTestParams {
457465 }
458466 }
459467
468+ void SetGenesisBlock ()
469+ {
470+ if (consensus.genesis_style == " regtest2_style" ) {
471+ // Same style as in https://github.com/bitcoin/bitcoin/pull/8994
472+ genesis = CreateGenesisBlock (strNetworkID.c_str (), CScript (OP_TRUE), 1296688602 , 2 , 0x207fffff , 1 , 50 * COIN);
473+
474+ } else if (consensus.genesis_style == " default_style" ) {
475+ CHashWriter h (SER_DISK, 0 );
476+ h << strNetworkID;
477+ uint256 hash = h.GetHash ();
478+ CScript coinbase_sig = CScript () << std::vector<uint8_t >(hash.begin (), hash.end ());
479+ genesis = CreateGenesisBlock (coinbase_sig, CScript (OP_TRUE), 1296688602 , 2 , 0x207fffff , 1 , 50 * COIN);
480+
481+ } else {
482+ throw std::runtime_error (strprintf (" %s: Unknown consensus.genesis_style %s." , __func__, consensus.genesis_style ));
483+ }
484+ }
485+
460486public:
461487 CCustomParams (const std::string& chain, ArgsManager& args) : CRegTestParams(args)
462488 {
463489 strNetworkID = chain;
464490 UpdateFromArgs (args);
465- genesis = CreateGenesisBlock (strNetworkID. c_str (), CScript (OP_TRUE), 1296688602 , 2 , 0x207fffff , 1 , 50 * COIN );
491+ SetGenesisBlock ( );
466492 consensus.hashGenesisBlock = genesis.GetHash ();
467493 }
468494};
0 commit comments