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