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

fix(client): fallback to default api version when node does not support discovery #113

Merged
merged 1 commit into from
Jan 26, 2024
Merged
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
17 changes: 13 additions & 4 deletions go/node/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package client
import (
"context"
"errors"
"strings"

sdkclient "github.com/cosmos/cosmos-sdk/client"
"github.com/spf13/pflag"
Expand All @@ -24,16 +25,21 @@ func DiscoverClient(ctx context.Context, cctx sdkclient.Context, flags *pflag.Fl
result := new(Akash)
params := make(map[string]interface{})
_, err = rpc.Call(ctx, "akash", params, result)
if err != nil {
if err != nil && !strings.Contains(err.Error(), "Method not found") {
return err
}

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

var cl interface{}

switch result.ClientInfo.ApiVersion {
case "v1beta2":
cl, err = v1beta2.NewClient(ctx, cctx, flags)
// case "":
default:
return ErrUnknownClientVersion
}
Expand All @@ -54,16 +60,19 @@ func DiscoverQueryClient(ctx context.Context, cctx sdkclient.Context, setup func
result := new(Akash)
params := make(map[string]interface{})
_, err = rpc.Call(ctx, "akash", params, result)
if err != nil {
if err != nil && !strings.Contains(err.Error(), "Method not found") {
return err
}

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

var cl interface{}

switch result.ClientInfo.ApiVersion {
case "v1beta2":
cl = v1beta2.NewQueryClient(cctx)
// case "":
default:
return ErrUnknownClientVersion
}
Expand Down
Loading