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