Ejemplo n.º 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.TxRoot       = Keccak.EmptyTreeHash;

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

            chainSpec.Allocations = new Dictionary <Address, (UInt256 Balance, byte[] Code)>();
            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}");
                    }

                    // todo: handle code like in chainspec
                    chainSpec.Allocations[new Address(account.Key)] = (allocationValue, null);
                }
            }
        }
Ejemplo n.º 3
0
 private void LoadEngine(GenesisFileJson genesisJson, ChainSpec chainSpec)
 {
     if (genesisJson.Config.Clique != null)
     {
         chainSpec.SealEngineType = SealEngineType.Clique;
         chainSpec.Clique         = new CliqueParameters();
         chainSpec.Clique.Period  = genesisJson.Config.Clique.Period;
         chainSpec.Clique.Epoch   = genesisJson.Config.Clique.Epoch;
         chainSpec.Clique.Reward  = 0;
     }
     else
     {
         chainSpec.SealEngineType = SealEngineType.Ethash;
     }
 }
Ejemplo n.º 4
0
        private static void LoadAllocations(GenesisFileJson genesisJson, ChainSpec chainSpec)
        {
            if (genesisJson.Alloc == null)
            {
                return;
            }

            chainSpec.Allocations = new Dictionary <Address, ChainSpecAllocation>();
            foreach ((string addressString, AllocationJson allocation) in genesisJson.Alloc)
            {
                if (allocation.BuiltIn != null)
                {
                    continue;
                }

                chainSpec.Allocations[new Address(addressString)] = new ChainSpecAllocation(allocation.Balance);
            }
        }