Skip to content

Commit

Permalink
Merge remote-tracking branch 'pokt/main' into merge/block-client_x_retry
Browse files Browse the repository at this point in the history
* pokt/main:
  refactor: add `either.Bytes` alias (#117)
  feat: add either.AsyncErr type & helpers (#115)
  • Loading branch information
bryanchriswhite committed Oct 31, 2023
2 parents ea63e00 + fd0db1d commit 7b3a93a
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 9 deletions.
10 changes: 5 additions & 5 deletions pkg/client/events_query/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ type eventsQueryClient struct {
// corresponding connection which produces its inputs.
type eventsBytesAndConn struct {
// eventsBytes is an observable which is notified about chain event messages
// matching the given query. It receives an either.Either[[]byte] which is
// matching the given query. It receives an either.Bytes which is
// either an error or the event message bytes.
eventsBytes observable.Observable[either.Either[[]byte]]
eventsBytes observable.Observable[either.Bytes]
conn client.Connection
isClosed bool
}
Expand Down Expand Up @@ -81,7 +81,7 @@ func NewEventsQueryClient(cometWebsocketURL string, opts ...client.EventsQueryCl
}

// EventsBytes returns an eventsBytes observable which is notified about chain
// event messages matching the given query. It receives an either.Either[[]byte]
// event messages matching the given query. It receives an either.Bytes
// which is either an error or the event message bytes.
// (see: https://pkg.go.dev/github.com/cometbft/cometbft/types#pkg-constants)
// (see: https://docs.cosmos.network/v0.47/core/events#subscribing-to-events)
Expand Down Expand Up @@ -151,7 +151,7 @@ func (eqc *eventsQueryClient) newEventsBytesAndConn(
}

// Construct an eventsBytes for the given query.
eventsBzObservable, eventsBzPublishCh := channel.NewObservable[either.Either[[]byte]]()
eventsBzObservable, eventsBzPublishCh := channel.NewObservable[either.Bytes]()

// Publish either events bytes or an error received from the connection to
// the eventsBz observable.
Expand Down Expand Up @@ -198,7 +198,7 @@ func (eqc *eventsQueryClient) openEventsBytesAndConn(
func (eqc *eventsQueryClient) goPublishEventsBz(
ctx context.Context,
conn client.Connection,
eventsBzPublishCh chan<- either.Either[[]byte],
eventsBzPublishCh chan<- either.Bytes,
) {
// Read and handle messages from the websocket. This loop will exit when the
// websocket connection is isClosed and/or returns an error.
Expand Down
4 changes: 2 additions & 2 deletions pkg/client/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ type Block interface {
// value which contains either an error or the event message bytes.
// TODO_HACK: The purpose of this type is to work around gomock's lack of
// support for generic types. For the same reason, this type cannot be an
// alias (i.e. EventsBytesObservable = observable.Observable[either.Either[[]byte]]).
type EventsBytesObservable observable.Observable[either.Either[[]byte]]
// alias (i.e. EventsBytesObservable = observable.Observable[either.Bytes]).
type EventsBytesObservable observable.Observable[either.Bytes]

// EventsQueryClient is used to subscribe to chain event messages matching the given query,
type EventsQueryClient interface {
Expand Down
2 changes: 1 addition & 1 deletion pkg/either/errors.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package either

// SyncErr creates an AsyncError either from a synchronous error.
// It wraps the Error into the left field (conventionally associated with the
// It wraps the Error into the left field (conventionally associated with the
// error value in the Either pattern) of the Either type. It casts the result
// to the AsyncError type.
func SyncErr(err error) AsyncError {
Expand Down
5 changes: 4 additions & 1 deletion pkg/either/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,7 @@ package either
// AsyncError represents a value which could either be a synchronous error or
// an asynchronous error (sent through a channel). It wraps the more generic
// `Either` type specific for error channels.
type AsyncError Either[chan error]
type (
AsyncError Either[chan error]
Bytes = Either[[]byte]
)

0 comments on commit 7b3a93a

Please sign in to comment.