Skip to content

Commit

Permalink
[Code Health] refactor: block query client interface (#616)
Browse files Browse the repository at this point in the history
  • Loading branch information
bryanchriswhite authored Jun 24, 2024
1 parent f21253c commit 60fda01
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 6 deletions.
7 changes: 6 additions & 1 deletion pkg/appgateserver/sdkadapter/block_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/client/block/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -34,7 +33,8 @@ const (
// the interface.
//
// Required dependencies:
// - client.EventsQueryClient
// - client.EventsQueryClient
// - client.BlockQueryClient
func NewBlockClient(
ctx context.Context,
deps depinject.Config,
Expand Down Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions pkg/client/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
}
2 changes: 1 addition & 1 deletion pkg/client/query/sessionquerier.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}

Expand Down

0 comments on commit 60fda01

Please sign in to comment.