github.com/ccm-chain/ccmchain@v1.0.0/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/ccm-chain/ccmchain/common" 11 "github.com/ccm-chain/ccmchain/common/hexutil" 12 "github.com/ccm-chain/ccmchain/common/math" 13 "github.com/ccm-chain/ccmchain/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 Nonce math.HexOrDecimal64 `json:"nonce"` 23 Timestamp math.HexOrDecimal64 `json:"timestamp"` 24 ExtraData hexutil.Bytes `json:"extraData"` 25 GasLimit math.HexOrDecimal64 `json:"gasLimit" gencodec:"required"` 26 Difficulty *math.HexOrDecimal256 `json:"difficulty" gencodec:"required"` 27 Mixhash common.Hash `json:"mixHash"` 28 Coinbase common.Address `json:"coinbase"` 29 Alloc map[common.UnprefixedAddress]GenesisAccount `json:"alloc" gencodec:"required"` 30 Number math.HexOrDecimal64 `json:"number"` 31 GasUsed math.HexOrDecimal64 `json:"gasUsed"` 32 ParentHash common.Hash `json:"parentHash"` 33 } 34 var enc Genesis 35 enc.Config = g.Config 36 enc.Nonce = math.HexOrDecimal64(g.Nonce) 37 enc.Timestamp = math.HexOrDecimal64(g.Timestamp) 38 enc.ExtraData = g.ExtraData 39 enc.GasLimit = math.HexOrDecimal64(g.GasLimit) 40 enc.Difficulty = (*math.HexOrDecimal256)(g.Difficulty) 41 enc.Mixhash = g.Mixhash 42 enc.Coinbase = g.Coinbase 43 if g.Alloc != nil { 44 enc.Alloc = make(map[common.UnprefixedAddress]GenesisAccount, len(g.Alloc)) 45 for k, v := range g.Alloc { 46 enc.Alloc[common.UnprefixedAddress(k)] = v 47 } 48 } 49 enc.Number = math.HexOrDecimal64(g.Number) 50 enc.GasUsed = math.HexOrDecimal64(g.GasUsed) 51 enc.ParentHash = g.ParentHash 52 return json.Marshal(&enc) 53 } 54 55 // UnmarshalJSON unmarshals from JSON. 56 func (g *Genesis) UnmarshalJSON(input []byte) error { 57 type Genesis struct { 58 Config *params.ChainConfig `json:"config"` 59 Nonce *math.HexOrDecimal64 `json:"nonce"` 60 Timestamp *math.HexOrDecimal64 `json:"timestamp"` 61 ExtraData *hexutil.Bytes `json:"extraData"` 62 GasLimit *math.HexOrDecimal64 `json:"gasLimit" gencodec:"required"` 63 Difficulty *math.HexOrDecimal256 `json:"difficulty" gencodec:"required"` 64 Mixhash *common.Hash `json:"mixHash"` 65 Coinbase *common.Address `json:"coinbase"` 66 Alloc map[common.UnprefixedAddress]GenesisAccount `json:"alloc" gencodec:"required"` 67 Number *math.HexOrDecimal64 `json:"number"` 68 GasUsed *math.HexOrDecimal64 `json:"gasUsed"` 69 ParentHash *common.Hash `json:"parentHash"` 70 } 71 var dec Genesis 72 if err := json.Unmarshal(input, &dec); err != nil { 73 return err 74 } 75 if dec.Config != nil { 76 g.Config = dec.Config 77 } 78 if dec.Nonce != nil { 79 g.Nonce = uint64(*dec.Nonce) 80 } 81 if dec.Timestamp != nil { 82 g.Timestamp = uint64(*dec.Timestamp) 83 } 84 if dec.ExtraData != nil { 85 g.ExtraData = *dec.ExtraData 86 } 87 if dec.GasLimit == nil { 88 return errors.New("missing required field 'gasLimit' for Genesis") 89 } 90 g.GasLimit = uint64(*dec.GasLimit) 91 if dec.Difficulty == nil { 92 return errors.New("missing required field 'difficulty' for Genesis") 93 } 94 g.Difficulty = (*big.Int)(dec.Difficulty) 95 if dec.Mixhash != nil { 96 g.Mixhash = *dec.Mixhash 97 } 98 if dec.Coinbase != nil { 99 g.Coinbase = *dec.Coinbase 100 } 101 if dec.Alloc == nil { 102 return errors.New("missing required field 'alloc' for Genesis") 103 } 104 g.Alloc = make(GenesisAlloc, len(dec.Alloc)) 105 for k, v := range dec.Alloc { 106 g.Alloc[common.Address(k)] = v 107 } 108 if dec.Number != nil { 109 g.Number = uint64(*dec.Number) 110 } 111 if dec.GasUsed != nil { 112 g.GasUsed = uint64(*dec.GasUsed) 113 } 114 if dec.ParentHash != nil { 115 g.ParentHash = *dec.ParentHash 116 } 117 return nil 118 }