github.com/alanchchen/go-ethereum@v1.6.6-0.20170601190819-6171d01b1195/core/gen_genesis_account.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/ethereum/go-ethereum/common" 11 "github.com/ethereum/go-ethereum/common/hexutil" 12 "github.com/ethereum/go-ethereum/common/math" 13 ) 14 15 func (g GenesisAccount) MarshalJSON() ([]byte, error) { 16 type GenesisAccount struct { 17 Code hexutil.Bytes `json:"code,omitempty"` 18 Storage map[common.Hash]common.Hash `json:"storage,omitempty"` 19 Balance *math.HexOrDecimal256 `json:"balance" gencodec:"required"` 20 Nonce math.HexOrDecimal64 `json:"nonce,omitempty"` 21 } 22 var enc GenesisAccount 23 enc.Code = g.Code 24 enc.Storage = g.Storage 25 enc.Balance = (*math.HexOrDecimal256)(g.Balance) 26 enc.Nonce = math.HexOrDecimal64(g.Nonce) 27 return json.Marshal(&enc) 28 } 29 30 func (g *GenesisAccount) UnmarshalJSON(input []byte) error { 31 type GenesisAccount struct { 32 Code hexutil.Bytes `json:"code,omitempty"` 33 Storage map[common.Hash]common.Hash `json:"storage,omitempty"` 34 Balance *math.HexOrDecimal256 `json:"balance" gencodec:"required"` 35 Nonce *math.HexOrDecimal64 `json:"nonce,omitempty"` 36 } 37 var dec GenesisAccount 38 if err := json.Unmarshal(input, &dec); err != nil { 39 return err 40 } 41 if dec.Code != nil { 42 g.Code = dec.Code 43 } 44 if dec.Storage != nil { 45 g.Storage = dec.Storage 46 } 47 if dec.Balance == nil { 48 return errors.New("missing required field 'balance' for GenesisAccount") 49 } 50 g.Balance = (*big.Int)(dec.Balance) 51 if dec.Nonce != nil { 52 g.Nonce = uint64(*dec.Nonce) 53 } 54 return nil 55 }