4
4
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
5
5
6
6
#include < chainparams.h>
7
- #include < consensus/merkle.h>
8
7
9
8
#include < chainparamsseeds.h>
9
+ #include < consensus/merkle.h>
10
+ #include < hash.h>
10
11
#include < tinyformat.h>
11
12
#include < util.h>
12
13
#include < utilstrencodings.h>
17
18
#include < boost/algorithm/string/classification.hpp>
18
19
#include < boost/algorithm/string/split.hpp>
19
20
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)
21
22
{
22
23
CMutableTransaction txNew;
23
24
txNew.nVersion = 1 ;
24
25
txNew.vin .resize (1 );
25
26
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 ;
27
28
txNew.vout [0 ].nValue = genesisReward;
28
29
txNew.vout [0 ].scriptPubKey = genesisOutputScript;
29
30
@@ -38,6 +39,12 @@ static CBlock CreateGenesisBlock(const char* pszTimestamp, const CScript& genesi
38
39
return genesis;
39
40
}
40
41
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
+
41
48
/* *
42
49
* Build the genesis block. Note that the output of its generation
43
50
* transaction cannot be spent since it did not originally exist in the
@@ -403,6 +410,7 @@ class CCustomParams : public CRegTestParams {
403
410
{
404
411
UpdateVersionBitsParametersFromArgs (args);
405
412
413
+ consensus.genesis_style = args.GetArg (" -con_genesis_style" , " signet_new" );
406
414
consensus.nSubsidyHalvingInterval = args.GetArg (" -con_nsubsidyhalvinginterval" , consensus.nSubsidyHalvingInterval );
407
415
consensus.BIP16Exception = uint256S (args.GetArg (" -con_bip16exception" , " 0x0" ));
408
416
consensus.BIP34Height = args.GetArg (" -con_bip34height" , consensus.BIP34Height );
@@ -452,12 +460,44 @@ class CCustomParams : public CRegTestParams {
452
460
}
453
461
}
454
462
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
+
455
495
public:
456
496
CCustomParams (const std::string& chain, ArgsManager& args) : CRegTestParams(args)
457
497
{
458
498
strNetworkID = chain;
459
499
UpdateFromArgs (args);
460
- genesis = CreateGenesisBlock (strNetworkID. c_str (), CScript (OP_TRUE), 1296688602 , 2 , 0x207fffff , 1 , 50 * COIN );
500
+ SetGenesisBlock ( );
461
501
consensus.hashGenesisBlock = genesis.GetHash ();
462
502
}
463
503
};
0 commit comments