|
10 | 10 | #include <tinyformat.h>
|
11 | 11 | #include <util.h>
|
12 | 12 | #include <utilstrencodings.h>
|
| 13 | +#include <crypto/sha256.h> |
13 | 14 | #include <versionbitsinfo.h>
|
14 | 15 |
|
15 | 16 | #include <assert.h>
|
16 | 17 |
|
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 | +// Safer for users if they load incorrect parameters via arguments. |
| 22 | +static std::vector<unsigned char> CommitToArguments(const Consensus::Params& params, const std::string& networkID) |
| 23 | +{ |
| 24 | + CSHA256 sha2; |
| 25 | + unsigned char commitment[32]; |
| 26 | + sha2.Write((const unsigned char*)networkID.c_str(), networkID.length()); |
| 27 | + // sha2.Write((const unsigned char*)HexStr(params.fedpegScript).c_str(), HexStr(params.fedpegScript).length()); |
| 28 | + // sha2.Write((const unsigned char*)HexStr(params.signblockscript).c_str(), HexStr(params.signblockscript).length()); |
| 29 | + sha2.Finalize(commitment); |
| 30 | + return std::vector<unsigned char>(commitment, commitment + 32); |
| 31 | +} |
| 32 | + |
| 33 | +static CBlock CreateGenesisBlock(const CScript& genesisScriptSig, const CScript& genesisOutputScript, uint32_t nTime, uint32_t nNonce, uint32_t nBits, int32_t nVersion, const CAmount& genesisReward) |
21 | 34 | {
|
22 | 35 | CMutableTransaction txNew;
|
23 | 36 | txNew.nVersion = 1;
|
24 | 37 | txNew.vin.resize(1);
|
25 | 38 | 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)); |
| 39 | + txNew.vin[0].scriptSig = genesisScriptSig; |
27 | 40 | txNew.vout[0].nValue = genesisReward;
|
28 | 41 | txNew.vout[0].scriptPubKey = genesisOutputScript;
|
29 | 42 |
|
@@ -52,8 +65,26 @@ static CBlock CreateGenesisBlock(const char* pszTimestamp, const CScript& genesi
|
52 | 65 | static CBlock CreateGenesisBlock(uint32_t nTime, uint32_t nNonce, uint32_t nBits, int32_t nVersion, const CAmount& genesisReward)
|
53 | 66 | {
|
54 | 67 | const char* pszTimestamp = "The Times 03/Jan/2009 Chancellor on brink of second bailout for banks";
|
| 68 | + const CScript genesisScriptSig = CScript() << 486604799 << CScriptNum(4) << std::vector<unsigned char>((const unsigned char*)pszTimestamp, (const unsigned char*)pszTimestamp + strlen(pszTimestamp)); |
55 | 69 | const CScript genesisOutputScript = CScript() << ParseHex("04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f") << OP_CHECKSIG;
|
56 |
| - return CreateGenesisBlock(pszTimestamp, genesisOutputScript, nTime, nNonce, nBits, nVersion, genesisReward); |
| 70 | + return CreateGenesisBlock(genesisScriptSig, genesisOutputScript, nTime, nNonce, nBits, nVersion, genesisReward); |
| 71 | +} |
| 72 | + |
| 73 | +/** Add an issuance transaction to the genesis block. Typically used to pre-issue |
| 74 | + * the policyAsset of a blockchain. The genesis block is not actually validated, |
| 75 | + * so this transaction simply has to match issuance structure. */ |
| 76 | +static void AppendInitialIssuance(CBlock& genesis_block, const COutPoint& prevout, const int64_t asset_values, const CScript& issuance_destination) { |
| 77 | + |
| 78 | + // Note: Genesis block isn't actually validated, outputs are entered into utxo db only |
| 79 | + CMutableTransaction txNew; |
| 80 | + txNew.nVersion = 1; |
| 81 | + txNew.vin.resize(1); |
| 82 | + txNew.vin[0].prevout = prevout; |
| 83 | + |
| 84 | + txNew.vout.push_back(CTxOut(asset_values, issuance_destination)); |
| 85 | + |
| 86 | + genesis_block.vtx.push_back(MakeTransactionRef(std::move(txNew))); |
| 87 | + genesis_block.hashMerkleRoot = BlockMerkleRoot(genesis_block); |
57 | 88 | }
|
58 | 89 |
|
59 | 90 | /**
|
@@ -442,6 +473,7 @@ class CCustomParams : public CRegTestParams {
|
442 | 473 | // All non-zero coinbase outputs must go to this scriptPubKey
|
443 | 474 | std::vector<unsigned char> man_bytes = ParseHex(gArgs.GetArg("-con_mandatorycoinbase", ""));
|
444 | 475 | consensus.mandatory_coinbase_destination = CScript(man_bytes.begin(), man_bytes.end()); // Blank script allows any coinbase destination
|
| 476 | + initialFreeCoins = gArgs.GetArg("-initialfreecoins", 0); |
445 | 477 |
|
446 | 478 | // Custom chains connect coinbase outputs to db by default
|
447 | 479 | consensus.connect_genesis_outputs = gArgs.GetArg("-con_connect_coinbase", true);
|
@@ -485,7 +517,11 @@ class CCustomParams : public CRegTestParams {
|
485 | 517 | {
|
486 | 518 | strNetworkID = chain;
|
487 | 519 | UpdateFromArgs(args);
|
488 |
| - genesis = CreateGenesisBlock(strNetworkID.c_str(), CScript(OP_TRUE), 1296688602, 2, 0x207fffff, 1, 50 * COIN); |
| 520 | + std::vector<unsigned char> commit = CommitToArguments(consensus, strNetworkID); |
| 521 | + genesis = CreateGenesisBlock(CScript(commit), CScript(OP_RETURN), 1296688602, 2, 0x207fffff, 1, 0); |
| 522 | + if (initialFreeCoins != 0) { |
| 523 | + AppendInitialIssuance(genesis, COutPoint(uint256(commit), 0), initialFreeCoins, CScript() << OP_TRUE); |
| 524 | + } |
489 | 525 | consensus.hashGenesisBlock = genesis.GetHash();
|
490 | 526 | }
|
491 | 527 | };
|
|
0 commit comments