示例#1
0
        private static void LoadGenesis(GenesisFileJson genesisJson, ChainSpec chainSpec)
        {
            var nonce       = genesisJson.Nonce;
            var mixHash     = genesisJson.MixHash;
            var parentHash  = genesisJson.ParentHash ?? Keccak.Zero;
            var timestamp   = genesisJson.Timestamp;
            var difficulty  = genesisJson.Difficulty;
            var extraData   = genesisJson.ExtraData;
            var gasLimit    = genesisJson.GasLimit;
            var beneficiary = genesisJson.Author ?? Address.Zero;

            BlockHeader genesisHeader = new BlockHeader(
                parentHash,
                Keccak.OfAnEmptySequenceRlp,
                beneficiary,
                difficulty,
                0,
                (long)gasLimit,
                timestamp,
                extraData);

            genesisHeader.Author           = beneficiary;
            genesisHeader.Hash             = Keccak.Zero; // need to run the block to know the actual hash
            genesisHeader.Bloom            = new Bloom();
            genesisHeader.GasUsed          = 0;
            genesisHeader.MixHash          = mixHash;
            genesisHeader.Nonce            = (ulong)nonce;
            genesisHeader.ReceiptsRoot     = Keccak.EmptyTreeHash;
            genesisHeader.StateRoot        = Keccak.EmptyTreeHash;
            genesisHeader.TransactionsRoot = Keccak.EmptyTreeHash;

            chainSpec.Genesis = new Block(genesisHeader);
        }
示例#2
0
        private static void LoadAllocations(GenesisFileJson genesisJson, ChainSpec chainSpec)
        {
            if (genesisJson.Alloc == null)
            {
                return;
            }

            chainSpec.Allocations = new Dictionary <Address, UInt256>();
            foreach (KeyValuePair <string, AllocationJson> account in genesisJson.Alloc)
            {
                if (account.Value.Balance != null)
                {
                    bool result = UInt256.TryParse(account.Value.Balance, out UInt256 allocationValue);
                    if (!result)
                    {
                        result = UInt256.TryParse(account.Value.Balance.Replace("0x", string.Empty), NumberStyles.HexNumber, CultureInfo.InvariantCulture, out allocationValue);
                    }

                    if (!result)
                    {
                        throw new InvalidDataException($"Cannot recognize allocation value format in {account.Value.Balance}");
                    }

                    chainSpec.Allocations[new Address(account.Key)] = allocationValue;
                }
            }
        }
示例#3
0
 private void LoadEngine(GenesisFileJson genesisJson, ChainSpec chainSpec)
 {
     if (genesisJson.Config.Clique != null)
     {
         chainSpec.SealEngineType = SealEngineType.Clique;
         chainSpec.CliquePeriod   = genesisJson.Config.Clique.Period;
         chainSpec.CliqueEpoch    = genesisJson.Config.Clique.Epoch;
         chainSpec.CliqueReward   = 0;
     }
     else
     {
         chainSpec.SealEngineType = SealEngineType.Ethash;
     }
 }