args.go 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. // Copyright 2015 The go-ethereum Authors
  2. // This file is part of the go-ethereum library.
  3. //
  4. // The go-ethereum library is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU Lesser General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // The go-ethereum library is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU Lesser General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU Lesser General Public License
  15. // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
  16. package api
  17. import (
  18. "encoding/json"
  19. "github.com/ethereum/go-ethereum/rpc/shared"
  20. )
  21. type CompileArgs struct {
  22. Source string
  23. }
  24. func (args *CompileArgs) UnmarshalJSON(b []byte) (err error) {
  25. var obj []interface{}
  26. if err := json.Unmarshal(b, &obj); err != nil {
  27. return shared.NewDecodeParamError(err.Error())
  28. }
  29. if len(obj) < 1 {
  30. return shared.NewInsufficientParamsError(len(obj), 1)
  31. }
  32. argstr, ok := obj[0].(string)
  33. if !ok {
  34. return shared.NewInvalidTypeError("arg0", "is not a string")
  35. }
  36. args.Source = argstr
  37. return nil
  38. }
  39. type FilterStringArgs struct {
  40. Word string
  41. }
  42. func (args *FilterStringArgs) UnmarshalJSON(b []byte) (err error) {
  43. var obj []interface{}
  44. if err := json.Unmarshal(b, &obj); err != nil {
  45. return shared.NewDecodeParamError(err.Error())
  46. }
  47. if len(obj) < 1 {
  48. return shared.NewInsufficientParamsError(len(obj), 1)
  49. }
  50. var argstr string
  51. argstr, ok := obj[0].(string)
  52. if !ok {
  53. return shared.NewInvalidTypeError("filter", "not a string")
  54. }
  55. switch argstr {
  56. case "latest", "pending":
  57. break
  58. default:
  59. return shared.NewValidationError("Word", "Must be `latest` or `pending`")
  60. }
  61. args.Word = argstr
  62. return nil
  63. }