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