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