diff --git a/pkg/client/interface.go b/pkg/client/interface.go index f2aa1dd40..620a77af0 100644 --- a/pkg/client/interface.go +++ b/pkg/client/interface.go @@ -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 @@ -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) } diff --git a/pkg/client/query/supplierquerier.go b/pkg/client/query/supplierquerier.go index 040a4303f..e1c4c1424 100644 --- a/pkg/client/query/supplierquerier.go +++ b/pkg/client/query/supplierquerier.go @@ -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 } @@ -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]", diff --git a/x/supplier/types/query_client.go b/x/supplier/types/query_client.go new file mode 100644 index 000000000..a26c712f3 --- /dev/null +++ b/x/supplier/types/query_client.go @@ -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 ¶ms, nil +}