Exemplo n.º 1
0
        private static void LoadAllocations(ChainSpec chainSpec, ChainSpecJson chainSpecJson)
        {
            if (chainSpecJson.Accounts == null)
            {
                return;
            }

            chainSpec.Allocations = new Dictionary <Address, UInt256>();
            foreach (KeyValuePair <string, ChainSpecAccountJson> account in chainSpecJson.Accounts)
            {
                if (account.Value.Balance != null)
                {
                    chainSpec.Allocations[new Address(account.Key)] = UInt256.Parse(account.Value.Balance);
                }
            }
        }
Exemplo n.º 2
0
        private static void LoadGenesis(ChainSpecJson chainSpecJson, ChainSpec chainSpec)
        {
            if (chainSpecJson.Genesis == null)
            {
                return;
            }

            var nonce       = ToULong(chainSpecJson.Genesis.Seal.Ethereum.Nonce);
            var mixHash     = HexToKeccak(chainSpecJson.Genesis.Seal.Ethereum.MixHash);
            var parentHash  = HexToKeccak(chainSpecJson.Genesis.ParentHash);
            var timestamp   = HexToUInt256(chainSpecJson.Genesis.Timestamp);
            var difficulty  = HexToUInt256(chainSpecJson.Genesis.Difficulty);
            var extraData   = Bytes.FromHexString(chainSpecJson.Genesis.ExtraData);
            var gasLimit    = HexToLong(chainSpecJson.Genesis.GasLimit);
            var beneficiary = new Address(chainSpecJson.Genesis.Author);

            BlockHeader genesisHeader = new BlockHeader(
                parentHash,
                Keccak.OfAnEmptySequenceRlp,
                beneficiary,
                difficulty,
                0,
                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            = nonce;
            genesisHeader.ReceiptsRoot     = Keccak.EmptyTreeHash;
            genesisHeader.StateRoot        = Keccak.EmptyTreeHash;
            genesisHeader.TransactionsRoot = Keccak.EmptyTreeHash;

            chainSpec.Genesis = new Block(genesisHeader);
        }
Exemplo n.º 3
0
        private static void LoadGenesis(ChainSpecJson chainSpecJson, ChainSpec chainSpec)
        {
            if (chainSpecJson.Genesis == null)
            {
                return;
            }

            var nonce       = chainSpecJson.Genesis.Seal.Ethereum?.Nonce ?? 0;
            var mixHash     = chainSpecJson.Genesis.Seal.Ethereum?.MixHash ?? Keccak.Zero;
            var parentHash  = chainSpecJson.Genesis.ParentHash;
            var timestamp   = chainSpecJson.Genesis.Timestamp;
            var difficulty  = chainSpecJson.Genesis.Difficulty;
            var extraData   = chainSpecJson.Genesis.ExtraData;
            var gasLimit    = chainSpecJson.Genesis.GasLimit;
            var beneficiary = chainSpecJson.Genesis.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);
        }