github.com/dogestan/eth@v1.9.7/core/gen_genesis.go (about) 1 // Code generated by github.com/fjl/gencodec. DO NOT EDIT. 2 3 package core 4 5 import ( 6 "encoding/json" 7 "errors" 8 "math/big" 9 10 "github.com/ethereum/go-ethereum/common" 11 "github.com/ethereum/go-ethereum/common/hexutil" 12 "github.com/ethereum/go-ethereum/common/math" 13 "github.com/ethereum/go-ethereum/params" 14 ) 15 16 var _ = (*genesisSpecMarshaling)(nil) 17 18 func (g Genesis) MarshalJSON() ([]byte, error) { 19 type Genesis struct { 20 Config *params.ChainConfig `json:"config"` 21 Nonce math.HexOrDecimal64 `json:"nonce"` 22 Timestamp math.HexOrDecimal64 `json:"timestamp"` 23 ExtraData hexutil.Bytes `json:"extraData"` 24 GasLimit math.HexOrDecimal64 `json:"gasLimit" gencodec:"required"` 25 Difficulty *math.HexOrDecimal256 `json:"difficulty" gencodec:"required"` 26 Mixhash common.Hash `json:"mixHash"` 27 Coinbase common.Address `json:"coinbase"` 28 Alloc map[common.UnprefixedAddress]GenesisAccount `json:"alloc" gencodec:"required"` 29 Number math.HexOrDecimal64 `json:"number"` 30 GasUsed math.HexOrDecimal64 `json:"gasUsed"` 31 ParentHash common.Hash `json:"parentHash"` 32 } 33 var enc Genesis 34 enc.Config = g.Config 35 enc.Nonce = math.HexOrDecimal64(g.Nonce) 36 enc.Timestamp = math.HexOrDecimal64(g.Timestamp) 37 enc.ExtraData = g.ExtraData 38 enc.GasLimit = math.HexOrDecimal64(g.GasLimit) 39 enc.Difficulty = (*math.HexOrDecimal256)(g.Difficulty) 40 enc.Mixhash = g.Mixhash 41 enc.Coinbase = g.Coinbase 42 if g.Alloc != nil { 43 enc.Alloc = make(map[common.UnprefixedAddress]GenesisAccount, len(g.Alloc)) 44 for k, v := range g.Alloc { 45 enc.Alloc[common.UnprefixedAddress(k)] = v 46 } 47 } 48 enc.Number = math.HexOrDecimal64(g.Number) 49 enc.GasUsed = math.HexOrDecimal64(g.GasUsed) 50 enc.ParentHash = g.ParentHash 51 return json.Marshal(&enc) 52 } 53 54 func (g *Genesis) UnmarshalJSON(input []byte) error { 55 type Genesis struct { 56 Config *params.ChainConfig `json:"config"` 57 Nonce *math.HexOrDecimal64 `json:"nonce"` 58 Timestamp *math.HexOrDecimal64 `json:"timestamp"` 59 ExtraData *hexutil.Bytes `json:"extraData"` 60 GasLimit *math.HexOrDecimal64 `json:"gasLimit" gencodec:"required"` 61 Difficulty *math.HexOrDecimal256 `json:"difficulty" gencodec:"required"` 62 Mixhash *common.Hash `json:"mixHash"` 63 Coinbase *common.Address `json:"coinbase"` 64 Alloc map[common.UnprefixedAddress]GenesisAccount `json:"alloc" gencodec:"required"` 65 Number *math.HexOrDecimal64 `json:"number"` 66 GasUsed *math.HexOrDecimal64 `json:"gasUsed"` 67 ParentHash *common.Hash `json:"parentHash"` 68 } 69 var dec Genesis 70 if err := json.Unmarshal(input, &dec); err != nil { 71 return err 72 } 73 if dec.Config != nil { 74 g.Config = dec.Config 75 } 76 if dec.Nonce != nil { 77 g.Nonce = uint64(*dec.Nonce) 78 } 79 if dec.Timestamp != nil { 80 g.Timestamp = uint64(*dec.Timestamp) 81 } 82 if dec.ExtraData != nil { 83 g.ExtraData = *dec.ExtraData 84 } 85 if dec.GasLimit == nil { 86 return errors.New("missing required field 'gasLimit' for Genesis") 87 } 88 g.GasLimit = uint64(*dec.GasLimit) 89 if dec.Difficulty == nil { 90 return errors.New("missing required field 'difficulty' for Genesis") 91 } 92 g.Difficulty = (*big.Int)(dec.Difficulty) 93 if dec.Mixhash != nil { 94 g.Mixhash = *dec.Mixhash 95 } 96 if dec.Coinbase != nil { 97 g.Coinbase = *dec.Coinbase 98 } 99 if dec.Alloc == nil { 100 return errors.New("missing required field 'alloc' for Genesis") 101 } 102 g.Alloc = make(GenesisAlloc, len(dec.Alloc)) 103 for k, v := range dec.Alloc { 104 g.Alloc[common.Address(k)] = v 105 } 106 if dec.Number != nil { 107 g.Number = uint64(*dec.Number) 108 } 109 if dec.GasUsed != nil { 110 g.GasUsed = uint64(*dec.GasUsed) 111 } 112 if dec.ParentHash != nil { 113 g.ParentHash = *dec.ParentHash 114 } 115 return nil 116 }