github.com/intfoundation/intchain@v0.0.0-20220727031208-4316ad31ca73/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/intfoundation/intchain/common" 11 "github.com/intfoundation/intchain/common/hexutil" 12 "github.com/intfoundation/intchain/common/math" 13 ) 14 15 var _ = (*genesisAccountMarshaling)(nil) 16 17 func (g GenesisAccount) MarshalJSON() ([]byte, error) { 18 type GenesisAccount struct { 19 Code hexutil.Bytes `json:"code,omitempty"` 20 Storage map[storageJSON]storageJSON `json:"storage,omitempty"` 21 Balance *math.HexOrDecimal256 `json:"balance" gencodec:"required"` 22 Nonce math.HexOrDecimal64 `json:"nonce,omitempty"` 23 Amount *math.HexOrDecimal256 `json:"amount,omitempty"` 24 25 DelegateBalance *math.HexOrDecimal256 `json:"delegate,omitempty"` 26 DepositProxiedDetail map[common.Address]*math.HexOrDecimal256 `json:"proxiedList,omitempty"` 27 Candidate bool `json:"candidate,omitempty"` 28 Commission uint8 `json:"commission,omitempty"` 29 30 PrivateKey hexutil.Bytes `json:"secretKey,omitempty"` 31 } 32 var enc GenesisAccount 33 enc.Code = g.Code 34 if g.Storage != nil { 35 enc.Storage = make(map[storageJSON]storageJSON, len(g.Storage)) 36 for k, v := range g.Storage { 37 enc.Storage[storageJSON(k)] = storageJSON(v) 38 } 39 } 40 enc.Balance = (*math.HexOrDecimal256)(g.Balance) 41 enc.Nonce = math.HexOrDecimal64(g.Nonce) 42 enc.Amount = (*math.HexOrDecimal256)(g.Amount) 43 44 if g.DelegateBalance != nil { 45 enc.DelegateBalance = (*math.HexOrDecimal256)(g.DelegateBalance) 46 } 47 if g.DepositProxiedDetail != nil { 48 enc.DepositProxiedDetail = make(map[common.Address]*math.HexOrDecimal256, len(g.DepositProxiedDetail)) 49 for k, v := range g.DepositProxiedDetail { 50 enc.DepositProxiedDetail[k] = (*math.HexOrDecimal256)(v) 51 } 52 } 53 enc.Candidate = g.Candidate 54 enc.Commission = g.Commission 55 56 enc.PrivateKey = g.PrivateKey 57 return json.Marshal(&enc) 58 } 59 60 func (g *GenesisAccount) UnmarshalJSON(input []byte) error { 61 type GenesisAccount struct { 62 Code *hexutil.Bytes `json:"code,omitempty"` 63 Storage map[storageJSON]storageJSON `json:"storage,omitempty"` 64 Balance *math.HexOrDecimal256 `json:"balance" gencodec:"required"` 65 Nonce *math.HexOrDecimal64 `json:"nonce,omitempty"` 66 Amount *math.HexOrDecimal256 `json:"amount,omitempty"` 67 68 // Delegate 69 DelegateBalance *math.HexOrDecimal256 `json:"delegate,omitempty"` 70 DepositProxiedDetail map[common.Address]*math.HexOrDecimal256 `json:"proxiedList,omitempty"` 71 Candidate bool `json:"candidate,omitempty"` 72 Commission uint8 `json:"commission,omitempty"` 73 74 PrivateKey *hexutil.Bytes `json:"secretKey,omitempty"` 75 } 76 var dec GenesisAccount 77 if err := json.Unmarshal(input, &dec); err != nil { 78 return err 79 } 80 if dec.Code != nil { 81 g.Code = *dec.Code 82 } 83 if dec.Storage != nil { 84 g.Storage = make(map[common.Hash]common.Hash, len(dec.Storage)) 85 for k, v := range dec.Storage { 86 g.Storage[common.Hash(k)] = common.Hash(v) 87 } 88 } 89 if dec.Balance == nil { 90 return errors.New("missing required field 'balance' for GenesisAccount") 91 } 92 g.Balance = (*big.Int)(dec.Balance) 93 if dec.Nonce != nil { 94 g.Nonce = uint64(*dec.Nonce) 95 } 96 if dec.Amount != nil { 97 g.Amount = (*big.Int)(dec.Amount) 98 } 99 if dec.DelegateBalance != nil { 100 g.DelegateBalance = (*big.Int)(dec.DelegateBalance) 101 } 102 if dec.DepositProxiedDetail != nil { 103 g.DepositProxiedDetail = make(map[common.Address]*big.Int, len(dec.DepositProxiedDetail)) 104 for k, v := range dec.DepositProxiedDetail { 105 g.DepositProxiedDetail[k] = (*big.Int)(v) 106 } 107 } 108 g.Candidate = dec.Candidate 109 g.Commission = dec.Commission 110 111 if dec.PrivateKey != nil { 112 g.PrivateKey = *dec.PrivateKey 113 } 114 return nil 115 }