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