github.com/theQRL/go-zond@v0.1.1/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/theQRL/go-zond/common" 11 "github.com/theQRL/go-zond/common/hexutil" 12 "github.com/theQRL/go-zond/common/math" 13 ) 14 15 var _ = (*genesisAccountMarshaling)(nil) 16 17 // MarshalJSON marshals as JSON. 18 func (g GenesisAccount) MarshalJSON() ([]byte, error) { 19 type GenesisAccount struct { 20 Code hexutil.Bytes `json:"code,omitempty"` 21 Storage map[storageJSON]storageJSON `json:"storage,omitempty"` 22 Balance *math.HexOrDecimal256 `json:"balance" gencodec:"required"` 23 Nonce math.HexOrDecimal64 `json:"nonce,omitempty"` 24 PrivateKey hexutil.Bytes `json:"secretKey,omitempty"` 25 } 26 var enc GenesisAccount 27 enc.Code = g.Code 28 if g.Storage != nil { 29 enc.Storage = make(map[storageJSON]storageJSON, len(g.Storage)) 30 for k, v := range g.Storage { 31 enc.Storage[storageJSON(k)] = storageJSON(v) 32 } 33 } 34 enc.Balance = (*math.HexOrDecimal256)(g.Balance) 35 enc.Nonce = math.HexOrDecimal64(g.Nonce) 36 enc.PrivateKey = g.PrivateKey 37 return json.Marshal(&enc) 38 } 39 40 // UnmarshalJSON unmarshals from JSON. 41 func (g *GenesisAccount) UnmarshalJSON(input []byte) error { 42 type GenesisAccount struct { 43 Code *hexutil.Bytes `json:"code,omitempty"` 44 Storage map[storageJSON]storageJSON `json:"storage,omitempty"` 45 Balance *math.HexOrDecimal256 `json:"balance" gencodec:"required"` 46 Nonce *math.HexOrDecimal64 `json:"nonce,omitempty"` 47 PrivateKey *hexutil.Bytes `json:"secretKey,omitempty"` 48 } 49 var dec GenesisAccount 50 if err := json.Unmarshal(input, &dec); err != nil { 51 return err 52 } 53 if dec.Code != nil { 54 g.Code = *dec.Code 55 } 56 if dec.Storage != nil { 57 g.Storage = make(map[common.Hash]common.Hash, len(dec.Storage)) 58 for k, v := range dec.Storage { 59 g.Storage[common.Hash(k)] = common.Hash(v) 60 } 61 } 62 if dec.Balance == nil { 63 return errors.New("missing required field 'balance' for GenesisAccount") 64 } 65 g.Balance = (*big.Int)(dec.Balance) 66 if dec.Nonce != nil { 67 g.Nonce = uint64(*dec.Nonce) 68 } 69 if dec.PrivateKey != nil { 70 g.PrivateKey = *dec.PrivateKey 71 } 72 return nil 73 }