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.

68 lines
1.8 KiB

  1. package mock
  2. import (
  3. stdlog "log"
  4. "reflect"
  5. "github.com/tendermint/tmlibs/log"
  6. em "github.com/tendermint/tools/tm-monitor/eventmeter"
  7. "github.com/tendermint/go-amino"
  8. )
  9. type EventMeter struct {
  10. latencyCallback em.LatencyCallbackFunc
  11. disconnectCallback em.DisconnectCallbackFunc
  12. eventCallback em.EventCallbackFunc
  13. }
  14. func (e *EventMeter) Start() error { return nil }
  15. func (e *EventMeter) Stop() {}
  16. func (e *EventMeter) SetLogger(l log.Logger) {}
  17. func (e *EventMeter) RegisterLatencyCallback(cb em.LatencyCallbackFunc) { e.latencyCallback = cb }
  18. func (e *EventMeter) RegisterDisconnectCallback(cb em.DisconnectCallbackFunc) {
  19. e.disconnectCallback = cb
  20. }
  21. func (e *EventMeter) Subscribe(query string, cb em.EventCallbackFunc) error {
  22. e.eventCallback = cb
  23. return nil
  24. }
  25. func (e *EventMeter) Unsubscribe(query string) error {
  26. e.eventCallback = nil
  27. return nil
  28. }
  29. func (e *EventMeter) Call(callback string, args ...interface{}) {
  30. switch callback {
  31. case "latencyCallback":
  32. e.latencyCallback(args[0].(float64))
  33. case "disconnectCallback":
  34. e.disconnectCallback()
  35. case "eventCallback":
  36. e.eventCallback(args[0].(*em.EventMetric), args[1])
  37. }
  38. }
  39. type RpcClient struct {
  40. Stubs map[string]interface{}
  41. cdc *amino.Codec
  42. }
  43. func (c *RpcClient) Call(method string, params map[string]interface{}, result interface{}) (interface{}, error) {
  44. s, ok := c.Stubs[method]
  45. if !ok {
  46. stdlog.Fatalf("Call to %s, but no stub is defined for it", method)
  47. }
  48. rv, rt := reflect.ValueOf(result), reflect.TypeOf(result)
  49. rv, rt = rv.Elem(), rt.Elem()
  50. rv.Set(reflect.ValueOf(s))
  51. return s, nil
  52. }
  53. func (c *RpcClient) Codec() *amino.Codec {
  54. return c.cdc
  55. }
  56. func (c *RpcClient) SetCodec(cdc *amino.Codec) {
  57. c.cdc = cdc
  58. }