diff --git a/src/chainparams.cpp b/src/chainparams.cpp index e335fe7b30..b43acb9228 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -475,6 +475,9 @@ class CCustomParams : public CRegTestParams { consensus.mandatory_coinbase_destination = CScript(man_bytes.begin(), man_bytes.end()); // Blank script allows any coinbase destination initialFreeCoins = gArgs.GetArg("-initialfreecoins", 0); + // Determines type of genesis block + consensus.genesis_style = gArgs.GetArg("-con_genesis_style", "elements"); + // Custom chains connect coinbase outputs to db by default consensus.connect_genesis_outputs = gArgs.GetArg("-con_connect_coinbase", true); @@ -512,16 +515,28 @@ class CCustomParams : public CRegTestParams { } } + void SetGenesisBlock() { + if (consensus.genesis_style == "bitcoin") { + // For compatibility with bitcoin (regtest) + genesis = CreateGenesisBlock(1296688602, 2, 0x207fffff, 1, 50 * COIN); + } else if (consensus.genesis_style == "elements") { + // Intended compatibility with Liquid v1 and elements-0.14.1 + std::vector commit = CommitToArguments(consensus, strNetworkID); + genesis = CreateGenesisBlock(CScript(commit), CScript(OP_RETURN), 1296688602, 2, 0x207fffff, 1, 0); + if (initialFreeCoins != 0) { + AppendInitialIssuance(genesis, COutPoint(uint256(commit), 0), initialFreeCoins, CScript() << OP_TRUE); + } + } else { + throw std::runtime_error(strprintf("Invalid -genesis_style (%s)", consensus.genesis_style)); + } + } + public: CCustomParams(const std::string& chain, ArgsManager& args) : CRegTestParams(args) { strNetworkID = chain; UpdateFromArgs(args); - std::vector commit = CommitToArguments(consensus, strNetworkID); - genesis = CreateGenesisBlock(CScript(commit), CScript(OP_RETURN), 1296688602, 2, 0x207fffff, 1, 0); - if (initialFreeCoins != 0) { - AppendInitialIssuance(genesis, COutPoint(uint256(commit), 0), initialFreeCoins, CScript() << OP_TRUE); - } + SetGenesisBlock(); consensus.hashGenesisBlock = genesis.GetHash(); } }; diff --git a/src/chainparamsbase.cpp b/src/chainparamsbase.cpp index 1cc7a8448f..b3f72dbe18 100644 --- a/src/chainparamsbase.cpp +++ b/src/chainparamsbase.cpp @@ -27,6 +27,7 @@ void SetupChainParamsBaseOptions() gArgs.AddArg("-con_blocksubsidy", "Defines the amount of block subsidy to start with, at genesis block.", false, OptionsCategory::ELEMENTS); gArgs.AddArg("-con_connect_coinbase", "Connect outputs in genesis block to utxo database.", false, OptionsCategory::ELEMENTS); gArgs.AddArg("-con_blockheightinheader", "Whether the chain includes the block height directly in the header, for easier validation of block height in low-resource environments. (default: true)", false, OptionsCategory::CHAINPARAMS); + gArgs.AddArg("-con_genesis_style=