github.com/devfans/go-ethereum@v1.5.10-0.20170326212234-7419d0c38291/core/gen_genesis.go (about) 1 // 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 func (g *Genesis) MarshalJSON() ([]byte, error) { 17 type GenesisJSON struct { 18 ChainConfig *params.ChainConfig `json:"config" optional:"true"` 19 Nonce *math.HexOrDecimal64 `json:"nonce" optional:"true"` 20 Timestamp *math.HexOrDecimal64 `json:"timestamp" optional:"true"` 21 ParentHash *common.Hash `json:"parentHash" optional:"true"` 22 ExtraData hexutil.Bytes `json:"extraData" optional:"true"` 23 GasLimit *math.HexOrDecimal64 `json:"gasLimit"` 24 Difficulty *math.HexOrDecimal256 `json:"difficulty"` 25 Mixhash *common.Hash `json:"mixHash" optional:"true"` 26 Coinbase *common.Address `json:"coinbase" optional:"true"` 27 Alloc map[common.UnprefixedAddress]GenesisAccount `json:"alloc"` 28 } 29 var enc GenesisJSON 30 enc.ChainConfig = g.Config 31 enc.Nonce = (*math.HexOrDecimal64)(&g.Nonce) 32 enc.Timestamp = (*math.HexOrDecimal64)(&g.Timestamp) 33 enc.ParentHash = &g.ParentHash 34 if g.ExtraData != nil { 35 enc.ExtraData = g.ExtraData 36 } 37 enc.GasLimit = (*math.HexOrDecimal64)(&g.GasLimit) 38 enc.Difficulty = (*math.HexOrDecimal256)(g.Difficulty) 39 enc.Mixhash = &g.Mixhash 40 enc.Coinbase = &g.Coinbase 41 if g.Alloc != nil { 42 enc.Alloc = make(map[common.UnprefixedAddress]GenesisAccount, len(g.Alloc)) 43 for k, v := range g.Alloc { 44 enc.Alloc[common.UnprefixedAddress(k)] = v 45 } 46 } 47 return json.Marshal(&enc) 48 } 49 50 func (g *Genesis) UnmarshalJSON(input []byte) error { 51 type GenesisJSON struct { 52 ChainConfig *params.ChainConfig `json:"config" optional:"true"` 53 Nonce *math.HexOrDecimal64 `json:"nonce" optional:"true"` 54 Timestamp *math.HexOrDecimal64 `json:"timestamp" optional:"true"` 55 ParentHash *common.Hash `json:"parentHash" optional:"true"` 56 ExtraData hexutil.Bytes `json:"extraData" optional:"true"` 57 GasLimit *math.HexOrDecimal64 `json:"gasLimit"` 58 Difficulty *math.HexOrDecimal256 `json:"difficulty"` 59 Mixhash *common.Hash `json:"mixHash" optional:"true"` 60 Coinbase *common.Address `json:"coinbase" optional:"true"` 61 Alloc map[common.UnprefixedAddress]GenesisAccount `json:"alloc"` 62 } 63 var dec GenesisJSON 64 if err := json.Unmarshal(input, &dec); err != nil { 65 return err 66 } 67 var x Genesis 68 if dec.ChainConfig != nil { 69 x.Config = dec.ChainConfig 70 } 71 if dec.Nonce != nil { 72 x.Nonce = uint64(*dec.Nonce) 73 } 74 if dec.Timestamp != nil { 75 x.Timestamp = uint64(*dec.Timestamp) 76 } 77 if dec.ParentHash != nil { 78 x.ParentHash = *dec.ParentHash 79 } 80 if dec.ExtraData != nil { 81 x.ExtraData = dec.ExtraData 82 } 83 if dec.GasLimit == nil { 84 return errors.New("missing required field 'gasLimit' for Genesis") 85 } 86 x.GasLimit = uint64(*dec.GasLimit) 87 if dec.Difficulty == nil { 88 return errors.New("missing required field 'difficulty' for Genesis") 89 } 90 x.Difficulty = (*big.Int)(dec.Difficulty) 91 if dec.Mixhash != nil { 92 x.Mixhash = *dec.Mixhash 93 } 94 if dec.Coinbase != nil { 95 x.Coinbase = *dec.Coinbase 96 } 97 if dec.Alloc == nil { 98 return errors.New("missing required field 'alloc' for Genesis") 99 } 100 x.Alloc = make(GenesisAlloc, len(dec.Alloc)) 101 for k, v := range dec.Alloc { 102 x.Alloc[common.Address(k)] = v 103 } 104 *g = x 105 return nil 106 }