You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

71 lines
1.5 KiB

  1. package rpctypes
  2. import (
  3. "github.com/tendermint/tendermint/events"
  4. )
  5. type RPCRequest struct {
  6. JSONRPC string `json:"jsonrpc"`
  7. ID string `json:"id"`
  8. Method string `json:"method"`
  9. Params []interface{} `json:"params"`
  10. }
  11. func NewRPCRequest(id string, method string, params []interface{}) RPCRequest {
  12. return RPCRequest{
  13. JSONRPC: "2.0",
  14. ID: id,
  15. Method: method,
  16. Params: params,
  17. }
  18. }
  19. //----------------------------------------
  20. /*
  21. Result is a generic interface.
  22. Applications should register type-bytes like so:
  23. var _ = wire.RegisterInterface(
  24. struct{ Result }{},
  25. wire.ConcreteType{&ResultGenesis{}, ResultTypeGenesis},
  26. wire.ConcreteType{&ResultBlockchainInfo{}, ResultTypeBlockchainInfo},
  27. ...
  28. )
  29. */
  30. type Result interface {
  31. }
  32. //----------------------------------------
  33. type RPCResponse struct {
  34. JSONRPC string `json:"jsonrpc"`
  35. ID string `json:"id"`
  36. Result Result `json:"result"`
  37. Error string `json:"error"`
  38. }
  39. func NewRPCResponse(id string, res Result, err string) RPCResponse {
  40. return RPCResponse{
  41. JSONRPC: "2.0",
  42. ID: id,
  43. Result: res,
  44. Error: err,
  45. }
  46. }
  47. //----------------------------------------
  48. // *wsConnection implements this interface.
  49. type WSRPCConnection interface {
  50. GetRemoteAddr() string
  51. GetEventSwitch() *events.EventSwitch
  52. WriteRPCResponse(resp RPCResponse)
  53. TryWriteRPCResponse(resp RPCResponse) bool
  54. }
  55. // websocket-only RPCFuncs take this as the first parameter.
  56. type WSRPCContext struct {
  57. Request RPCRequest
  58. WSRPCConnection
  59. }