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