github.com/ethereum/go-ethereum@v1.16.1/tests/gen_stauthorization.go (about) 1 // Code generated by github.com/fjl/gencodec. DO NOT EDIT. 2 3 package tests 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/math" 12 ) 13 14 var _ = (*stAuthorizationMarshaling)(nil) 15 16 // MarshalJSON marshals as JSON. 17 func (s stAuthorization) MarshalJSON() ([]byte, error) { 18 type stAuthorization struct { 19 ChainID *math.HexOrDecimal256 `json:"chainId" gencodec:"required"` 20 Address common.Address `json:"address" gencodec:"required"` 21 Nonce math.HexOrDecimal64 `json:"nonce" gencodec:"required"` 22 V math.HexOrDecimal64 `json:"v" gencodec:"required"` 23 R *math.HexOrDecimal256 `json:"r" gencodec:"required"` 24 S *math.HexOrDecimal256 `json:"s" gencodec:"required"` 25 } 26 var enc stAuthorization 27 enc.ChainID = (*math.HexOrDecimal256)(s.ChainID) 28 enc.Address = s.Address 29 enc.Nonce = math.HexOrDecimal64(s.Nonce) 30 enc.V = math.HexOrDecimal64(s.V) 31 enc.R = (*math.HexOrDecimal256)(s.R) 32 enc.S = (*math.HexOrDecimal256)(s.S) 33 return json.Marshal(&enc) 34 } 35 36 // UnmarshalJSON unmarshals from JSON. 37 func (s *stAuthorization) UnmarshalJSON(input []byte) error { 38 type stAuthorization struct { 39 ChainID *math.HexOrDecimal256 `json:"chainId" gencodec:"required"` 40 Address *common.Address `json:"address" gencodec:"required"` 41 Nonce *math.HexOrDecimal64 `json:"nonce" gencodec:"required"` 42 V *math.HexOrDecimal64 `json:"v" gencodec:"required"` 43 R *math.HexOrDecimal256 `json:"r" gencodec:"required"` 44 S *math.HexOrDecimal256 `json:"s" gencodec:"required"` 45 } 46 var dec stAuthorization 47 if err := json.Unmarshal(input, &dec); err != nil { 48 return err 49 } 50 if dec.ChainID == nil { 51 return errors.New("missing required field 'chainId' for stAuthorization") 52 } 53 s.ChainID = (*big.Int)(dec.ChainID) 54 if dec.Address == nil { 55 return errors.New("missing required field 'address' for stAuthorization") 56 } 57 s.Address = *dec.Address 58 if dec.Nonce == nil { 59 return errors.New("missing required field 'nonce' for stAuthorization") 60 } 61 s.Nonce = uint64(*dec.Nonce) 62 if dec.V == nil { 63 return errors.New("missing required field 'v' for stAuthorization") 64 } 65 s.V = uint8(*dec.V) 66 if dec.R == nil { 67 return errors.New("missing required field 'r' for stAuthorization") 68 } 69 s.R = (*big.Int)(dec.R) 70 if dec.S == nil { 71 return errors.New("missing required field 's' for stAuthorization") 72 } 73 s.S = (*big.Int)(dec.S) 74 return nil 75 }