types: rename and extend the EventData interface (#7687)

This is the interface shared by types that can be used as event data in, for
example, subscriptions via the RPC.

To be compatible with the RPC service, data need to support JSON encoding.
Require this as part of the interface.
This commit is contained in:
M. J. Fromberger
2022-01-26 07:01:55 -08:00
committed by GitHub
parent fcfe157f6b
commit 441ecbaeec
9 changed files with 70 additions and 63 deletions
+1 -1
View File
@@ -59,7 +59,7 @@ func WaitForHeight(ctx context.Context, c StatusClient, h int64, waiter Waiter)
// when the timeout duration has expired.
//
// This handles subscribing and unsubscribing under the hood
func WaitForOneEvent(c EventsClient, eventValue string, timeout time.Duration) (types.TMEventData, error) {
func WaitForOneEvent(c EventsClient, eventValue string, timeout time.Duration) (types.EventData, error) {
const subscriber = "helpers"
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()
+2 -7
View File
@@ -3,7 +3,6 @@ package coretypes
import (
"encoding/json"
"errors"
"fmt"
"time"
abci "github.com/tendermint/tendermint/abci/types"
@@ -307,7 +306,7 @@ type (
type ResultEvent struct {
SubscriptionID string
Query string
Data types.TMEventData
Data types.EventData
Events []abci.Event
}
@@ -319,11 +318,7 @@ type resultEventJSON struct {
}
func (r ResultEvent) MarshalJSON() ([]byte, error) {
data, ok := r.Data.(jsontypes.Tagged)
if !ok {
return nil, fmt.Errorf("type %T is not tagged", r.Data)
}
evt, err := jsontypes.Marshal(data)
evt, err := jsontypes.Marshal(r.Data)
if err != nil {
return nil, err
}