gen_sttransaction.go 2.1 KB

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