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 SupplierQueryClient #1001

Draft
wants to merge 1 commit into
base: issues/543/params-querier/session
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
3 changes: 3 additions & 0 deletions pkg/client/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
servicetypes "github.com/pokt-network/poktroll/x/service/types"
sessiontypes "github.com/pokt-network/poktroll/x/session/types"
sharedtypes "github.com/pokt-network/poktroll/x/shared/types"
suppliertypes "github.com/pokt-network/poktroll/x/supplier/types"
)

// MsgCreateClaim is an interface satisfying proof.MsgCreateClaim concrete type
Expand Down Expand Up @@ -280,6 +281,8 @@ type ApplicationQueryClient interface {
// SupplierQueryClient defines an interface that enables the querying of the
// on-chain supplier information
type SupplierQueryClient interface {
ParamsQuerier[*suppliertypes.Params]

// GetSupplier queries the chain for the details of the supplier provided
GetSupplier(ctx context.Context, supplierOperatorAddress string) (sharedtypes.Supplier, error)
}
Expand Down
39 changes: 31 additions & 8 deletions pkg/client/query/supplierquerier.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,14 @@ import (
suppliertypes "github.com/pokt-network/poktroll/x/supplier/types"
)

var _ client.SupplierQueryClient = (*supplierQuerier)(nil)

// supplierQuerier is a wrapper around the suppliertypes.QueryClient that enables the
// querying of on-chain supplier information through a single exposed method
// which returns an sharedtypes.Supplier struct
type supplierQuerier struct {
client.ParamsQuerier[*suppliertypes.Params]

clientConn grpc.ClientConn
supplierQuerier suppliertypes.QueryClient
}
Expand All @@ -24,28 +28,47 @@ type supplierQuerier struct {
//
// Required dependencies:
// - grpc.ClientConn
func NewSupplierQuerier(deps depinject.Config) (client.SupplierQueryClient, error) {
supq := &supplierQuerier{}
func NewSupplierQuerier(
deps depinject.Config,
paramsQuerierOpts ...ParamsQuerierOptionFn,
) (client.SupplierQueryClient, error) {
paramsQuerierCfg := DefaultParamsQuerierConfig()
for _, opt := range paramsQuerierOpts {
opt(paramsQuerierCfg)
}

paramsQuerier, err := NewCachedParamsQuerier[*suppliertypes.Params, suppliertypes.SupplierQueryClient](
deps, suppliertypes.NewSupplierQueryClient,
WithModuleInfo[*suppliertypes.Params](suppliertypes.ModuleName, suppliertypes.ErrSupplierParamInvalid),
WithParamsCacheOptions(paramsQuerierCfg.CacheOpts...),
)
if err != nil {
return nil, err
}

sq := &supplierQuerier{
ParamsQuerier: paramsQuerier,
}

if err := depinject.Inject(
if err = depinject.Inject(
deps,
&supq.clientConn,
&sq.clientConn,
); err != nil {
return nil, err
}

supq.supplierQuerier = suppliertypes.NewQueryClient(supq.clientConn)
sq.supplierQuerier = suppliertypes.NewQueryClient(sq.clientConn)

return supq, nil
return sq, nil
}

// GetSupplier returns an suppliertypes.Supplier struct for a given address
func (supq *supplierQuerier) GetSupplier(
func (sq *supplierQuerier) GetSupplier(
ctx context.Context,
operatorAddress string,
) (sharedtypes.Supplier, error) {
req := &suppliertypes.QueryGetSupplierRequest{OperatorAddress: operatorAddress}
res, err := supq.supplierQuerier.Supplier(ctx, req)
res, err := sq.supplierQuerier.Supplier(ctx, req)
if err != nil {
return sharedtypes.Supplier{}, suppliertypes.ErrSupplierNotFound.Wrapf(
"address: %s [%v]",
Expand Down
31 changes: 31 additions & 0 deletions x/supplier/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 SupplierQueryClient interface {
QueryClient

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

// TODO_IN_THIS_COMMIT: godoc...
func NewSupplierQueryClient(conn gogogrpc.ClientConn) SupplierQueryClient {
return NewQueryClient(conn).(SupplierQueryClient)
}

// 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
}
Loading