github.phpd.cn/morph-l2/go-ethereum@v1.9.7/tests/gen_sttransaction.go (about) 1 // Code generated by github.com/fjl/gencodec. DO NOT EDIT. 2 3 package tests 4 5 import ( 6 "encoding/json" 7 "math/big" 8 9 "github.com/ethereum/go-ethereum/common/hexutil" 10 "github.com/ethereum/go-ethereum/common/math" 11 ) 12 13 var _ = (*stTransactionMarshaling)(nil) 14 15 func (s stTransaction) MarshalJSON() ([]byte, error) { 16 type stTransaction struct { 17 GasPrice *math.HexOrDecimal256 `json:"gasPrice"` 18 Nonce math.HexOrDecimal64 `json:"nonce"` 19 To string `json:"to"` 20 Data []string `json:"data"` 21 GasLimit []math.HexOrDecimal64 `json:"gasLimit"` 22 Value []string `json:"value"` 23 PrivateKey hexutil.Bytes `json:"secretKey"` 24 } 25 var enc stTransaction 26 enc.GasPrice = (*math.HexOrDecimal256)(s.GasPrice) 27 enc.Nonce = math.HexOrDecimal64(s.Nonce) 28 enc.To = s.To 29 enc.Data = s.Data 30 if s.GasLimit != nil { 31 enc.GasLimit = make([]math.HexOrDecimal64, len(s.GasLimit)) 32 for k, v := range s.GasLimit { 33 enc.GasLimit[k] = math.HexOrDecimal64(v) 34 } 35 } 36 enc.Value = s.Value 37 enc.PrivateKey = s.PrivateKey 38 return json.Marshal(&enc) 39 } 40 41 func (s *stTransaction) UnmarshalJSON(input []byte) error { 42 type stTransaction struct { 43 GasPrice *math.HexOrDecimal256 `json:"gasPrice"` 44 Nonce *math.HexOrDecimal64 `json:"nonce"` 45 To *string `json:"to"` 46 Data []string `json:"data"` 47 GasLimit []math.HexOrDecimal64 `json:"gasLimit"` 48 Value []string `json:"value"` 49 PrivateKey *hexutil.Bytes `json:"secretKey"` 50 } 51 var dec stTransaction 52 if err := json.Unmarshal(input, &dec); err != nil { 53 return err 54 } 55 if dec.GasPrice != nil { 56 s.GasPrice = (*big.Int)(dec.GasPrice) 57 } 58 if dec.Nonce != nil { 59 s.Nonce = uint64(*dec.Nonce) 60 } 61 if dec.To != nil { 62 s.To = *dec.To 63 } 64 if dec.Data != nil { 65 s.Data = dec.Data 66 } 67 if dec.GasLimit != nil { 68 s.GasLimit = make([]uint64, len(dec.GasLimit)) 69 for k, v := range dec.GasLimit { 70 s.GasLimit[k] = uint64(v) 71 } 72 } 73 if dec.Value != nil { 74 s.Value = dec.Value 75 } 76 if dec.PrivateKey != nil { 77 s.PrivateKey = *dec.PrivateKey 78 } 79 return nil 80 }