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