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" , " signet_new" );
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 );
@@ -452,12 +460,44 @@ class CCustomParams : public CRegTestParams {
452460 }
453461 }
454462
463+ void SetGenesisBlock ()
464+ {
465+ if (consensus.genesis_style == " genesis_style1" ) {
466+ // Same style as in https://github.com/bitcoin/bitcoin/pull/8994
467+ assert (consensus.blockscript .empty () && " consensus.blockscript is for signets" );
468+ genesis = CreateGenesisBlock (strNetworkID.c_str (), CScript (OP_TRUE), 1296688602 , 2 , 0x207fffff , 1 , 50 * COIN);
469+
470+ } else if (consensus.genesis_style == " signet_new" ) {
471+ // Same style as in https://github.com/ElementsProject/elements/pull/433
472+ CHashWriter h (SER_DISK, 0 );
473+ h << strNetworkID;
474+ if (!consensus.blockscript .empty ()) {
475+ h << consensus.blockscript << consensus.siglen ;
476+ }
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 if (consensus.genesis_style == " signet_old" ) {
482+ // Same style as in https://github.com/kallewoof/bitcoin/pull/5
483+ assert (!consensus.blockscript .empty () && " Signets require consensus.blockscript" );
484+ CHashWriter h (SER_DISK, 0 );
485+ h << consensus.blockscript << consensus.siglen ;
486+ uint256 hash = h.GetHash ();
487+ CScript coinbase_sig = CScript () << std::vector<uint8_t >(hash.begin (), hash.end ());
488+ genesis = CreateGenesisBlock (coinbase_sig, CScript (OP_TRUE), 1534313275 , 0 , 0x1d00ffff , 1 , 50 * COIN);
489+
490+ } else {
491+ throw std::runtime_error (strprintf (" %s: Unknown consensus.genesis_style %s." , __func__, consensus.genesis_style ));
492+ }
493+ }
494+
455495public:
456496 CCustomParams (const std::string& chain, ArgsManager& args) : CRegTestParams(args)
457497 {
458498 strNetworkID = chain;
459499 UpdateFromArgs (args);
460- genesis = CreateGenesisBlock (strNetworkID. c_str (), CScript (OP_TRUE), 1296688602 , 2 , 0x207fffff , 1 , 50 * COIN );
500+ SetGenesisBlock ( );
461501 consensus.hashGenesisBlock = genesis.GetHash ();
462502 }
463503};
0 commit comments