Skip to content

Commit

Permalink
fix(client): fallback to default api version when node does not suppo…
Browse files Browse the repository at this point in the history
…rt discovery (#113)

Signed-off-by: Artur Troian <[email protected]>
  • Loading branch information
troian authored Jan 26, 2024
1 parent 40e1584 commit 361c75d
Showing 1 changed file with 13 additions and 4 deletions.
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

0 comments on commit 361c75d

Please sign in to comment.