mirror of
https://github.com/tendermint/tendermint.git
synced 2026-09-25 17:34:36 +00:00
rpc/client: add Events method to the client interface (#7982)
- Update documentation to deprecate the old methods. - Add Events methods to HTTP, WS, and Local clients. - Add Events method to the light client wrapper. - Rename legacy events client to SubscriptionClient.
This commit is contained in:
@@ -340,6 +340,14 @@ func (c *baseRPCClient) ConsensusParams(
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (c *baseRPCClient) Events(ctx context.Context, req *coretypes.RequestEvents) (*coretypes.ResultEvents, error) {
|
||||
result := new(coretypes.ResultEvents)
|
||||
if err := c.caller.Call(ctx, "events", req, result); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (c *baseRPCClient) Health(ctx context.Context) (*coretypes.ResultHealth, error) {
|
||||
result := new(coretypes.ResultHealth)
|
||||
if err := c.caller.Call(ctx, "health", nil, result); err != nil {
|
||||
|
||||
@@ -15,7 +15,7 @@ import (
|
||||
jsonrpcclient "github.com/tendermint/tendermint/rpc/jsonrpc/client"
|
||||
)
|
||||
|
||||
// wsEvents is a wrapper around WSClient, which implements EventsClient.
|
||||
// wsEvents is a wrapper around WSClient, which implements SubscriptionClient.
|
||||
type wsEvents struct {
|
||||
Logger log.Logger
|
||||
ws *jsonrpcclient.WSClient
|
||||
@@ -30,7 +30,7 @@ type wsSubscription struct {
|
||||
query string
|
||||
}
|
||||
|
||||
var _ rpcclient.EventsClient = (*wsEvents)(nil)
|
||||
var _ rpcclient.SubscriptionClient = (*wsEvents)(nil)
|
||||
|
||||
func newWsEvents(remote string) (*wsEvents, error) {
|
||||
w := &wsEvents{
|
||||
@@ -64,7 +64,7 @@ func (w *wsEvents) Start(ctx context.Context) error {
|
||||
// Stop shuts down the websocket client.
|
||||
func (w *wsEvents) Stop() error { return w.ws.Stop() }
|
||||
|
||||
// Subscribe implements EventsClient by using WSClient to subscribe given
|
||||
// Subscribe implements SubscriptionClient by using WSClient to subscribe given
|
||||
// subscriber to query. By default, it returns a channel with cap=1. Error is
|
||||
// returned if it fails to subscribe.
|
||||
//
|
||||
@@ -97,8 +97,8 @@ func (w *wsEvents) Subscribe(ctx context.Context, subscriber, query string,
|
||||
return outc, nil
|
||||
}
|
||||
|
||||
// Unsubscribe implements EventsClient by using WSClient to unsubscribe given
|
||||
// subscriber from query.
|
||||
// Unsubscribe implements SubscriptionClient by using WSClient to unsubscribe
|
||||
// given subscriber from query.
|
||||
//
|
||||
// It returns an error if wsEvents is not running.
|
||||
func (w *wsEvents) Unsubscribe(ctx context.Context, subscriber, query string) error {
|
||||
@@ -119,8 +119,8 @@ func (w *wsEvents) Unsubscribe(ctx context.Context, subscriber, query string) er
|
||||
return nil
|
||||
}
|
||||
|
||||
// UnsubscribeAll implements EventsClient by using WSClient to unsubscribe
|
||||
// given subscriber from all the queries.
|
||||
// UnsubscribeAll implements SubscriptionClient by using WSClient to
|
||||
// unsubscribe given subscriber from all the queries.
|
||||
//
|
||||
// It returns an error if wsEvents is not running.
|
||||
func (w *wsEvents) UnsubscribeAll(ctx context.Context, subscriber string) error {
|
||||
|
||||
Reference in New Issue
Block a user