From 361c75d91fc8ae43c588c1c7ea6135f845df766f Mon Sep 17 00:00:00 2001 From: Artur Troian Date: Fri, 26 Jan 2024 12:35:52 -0500 Subject: [PATCH] fix(client): fallback to default api version when node does not support discovery (#113) Signed-off-by: Artur Troian --- go/node/client/client.go | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/go/node/client/client.go b/go/node/client/client.go index 1f776b38..96d5576c 100644 --- a/go/node/client/client.go +++ b/go/node/client/client.go @@ -3,6 +3,7 @@ package client import ( "context" "errors" + "strings" sdkclient "github.com/cosmos/cosmos-sdk/client" "github.com/spf13/pflag" @@ -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 } @@ -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 }