github.com/dominant-strategies/go-quai@v0.28.2/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/dominant-strategies/go-quai/common" 11 "github.com/dominant-strategies/go-quai/common/hexutil" 12 "github.com/dominant-strategies/go-quai/common/math" 13 "github.com/dominant-strategies/go-quai/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 } 35 var enc Genesis 36 enc.Config = g.Config 37 enc.Nonce = math.HexOrDecimal64(g.Nonce) 38 enc.Timestamp = math.HexOrDecimal64(g.Timestamp) 39 enc.ExtraData = g.ExtraData 40 enc.Mixhash = g.Mixhash 41 enc.Coinbase = g.Coinbase 42 enc.Number = make([]math.HexOrDecimal64, common.HierarchyDepth) 43 enc.ParentHash = make([]common.Hash, common.HierarchyDepth) 44 for i := 0; i < common.HierarchyDepth; i++ { 45 enc.Number[i] = math.HexOrDecimal64(g.Number[i]) 46 enc.ParentHash[i] = g.ParentHash[i] 47 } 48 enc.GasLimit = math.HexOrDecimal64(g.GasLimit) 49 enc.GasUsed = math.HexOrDecimal64(g.GasUsed) 50 enc.BaseFee = (*math.HexOrDecimal256)(g.BaseFee) 51 enc.Difficulty = (*math.HexOrDecimal256)(g.Difficulty) 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 BaseFee *math.HexOrDecimal256 `json:"baseFeePerGas"` 71 } 72 var dec Genesis 73 if err := json.Unmarshal(input, &dec); err != nil { 74 return err 75 } 76 if dec.Config != nil { 77 g.Config = dec.Config 78 } 79 if dec.Nonce != nil { 80 g.Nonce = uint64(*dec.Nonce) 81 } 82 if dec.Timestamp != nil { 83 g.Timestamp = uint64(*dec.Timestamp) 84 } 85 if dec.ExtraData != nil { 86 g.ExtraData = *dec.ExtraData 87 } 88 if dec.Mixhash != nil { 89 g.Mixhash = *dec.Mixhash 90 } 91 if dec.Alloc == nil { 92 return errors.New("missing required field 'alloc' for Genesis") 93 } 94 if dec.GasLimit == nil { 95 return errors.New("missing required field 'gasLimit' for Genesis") 96 } 97 g.GasLimit = uint64(*dec.GasLimit) 98 if dec.GasUsed != nil { 99 g.GasUsed = uint64(*dec.GasUsed) 100 } 101 if dec.Difficulty == nil { 102 return errors.New("missing required field 'difficulty' for Genesis") 103 } 104 g.Difficulty = (*big.Int)(dec.Difficulty) 105 if dec.BaseFee != nil { 106 g.BaseFee = (*big.Int)(dec.BaseFee) 107 } 108 if dec.Coinbase != nil { 109 g.Coinbase = *dec.Coinbase 110 } 111 for i := 0; i < common.HierarchyDepth; i++ { 112 if dec.Number[i] != nil { 113 g.Number[i] = uint64(*dec.Number[i]) 114 } 115 if dec.ParentHash[i] != nil { 116 g.ParentHash[i] = *dec.ParentHash[i] 117 } 118 } 119 return nil 120 }