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

docs(node/client): documentation and interface implementation checks #139

Merged
merged 3 commits into from
Apr 12, 2024
Merged
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
23 changes: 20 additions & 3 deletions go/node/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,20 @@
ErrUnknownClientVersion = errors.New("akash-api: unknown client version")
)

const (
// DefaultClientApiVersion indicates the default ApiVersion of the client.
DefaultClientApiVersion = "v1beta2"

Check failure on line 20 in go/node/client/client.go

View workflow job for this annotation

GitHub Actions / proto

var-naming: const DefaultClientApiVersion should be DefaultClientAPIVersion (revive)
)

// SetupFn defines a function that takes a parameter, ideally a Client or QueryClient.
// These functions must validate the client and make it accessible.
type SetupFn func(interface{}) error

// DiscoverClient queries an RPC node to get the version of the client and executes a SetupFn function
// passing a new versioned Client instance as parameter.
// If any error occurs when calling the RPC node or the Cosmos SDK client Context is set to offline the default value of
// DefaultClientApiVersion will be used.
// An error is returned if client discovery is not successful.
func DiscoverClient(ctx context.Context, cctx sdkclient.Context, setup SetupFn, opts ...cltypes.ClientOption) error {
rpc, err := tmjclient.New(cctx.NodeURI)
if err != nil {
Expand All @@ -31,9 +43,9 @@
}

// if client info is nil, mostly likely "akash" endpoint is not yet supported on the node
// fallback to manually set version to v1beta2
// fallback to manually set version to DefaultClientApiVersion
if result.ClientInfo == nil || cctx.Offline {
result.ClientInfo = &ClientInfo{ApiVersion: "v1beta2"}
result.ClientInfo = &ClientInfo{ApiVersion: DefaultClientApiVersion}
}

var cl interface{}
Expand All @@ -56,6 +68,11 @@
return nil
}

// DiscoverQueryClient queries an RPC node to get the version of the client and executes a SetupFn function
// passing a new versioned QueryClient instance as parameter.
// If any error occurs when calling the RPC node or the Cosmos SDK client Context is set to offline the default value of
// DefaultClientApiVersion will be used.
// An error is returned if client discovery is not successful.
func DiscoverQueryClient(ctx context.Context, cctx sdkclient.Context, setup SetupFn) error {
rpc, err := tmjclient.New(cctx.NodeURI)
if err != nil {
Expand All @@ -70,7 +87,7 @@
}

if result.ClientInfo == nil {
result.ClientInfo = &ClientInfo{ApiVersion: "v1beta2"}
result.ClientInfo = &ClientInfo{ApiVersion: DefaultClientApiVersion}
}

var cl interface{}
Expand Down
15 changes: 15 additions & 0 deletions go/node/client/v1beta2/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ import (
ptypes "github.com/akash-network/akash-api/go/node/provider/v1beta3"
)

// QueryClient is the interface that exposes query modules.
//
//go:generate mockery --name QueryClient --output ./mocks
type QueryClient interface {
dtypes.QueryClient
Expand All @@ -54,6 +56,11 @@ type QueryClient interface {
ClientContext() sdkclient.Context
}

// TxClient is the interface that wraps the Broadcast method.
// Broadcast broadcasts a transaction. A transaction is composed of 1 or many messages. This allows several
// operations to be performed in a single transaction.
// A transaction broadcast can be configured with an arbitrary number of BroadcastOption.
//
//go:generate mockery --name TxClient --output ./mocks
type TxClient interface {
Broadcast(context.Context, []sdk.Msg, ...BroadcastOption) (interface{}, error)
Expand All @@ -64,6 +71,8 @@ type NodeClient interface {
SyncInfo(ctx context.Context) (*tmrpc.SyncInfo, error)
}

// Client is the umbrella interface that exposes every other client's modules.
//
//go:generate mockery --name Client --output ./mocks
type Client interface {
Query() QueryClient
Expand All @@ -81,6 +90,7 @@ type client struct {

var _ Client = (*client)(nil)

// NewClient creates a new client.
func NewClient(ctx context.Context, cctx sdkclient.Context, opts ...cltypes.ClientOption) (Client, error) {
nd := newNode(cctx)

Expand All @@ -98,22 +108,27 @@ func NewClient(ctx context.Context, cctx sdkclient.Context, opts ...cltypes.Clie
return cl, nil
}

// Query implements Client by returning the QueryClient instance of the client.
func (cl *client) Query() QueryClient {
return cl.qclient
}

// Tx implements Client by returning the TxClient instance of the client.
func (cl *client) Tx() TxClient {
return cl.tx
}

// Node implements Client by returning the NodeClient instance of the client.
func (cl *client) Node() NodeClient {
return cl.node
}

// ClientContext implements Client by returning the Cosmos SDK client context instance of the client.
func (cl *client) ClientContext() sdkclient.Context {
return cl.qclient.cctx
}

// PrintMessage implements Client by printing the raw message passed as parameter.
func (cl *client) PrintMessage(msg interface{}) error {
var err error

Expand Down
2 changes: 2 additions & 0 deletions go/node/client/v1beta2/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
tmrpc "github.com/tendermint/tendermint/rpc/core/types"
)

var _ NodeClient = (*node)(nil)

type node struct {
rpc rpcclient.Client
}
Expand Down
37 changes: 32 additions & 5 deletions go/node/client/v1beta2/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import (
ptypes "github.com/akash-network/akash-api/go/node/provider/v1beta3"
)

var _ QueryClient = (*queryClient)(nil)

type sdkQueryClient struct {
auth authtypes.QueryClient
authz authz.QueryClient
Expand All @@ -51,7 +53,7 @@ type queryClient struct {
cctx sdkclient.Context
}

// NewQueryClient creates new query client instance
// NewQueryClient creates new query client instance based on a Cosmos SDK client context.
func NewQueryClient(cctx sdkclient.Context) QueryClient {
return newQueryClient(cctx)
}
Expand Down Expand Up @@ -81,170 +83,195 @@ func newQueryClient(cctx sdkclient.Context) *queryClient {
}
}

// ClientContext returns the client's Cosmos SDK client context.
func (c *queryClient) ClientContext() sdkclient.Context {
return c.cctx
}

// Deployments queries deployments.
func (c *queryClient) Deployments(ctx context.Context, in *dtypes.QueryDeploymentsRequest, opts ...grpc.CallOption) (*dtypes.QueryDeploymentsResponse, error) {
if c.dclient == nil {
return &dtypes.QueryDeploymentsResponse{}, ErrClientNotFound
}
return c.dclient.Deployments(ctx, in, opts...)
}

// Deployment queries a deployment.
func (c *queryClient) Deployment(ctx context.Context, in *dtypes.QueryDeploymentRequest, opts ...grpc.CallOption) (*dtypes.QueryDeploymentResponse, error) {
if c.dclient == nil {
return &dtypes.QueryDeploymentResponse{}, ErrClientNotFound
}
return c.dclient.Deployment(ctx, in, opts...)
}

// Group queries a group.
func (c *queryClient) Group(ctx context.Context, in *dtypes.QueryGroupRequest, opts ...grpc.CallOption) (*dtypes.QueryGroupResponse, error) {
if c.dclient == nil {
return &dtypes.QueryGroupResponse{}, ErrClientNotFound
}
return c.dclient.Group(ctx, in, opts...)
}

// Orders queries orders.
func (c *queryClient) Orders(ctx context.Context, in *mtypes.QueryOrdersRequest, opts ...grpc.CallOption) (*mtypes.QueryOrdersResponse, error) {
if c.mclient == nil {
return &mtypes.QueryOrdersResponse{}, ErrClientNotFound
}
return c.mclient.Orders(ctx, in, opts...)
}

// Order queries an order.
func (c *queryClient) Order(ctx context.Context, in *mtypes.QueryOrderRequest, opts ...grpc.CallOption) (*mtypes.QueryOrderResponse, error) {
if c.mclient == nil {
return &mtypes.QueryOrderResponse{}, ErrClientNotFound
}
return c.mclient.Order(ctx, in, opts...)
}

// Bids queries bids.
func (c *queryClient) Bids(ctx context.Context, in *mtypes.QueryBidsRequest, opts ...grpc.CallOption) (*mtypes.QueryBidsResponse, error) {
if c.mclient == nil {
return &mtypes.QueryBidsResponse{}, ErrClientNotFound
}
return c.mclient.Bids(ctx, in, opts...)
}

// Bid queries a specific bid.
func (c *queryClient) Bid(ctx context.Context, in *mtypes.QueryBidRequest, opts ...grpc.CallOption) (*mtypes.QueryBidResponse, error) {
if c.mclient == nil {
return &mtypes.QueryBidResponse{}, ErrClientNotFound
}
return c.mclient.Bid(ctx, in, opts...)
}

// Leases queries leases.
func (c *queryClient) Leases(ctx context.Context, in *mtypes.QueryLeasesRequest, opts ...grpc.CallOption) (*mtypes.QueryLeasesResponse, error) {
if c.mclient == nil {
return &mtypes.QueryLeasesResponse{}, ErrClientNotFound
}
return c.mclient.Leases(ctx, in, opts...)
}

// Lease queries a lease.
func (c *queryClient) Lease(ctx context.Context, in *mtypes.QueryLeaseRequest, opts ...grpc.CallOption) (*mtypes.QueryLeaseResponse, error) {
if c.mclient == nil {
return &mtypes.QueryLeaseResponse{}, ErrClientNotFound
}
return c.mclient.Lease(ctx, in, opts...)
}

// Providers queries providers.
func (c *queryClient) Providers(ctx context.Context, in *ptypes.QueryProvidersRequest, opts ...grpc.CallOption) (*ptypes.QueryProvidersResponse, error) {
if c.pclient == nil {
return &ptypes.QueryProvidersResponse{}, ErrClientNotFound
}
return c.pclient.Providers(ctx, in, opts...)
}

// Provider queries a provider.
func (c *queryClient) Provider(ctx context.Context, in *ptypes.QueryProviderRequest, opts ...grpc.CallOption) (*ptypes.QueryProviderResponse, error) {
if c.pclient == nil {
return &ptypes.QueryProviderResponse{}, ErrClientNotFound
}
return c.pclient.Provider(ctx, in, opts...)
}

// AllProvidersAttributes queries all providers
// AllProvidersAttributes queries all providers.
func (c *queryClient) AllProvidersAttributes(ctx context.Context, in *atypes.QueryAllProvidersAttributesRequest, opts ...grpc.CallOption) (*atypes.QueryProvidersResponse, error) {
if c.pclient == nil {
return &atypes.QueryProvidersResponse{}, ErrClientNotFound
}
return c.aclient.AllProvidersAttributes(ctx, in, opts...)
}

// ProviderAttributes queries all provider signed attributes
// ProviderAttributes queries all provider signed attributes.
func (c *queryClient) ProviderAttributes(ctx context.Context, in *atypes.QueryProviderAttributesRequest, opts ...grpc.CallOption) (*atypes.QueryProvidersResponse, error) {
if c.pclient == nil {
return &atypes.QueryProvidersResponse{}, ErrClientNotFound
}
return c.aclient.ProviderAttributes(ctx, in, opts...)
}

// ProviderAuditorAttributes queries provider signed attributes by specific validator
// ProviderAuditorAttributes queries provider signed attributes by specific validator.
func (c *queryClient) ProviderAuditorAttributes(ctx context.Context, in *atypes.QueryProviderAuditorRequest, opts ...grpc.CallOption) (*atypes.QueryProvidersResponse, error) {
if c.pclient == nil {
return &atypes.QueryProvidersResponse{}, ErrClientNotFound
}
return c.aclient.ProviderAuditorAttributes(ctx, in, opts...)
}

// AuditorAttributes queries all providers signed by this validator
// AuditorAttributes queries all providers signed by this validator.
func (c *queryClient) AuditorAttributes(ctx context.Context, in *atypes.QueryAuditorAttributesRequest, opts ...grpc.CallOption) (*atypes.QueryProvidersResponse, error) {
if c.aclient == nil {
return &atypes.QueryProvidersResponse{}, ErrClientNotFound
}
return c.aclient.AuditorAttributes(ctx, in, opts...)
}

// Certificates queries certificates.
func (c *queryClient) Certificates(ctx context.Context, in *ctypes.QueryCertificatesRequest, opts ...grpc.CallOption) (*ctypes.QueryCertificatesResponse, error) {
if c.cclient == nil {
return &ctypes.QueryCertificatesResponse{}, ErrClientNotFound
}
return c.cclient.Certificates(ctx, in, opts...)
}

// Auth implements QueryClient by returning the auth Cosmos SDK query client.
func (c *queryClient) Auth() authtypes.QueryClient {
return c.sdk.auth
}

// Authz implements QueryClient by returning the authz Cosmos SDK query client.
func (c *queryClient) Authz() authz.QueryClient {
return c.sdk.authz
}

// Bank implements QueryClient by returning the bank Cosmos SDK query client.
func (c *queryClient) Bank() banktypes.QueryClient {
return c.sdk.bank
}

// Distribution implements QueryClient by returning the distribution Cosmos SDK query client.
func (c *queryClient) Distribution() disttypes.QueryClient {
return c.sdk.distr
}

// Evidence implements QueryClient by returning the evidence Cosmos SDK query client.
func (c *queryClient) Evidence() evdtypes.QueryClient {
return c.sdk.evidence
}

// Feegrant implements QueryClient by returning the feegrant Cosmos SDK query client.
func (c *queryClient) Feegrant() feegranttypes.QueryClient {
return c.sdk.feegrant
}

// Gov implements QueryClient by returning the governance Cosmos SDK query client.
func (c *queryClient) Gov() govtypes.QueryClient {
return c.sdk.gov
}

// Mint implements QueryClient by returning the mint Cosmos SDK query client.
func (c *queryClient) Mint() minttypes.QueryClient {
return c.sdk.mint
}

// Params implements QueryClient by returning the params Cosmos SDK query client.
func (c *queryClient) Params() paramtypes.QueryClient {
return c.sdk.params
}

// Slashing implements QueryClient by returning the slashing Cosmos SDK query client.
func (c *queryClient) Slashing() slashtypes.QueryClient {
return c.sdk.slashing
}

// Staking implements QueryClient by returning the staking Cosmos SDK query client.
func (c *queryClient) Staking() staketypes.QueryClient {
return c.sdk.staking
}

// Upgrade implements QueryClient by returning the upgrade Cosmos SDK query client.
func (c *queryClient) Upgrade() upgradetypes.QueryClient {
return c.sdk.upgrade
}
Loading
Loading