github.com/devfans/go-ethereum@v1.5.10-0.20170326212234-7419d0c38291/core/gen_genesis_account.go (about) 1 // 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 GenesisAccountJSON struct { 17 Code hexutil.Bytes `json:"code" optional:"true"` 18 Storage map[common.Hash]common.Hash `json:"storage" optional:"true"` 19 Balance *math.HexOrDecimal256 `json:"balance"` 20 Nonce *math.HexOrDecimal64 `json:"nonce" optional:"true"` 21 } 22 var enc GenesisAccountJSON 23 if g.Code != nil { 24 enc.Code = g.Code 25 } 26 if g.Storage != nil { 27 enc.Storage = g.Storage 28 } 29 enc.Balance = (*math.HexOrDecimal256)(g.Balance) 30 enc.Nonce = (*math.HexOrDecimal64)(&g.Nonce) 31 return json.Marshal(&enc) 32 } 33 34 func (g *GenesisAccount) UnmarshalJSON(input []byte) error { 35 type GenesisAccountJSON struct { 36 Code hexutil.Bytes `json:"code" optional:"true"` 37 Storage map[common.Hash]common.Hash `json:"storage" optional:"true"` 38 Balance *math.HexOrDecimal256 `json:"balance"` 39 Nonce *math.HexOrDecimal64 `json:"nonce" optional:"true"` 40 } 41 var dec GenesisAccountJSON 42 if err := json.Unmarshal(input, &dec); err != nil { 43 return err 44 } 45 var x GenesisAccount 46 if dec.Code != nil { 47 x.Code = dec.Code 48 } 49 if dec.Storage != nil { 50 x.Storage = dec.Storage 51 } 52 if dec.Balance == nil { 53 return errors.New("missing required field 'balance' for GenesisAccount") 54 } 55 x.Balance = (*big.Int)(dec.Balance) 56 if dec.Nonce != nil { 57 x.Nonce = uint64(*dec.Nonce) 58 } 59 *g = x 60 return nil 61 }