github.com/klaytn/klaytn@v1.10.2/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/klaytn/klaytn/common/hexutil" 10 "github.com/klaytn/klaytn/common/math" 11 ) 12 13 var _ = (*stTransactionMarshaling)(nil) 14 15 // MarshalJSON marshals as JSON. 16 func (s stTransaction) MarshalJSON() ([]byte, error) { 17 type stTransaction struct { 18 GasPrice *math.HexOrDecimal256 `json:"gasPrice"` 19 Nonce math.HexOrDecimal64 `json:"nonce"` 20 To string `json:"to"` 21 Data []string `json:"data"` 22 GasLimit []math.HexOrDecimal64 `json:"gasLimit"` 23 Value []string `json:"value"` 24 PrivateKey hexutil.Bytes `json:"secretKey"` 25 } 26 var enc stTransaction 27 enc.GasPrice = (*math.HexOrDecimal256)(s.GasPrice) 28 enc.Nonce = math.HexOrDecimal64(s.Nonce) 29 enc.To = s.To 30 enc.Data = s.Data 31 if s.GasLimit != nil { 32 enc.GasLimit = make([]math.HexOrDecimal64, len(s.GasLimit)) 33 for k, v := range s.GasLimit { 34 enc.GasLimit[k] = math.HexOrDecimal64(v) 35 } 36 } 37 enc.Value = s.Value 38 enc.PrivateKey = s.PrivateKey 39 return json.Marshal(&enc) 40 } 41 42 // UnmarshalJSON unmarshals from JSON. 43 func (s *stTransaction) UnmarshalJSON(input []byte) error { 44 type stTransaction struct { 45 GasPrice *math.HexOrDecimal256 `json:"gasPrice"` 46 Nonce *math.HexOrDecimal64 `json:"nonce"` 47 To *string `json:"to"` 48 Data []string `json:"data"` 49 GasLimit []math.HexOrDecimal64 `json:"gasLimit"` 50 Value []string `json:"value"` 51 PrivateKey *hexutil.Bytes `json:"secretKey"` 52 } 53 var dec stTransaction 54 if err := json.Unmarshal(input, &dec); err != nil { 55 return err 56 } 57 if dec.GasPrice != nil { 58 s.GasPrice = (*big.Int)(dec.GasPrice) 59 } 60 if dec.Nonce != nil { 61 s.Nonce = uint64(*dec.Nonce) 62 } 63 if dec.To != nil { 64 s.To = *dec.To 65 } 66 if dec.Data != nil { 67 s.Data = dec.Data 68 } 69 if dec.GasLimit != nil { 70 s.GasLimit = make([]uint64, len(dec.GasLimit)) 71 for k, v := range dec.GasLimit { 72 s.GasLimit[k] = uint64(v) 73 } 74 } 75 if dec.Value != nil { 76 s.Value = dec.Value 77 } 78 if dec.PrivateKey != nil { 79 s.PrivateKey = *dec.PrivateKey 80 } 81 return nil 82 }