From 60fda016c15237e041ef29b20940e0edba304065 Mon Sep 17 00:00:00 2001 From: Bryan White Date: Mon, 24 Jun 2024 11:51:41 +0200 Subject: [PATCH] [Code Health] refactor: block query client interface (#616) --- pkg/appgateserver/sdkadapter/block_client.go | 7 ++++++- pkg/client/block/client.go | 8 ++++---- pkg/client/interface.go | 8 ++++++++ pkg/client/query/sessionquerier.go | 2 +- 4 files changed, 19 insertions(+), 6 deletions(-) diff --git a/pkg/appgateserver/sdkadapter/block_client.go b/pkg/appgateserver/sdkadapter/block_client.go index cc74ccdc4..dc5aa5039 100644 --- a/pkg/appgateserver/sdkadapter/block_client.go +++ b/pkg/appgateserver/sdkadapter/block_client.go @@ -19,13 +19,18 @@ type sdkBlockClient struct { // NewBlockClient creates a new ShannonSDK compatible block client. // It is a wrapper around the client.BlockClient and implements the sdk.BlockClient // interface. +// +// Required dependencies: +// - shannonsdk.BlockClient func NewBlockClient( ctx context.Context, deps depinject.Config, ) (sdk.BlockClient, error) { blockClient := &sdkBlockClient{} - depinject.Inject(deps, &blockClient.client) + if err := depinject.Inject(deps, &blockClient.client); err != nil { + return nil, err + } return blockClient, nil } diff --git a/pkg/client/block/client.go b/pkg/client/block/client.go index 07ab0df44..b76ecbac2 100644 --- a/pkg/client/block/client.go +++ b/pkg/client/block/client.go @@ -4,7 +4,6 @@ import ( "context" "cosmossdk.io/depinject" - cometclient "github.com/cosmos/cosmos-sdk/client" "github.com/pokt-network/poktroll/pkg/client" "github.com/pokt-network/poktroll/pkg/client/events" @@ -34,7 +33,8 @@ const ( // the interface. // // Required dependencies: -// - client.EventsQueryClient +// - client.EventsQueryClient +// - client.BlockQueryClient func NewBlockClient( ctx context.Context, deps depinject.Config, @@ -81,14 +81,14 @@ func NewBlockClient( } // blockReplayClient is BlockClient implementation that combines a CometRPC client -// to get the its first block at start up and an EventsReplayClient that subscribes +// to get the initial block at start up and an EventsReplayClient that subscribes // to new committed block events. // It uses a ReplayObservable to retain and replay past observed blocks. type blockReplayClient struct { // onStartQueryClient is the RPC client that is used to query for the initial block // upon blockReplayClient construction. The result of this query is only used if it // returns before the eventsReplayClient receives its first event. - onStartQueryClient cometclient.CometRPC + onStartQueryClient client.BlockQueryClient // eventsReplayClient is the underlying EventsReplayClient that is used to // subscribe to new committed block events. It uses both the Block type diff --git a/pkg/client/interface.go b/pkg/client/interface.go index 0b0dfd4a0..56aa8dcd7 100644 --- a/pkg/client/interface.go +++ b/pkg/client/interface.go @@ -19,6 +19,7 @@ import ( "context" cometrpctypes "github.com/cometbft/cometbft/rpc/core/types" + coretypes "github.com/cometbft/cometbft/rpc/core/types" comettypes "github.com/cometbft/cometbft/types" cosmosclient "github.com/cosmos/cosmos-sdk/client" cosmoskeyring "github.com/cosmos/cosmos-sdk/crypto/keyring" @@ -297,3 +298,10 @@ type SharedQueryClient interface { // the session that includes queryHeight opens. GetProofWindowOpenHeight(ctx context.Context, queryHeight int64) (int64, error) } + +// BlockQueryClient defines an interface that enables the querying of +// on-chain block information for a given height. If height is nil, the +// latest block is returned. +type BlockQueryClient interface { + Block(ctx context.Context, height *int64) (*coretypes.ResultBlock, error) +} diff --git a/pkg/client/query/sessionquerier.go b/pkg/client/query/sessionquerier.go index a08d49f16..091bf6de0 100644 --- a/pkg/client/query/sessionquerier.go +++ b/pkg/client/query/sessionquerier.go @@ -25,7 +25,7 @@ type sessionQuerier struct { // injecting the dependecies provided by the depinject.Config. // // Required dependencies: -// - clientCtx +// - clientCtx (grpc.ClientConn) func NewSessionQuerier(deps depinject.Config) (client.SessionQueryClient, error) { sessq := &sessionQuerier{}