messages.go 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /*
  2. This file is part of go-ethereum
  3. go-ethereum is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 3 of the License, or
  6. (at your option) any later version.
  7. go-ethereum is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
  13. */
  14. package rpc
  15. import (
  16. "encoding/json"
  17. "fmt"
  18. )
  19. type InsufficientParamsError struct {
  20. have int
  21. want int
  22. }
  23. func (e *InsufficientParamsError) Error() string {
  24. return fmt.Sprintf("insufficient params, want %d have %d", e.want, e.have)
  25. }
  26. func NewInsufficientParamsError(have int, want int) *InsufficientParamsError {
  27. return &InsufficientParamsError{
  28. have: have,
  29. want: want,
  30. }
  31. }
  32. type NotImplementedError struct {
  33. Method string
  34. }
  35. func (e *NotImplementedError) Error() string {
  36. return fmt.Sprintf("%s method not implemented", e.Method)
  37. }
  38. func NewNotImplementedError(method string) *NotImplementedError {
  39. return &NotImplementedError{
  40. Method: method,
  41. }
  42. }
  43. type DecodeParamError struct {
  44. err string
  45. }
  46. func (e *DecodeParamError) Error() string {
  47. return fmt.Sprintf("could not decode, %s", e.err)
  48. }
  49. func NewDecodeParamError(errstr string) error {
  50. return &DecodeParamError{
  51. err: errstr,
  52. }
  53. }
  54. type ValidationError struct {
  55. ParamName string
  56. msg string
  57. }
  58. func (e *ValidationError) Error() string {
  59. return fmt.Sprintf("%s not valid, %s", e.ParamName, e.msg)
  60. }
  61. func NewValidationError(param string, msg string) error {
  62. return &ValidationError{
  63. ParamName: param,
  64. msg: msg,
  65. }
  66. }
  67. type RpcRequest struct {
  68. ID interface{} `json:"id"`
  69. JsonRpc string `json:"jsonrpc"`
  70. Method string `json:"method"`
  71. Params json.RawMessage `json:"params"`
  72. }
  73. type RpcSuccessResponse struct {
  74. ID interface{} `json:"id"`
  75. JsonRpc string `json:"jsonrpc"`
  76. Result interface{} `json:"result"`
  77. }
  78. type RpcErrorResponse struct {
  79. ID interface{} `json:"id"`
  80. JsonRpc string `json:"jsonrpc"`
  81. Error *RpcErrorObject `json:"error"`
  82. }
  83. type RpcErrorObject struct {
  84. Code int `json:"code"`
  85. Message string `json:"message"`
  86. // Data interface{} `json:"data"`
  87. }