Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Clients] embed ParamsQuerier into ApplicationQueryClient #996

Draft
wants to merge 1 commit into
base: issues/543/params-querier/shared
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions pkg/client/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,8 @@ type AccountQueryClient interface {
// ApplicationQueryClient defines an interface that enables the querying of the
// on-chain application information
type ApplicationQueryClient interface {
ParamsQuerier[*apptypes.Params]

// GetApplication queries the chain for the details of the application provided
GetApplication(ctx context.Context, appAddress string) (apptypes.Application, error)

Expand Down
34 changes: 28 additions & 6 deletions pkg/client/query/appquerier.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import (
"context"

"cosmossdk.io/depinject"
grpc "github.com/cosmos/gogoproto/grpc"
gogogrpc "github.com/cosmos/gogoproto/grpc"

"github.com/pokt-network/poktroll/pkg/client"
apptypes "github.com/pokt-network/poktroll/x/application/types"
sharedtypes "github.com/pokt-network/poktroll/x/shared/types"
)

var _ client.ApplicationQueryClient = (*appQuerier)(nil)
Expand All @@ -16,19 +17,40 @@ var _ client.ApplicationQueryClient = (*appQuerier)(nil)
// querying of on-chain application information through a single exposed method
// which returns an apptypes.Application interface
type appQuerier struct {
clientConn grpc.ClientConn
client.ParamsQuerier[*apptypes.Params]

clientConn gogogrpc.ClientConn
applicationQuerier apptypes.QueryClient
}

// NewApplicationQuerier returns a new instance of a client.ApplicationQueryClient
// by injecting the dependecies provided by the depinject.Config
//
// Required dependencies:
// - clientCtx
func NewApplicationQuerier(deps depinject.Config) (client.ApplicationQueryClient, error) {
aq := &appQuerier{}
// - clientCtx (gogogrpc.ClientConn)
func NewApplicationQuerier(
deps depinject.Config,
opts ...ParamsQuerierOptionFn,
) (client.ApplicationQueryClient, error) {
cfg := DefaultParamsQuerierConfig()
for _, opt := range opts {
opt(cfg)
}

paramsQuerier, err := NewCachedParamsQuerier[*apptypes.Params, apptypes.ApplicationQueryClient](
deps, apptypes.NewAppQueryClient,
WithModuleInfo(sharedtypes.ModuleName, sharedtypes.ErrSharedParamInvalid),
WithQueryCacheOptions(cfg.CacheOpts...),
)
if err != nil {
return nil, err
}

aq := &appQuerier{
ParamsQuerier: paramsQuerier,
}

if err := depinject.Inject(
if err = depinject.Inject(
deps,
&aq.clientConn,
); err != nil {
Expand Down
4 changes: 4 additions & 0 deletions x/application/types/expected_keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,7 @@ type SharedKeeper interface {
GetParams(ctx context.Context) sharedtypes.Params
GetSessionEndHeight(ctx context.Context, queryHeight int64) int64
}

type ApplicationKeeper interface {
GetParams(ctx context.Context) Params
}
31 changes: 31 additions & 0 deletions x/application/types/query_client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package types

import (
"context"

gogogrpc "github.com/cosmos/gogoproto/grpc"
)

// TODO_IN_THIS_COMMIT: godoc...
type ApplicationQueryClient interface {
QueryClient

GetParams(context.Context) (*Params, error)
}

// TODO_IN_THIS_COMMIT: godoc...
func NewAppQueryClient(conn gogogrpc.ClientConn) ApplicationQueryClient {
return NewQueryClient(conn).(ApplicationQueryClient)
}

// TODO_IN_THIS_COMMIT: investigate generalization...
// TODO_IN_THIS_COMMIT: godoc...
func (c *queryClient) GetParams(ctx context.Context) (*Params, error) {
res, err := c.Params(ctx, &QueryParamsRequest{})
if err != nil {
return nil, err
}

params := res.GetParams()
return &params, nil
}
10 changes: 9 additions & 1 deletion x/proof/types/application_query_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/pokt-network/poktroll/pkg/client"
apptypes "github.com/pokt-network/poktroll/x/application/types"
sharedkeeper "github.com/pokt-network/poktroll/x/shared/keeper"
)

var _ client.ApplicationQueryClient = (*AppKeeperQueryClient)(nil)
Expand All @@ -13,6 +14,8 @@ var _ client.ApplicationQueryClient = (*AppKeeperQueryClient)(nil)
// It does not rely on the QueryClient, and therefore does not make any
// network requests as in the off-chain implementation.
type AppKeeperQueryClient struct {
client.ParamsQuerier[*apptypes.Params]

keeper ApplicationKeeper
}

Expand All @@ -22,7 +25,12 @@ type AppKeeperQueryClient struct {
// has delegated its signing power to.
// It should be injected into the RingClient when initialized from within the a keeper.
func NewAppKeeperQueryClient(appKeeper ApplicationKeeper) client.ApplicationQueryClient {
return &AppKeeperQueryClient{keeper: appKeeper}
keeperParamsQuerier := sharedkeeper.NewKeeperParamsQuerier[apptypes.Params](appKeeper)

return &AppKeeperQueryClient{
keeper: appKeeper,
ParamsQuerier: keeperParamsQuerier,
}
}

// GetApplication returns the application corresponding to the given address.
Expand Down
1 change: 1 addition & 0 deletions x/proof/types/expected_keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ type ApplicationKeeper interface {
GetApplication(ctx context.Context, address string) (app apptypes.Application, found bool)
GetAllApplications(ctx context.Context) []apptypes.Application
SetApplication(context.Context, apptypes.Application)
GetParams(context.Context) apptypes.Params
}

// SharedKeeper defines the expected interface needed to retrieve shared information.
Expand Down
1 change: 1 addition & 0 deletions x/tokenomics/types/expected_keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ type ApplicationKeeper interface {
GetAllApplications(ctx context.Context) []apptypes.Application
UnbondApplication(ctx context.Context, app *apptypes.Application) error
EndBlockerUnbondApplications(ctx context.Context) error
GetParams(ctx context.Context) apptypes.Params
}

type ProofKeeper interface {
Expand Down
Loading