From ee5583b81ef2a4b9910854a0f641a81d25d996ea Mon Sep 17 00:00:00 2001 From: Artur Troian Date: Wed, 6 Mar 2024 12:21:51 -0500 Subject: [PATCH] feat(client): implement client opts Signed-off-by: Artur Troian --- client/client.go | 12 ++++--- go.mod | 2 +- go.sum | 4 +-- x/audit/client/cli/tx.go | 15 ++++++-- x/cert/client/cli/tx.go | 15 ++++++-- x/cert/client/cli/tx_test.go | 4 ++- x/deployment/client/cli/tx.go | 64 ++++++++++++++++++++++++++++++----- x/market/client/cli/tx.go | 36 +++++++++++++++++--- x/provider/client/cli/tx.go | 15 ++++++-- 9 files changed, 138 insertions(+), 29 deletions(-) diff --git a/client/client.go b/client/client.go index cb76be38b4..19032bb79a 100644 --- a/client/client.go +++ b/client/client.go @@ -6,13 +6,12 @@ import ( "fmt" "reflect" - "github.com/spf13/pflag" - sdkclient "github.com/cosmos/cosmos-sdk/client" cmtrpctypes "github.com/tendermint/tendermint/rpc/jsonrpc/types" aclient "github.com/akash-network/akash-api/go/node/client" + cltypes "github.com/akash-network/akash-api/go/node/client/types" "github.com/akash-network/akash-api/go/node/client/v1beta2" ) @@ -39,9 +38,10 @@ func DiscoverQueryClient(ctx context.Context, cctx sdkclient.Context) (v1beta2.Q return cl, nil } -func DiscoverClient(ctx context.Context, cctx sdkclient.Context, flags *pflag.FlagSet) (v1beta2.Client, error) { +func DiscoverClient(ctx context.Context, cctx sdkclient.Context, opts ...cltypes.ClientOption) (v1beta2.Client, error) { var cl v1beta2.Client - err := aclient.DiscoverClient(ctx, cctx, flags, func(i interface{}) error { + + setupFn := func(i interface{}) error { var valid bool if cl, valid = i.(v1beta2.Client); !valid { @@ -49,7 +49,9 @@ func DiscoverClient(ctx context.Context, cctx sdkclient.Context, flags *pflag.Fl } return nil - }) + } + + err := aclient.DiscoverClient(ctx, cctx, setupFn, opts...) if err != nil { return nil, err diff --git a/go.mod b/go.mod index 646a3856a1..9e9bb0d396 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/akash-network/node go 1.21 require ( - github.com/akash-network/akash-api v0.0.51 + github.com/akash-network/akash-api v0.0.56 github.com/blang/semver/v4 v4.0.0 github.com/boz/go-lifecycle v0.1.1 github.com/cosmos/cosmos-sdk v0.45.16 diff --git a/go.sum b/go.sum index 37aa4298ce..b996ea1c3b 100644 --- a/go.sum +++ b/go.sum @@ -98,8 +98,8 @@ github.com/aead/siphash v1.0.1/go.mod h1:Nywa3cDsYNNK3gaciGTWPwHt0wlpNV15vwmswBA github.com/afex/hystrix-go v0.0.0-20180502004556-fa1af6a1f4f5/go.mod h1:SkGFH1ia65gfNATL8TAiHDNxPzPdmEL5uirI2Uyuz6c= github.com/ajg/form v1.5.1/go.mod h1:uL1WgH+h2mgNtvBq0339dVnzXdBETtL2LeUXaIv25UY= github.com/ajstarks/svgo v0.0.0-20180226025133-644b8db467af/go.mod h1:K08gAheRH3/J6wwsYMMT4xOr94bZjxIelGM0+d/wbFw= -github.com/akash-network/akash-api v0.0.51 h1:HGborV1y9RWeQESX2JU15iwX87zFrb2rDHVv51tg7I4= -github.com/akash-network/akash-api v0.0.51/go.mod h1:pNr61L4+0sheol7ZK0HjgK3rxpIAbYBGq1w1oH4B0+M= +github.com/akash-network/akash-api v0.0.56 h1:dUiDR7DXeMXgh9xyxCik4gznTsjSJhi8Pq3iPcZoqSc= +github.com/akash-network/akash-api v0.0.56/go.mod h1:pNr61L4+0sheol7ZK0HjgK3rxpIAbYBGq1w1oH4B0+M= github.com/akash-network/cometbft v0.34.27-akash h1:V1dApDOr8Ee7BJzYyQ7Z9VBtrAul4+baMeA6C49dje0= github.com/akash-network/cometbft v0.34.27-akash/go.mod h1:BcCbhKv7ieM0KEddnYXvQZR+pZykTKReJJYf7YC7qhw= github.com/akash-network/ledger-go v0.14.3 h1:LCEFkTfgGA2xFMN2CtiKvXKE7dh0QSM77PJHCpSkaAo= diff --git a/x/audit/client/cli/tx.go b/x/audit/client/cli/tx.go index 6dea0faedf..9fbdb243c7 100644 --- a/x/audit/client/cli/tx.go +++ b/x/audit/client/cli/tx.go @@ -4,6 +4,7 @@ import ( "fmt" "sort" + cltypes "github.com/akash-network/akash-api/go/node/client/types" "github.com/spf13/cobra" sdkclient "github.com/cosmos/cosmos-sdk/client" @@ -65,7 +66,12 @@ func cmdCreateProviderAttributes() *cobra.Command { return err } - cl, err := aclient.DiscoverClient(ctx, cctx, cmd.Flags()) + opts, err := cltypes.ClientOptionsFromFlags(cmd.Flags()) + if err != nil { + return err + } + + cl, err := aclient.DiscoverClient(ctx, cctx, opts...) if err != nil { return err } @@ -121,7 +127,12 @@ func cmdDeleteProviderAttributes() *cobra.Command { return err } - cl, err := aclient.DiscoverClient(ctx, cctx, cmd.Flags()) + opts, err := cltypes.ClientOptionsFromFlags(cmd.Flags()) + if err != nil { + return err + } + + cl, err := aclient.DiscoverClient(ctx, cctx, opts...) if err != nil { return err } diff --git a/x/cert/client/cli/tx.go b/x/cert/client/cli/tx.go index f095d97730..3b31dae764 100644 --- a/x/cert/client/cli/tx.go +++ b/x/cert/client/cli/tx.go @@ -7,6 +7,7 @@ import ( "math/big" "time" + cltypes "github.com/akash-network/akash-api/go/node/client/types" sdkclient "github.com/cosmos/cosmos-sdk/client" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/spf13/cobra" @@ -152,7 +153,12 @@ func doPublishCmd(cmd *cobra.Command) error { } - cl, err := aclient.DiscoverClient(ctx, cctx, cmd.Flags()) + opts, err := cltypes.ClientOptionsFromFlags(cmd.Flags()) + if err != nil { + return err + } + + cl, err := aclient.DiscoverClient(ctx, cctx, opts...) if err != nil { return err } @@ -208,7 +214,12 @@ func doRevokeCmd(cmd *cobra.Command) error { ctx := cmd.Context() - cl, err := aclient.DiscoverClient(ctx, cctx, cmd.Flags()) + opts, err := cltypes.ClientOptionsFromFlags(cmd.Flags()) + if err != nil { + return err + } + + cl, err := aclient.DiscoverClient(ctx, cctx, opts...) if err != nil { return err } diff --git a/x/cert/client/cli/tx_test.go b/x/cert/client/cli/tx_test.go index ea67e7375c..cc3e2ec00c 100644 --- a/x/cert/client/cli/tx_test.go +++ b/x/cert/client/cli/tx_test.go @@ -20,7 +20,9 @@ type certificateCLISuite struct { } func (s *certificateCLISuite) TestGeneratePublishAndRevokeServer() { - result, err := cli.TxGenerateServerExec(s.GoContextForTest(), s.ContextForTest(), s.WalletForTest(), testHost) + result, err := cli.TxGenerateServerExec(s.GoContextForTest(), s.ContextForTest(), s.WalletForTest(), + testHost, + fmt.Sprintf("--fees=%d%s", 1000, s.Config().BondDenom)) require.NoError(s.T(), err) require.NotNil(s.T(), result) diff --git a/x/deployment/client/cli/tx.go b/x/deployment/client/cli/tx.go index 8fa89d791e..c54e91a4bb 100644 --- a/x/deployment/client/cli/tx.go +++ b/x/deployment/client/cli/tx.go @@ -8,6 +8,7 @@ import ( "strings" "time" + cltypes "github.com/akash-network/akash-api/go/node/client/types" "github.com/spf13/cobra" tmrpc "github.com/tendermint/tendermint/rpc/core/types" @@ -63,7 +64,12 @@ func cmdCreate(key string) *cobra.Command { return err } - cl, err := aclient.DiscoverClient(ctx, cctx, cmd.Flags()) + opts, err := cltypes.ClientOptionsFromFlags(cmd.Flags()) + if err != nil { + return err + } + + cl, err := aclient.DiscoverClient(ctx, cctx, opts...) if err != nil { return err } @@ -170,7 +176,12 @@ func cmdDeposit(key string) *cobra.Command { return err } - cl, err := aclient.DiscoverClient(ctx, cctx, cmd.Flags()) + opts, err := cltypes.ClientOptionsFromFlags(cmd.Flags()) + if err != nil { + return err + } + + cl, err := aclient.DiscoverClient(ctx, cctx, opts...) if err != nil { return err } @@ -225,7 +236,12 @@ func cmdClose(key string) *cobra.Command { return err } - cl, err := aclient.DiscoverClient(ctx, cctx, cmd.Flags()) + opts, err := cltypes.ClientOptionsFromFlags(cmd.Flags()) + if err != nil { + return err + } + + cl, err := aclient.DiscoverClient(ctx, cctx, opts...) if err != nil { return err } @@ -264,7 +280,12 @@ func cmdUpdate(key string) *cobra.Command { return err } - cl, err := aclient.DiscoverClient(ctx, cctx, cmd.Flags()) + opts, err := cltypes.ClientOptionsFromFlags(cmd.Flags()) + if err != nil { + return err + } + + cl, err := aclient.DiscoverClient(ctx, cctx, opts...) if err != nil { return err } @@ -360,7 +381,12 @@ func cmdGroupClose(_ string) *cobra.Command { return err } - cl, err := aclient.DiscoverClient(ctx, cctx, cmd.Flags()) + opts, err := cltypes.ClientOptionsFromFlags(cmd.Flags()) + if err != nil { + return err + } + + cl, err := aclient.DiscoverClient(ctx, cctx, opts...) if err != nil { return err } @@ -408,7 +434,12 @@ func cmdGroupPause(_ string) *cobra.Command { return err } - cl, err := aclient.DiscoverClient(ctx, cctx, cmd.Flags()) + opts, err := cltypes.ClientOptionsFromFlags(cmd.Flags()) + if err != nil { + return err + } + + cl, err := aclient.DiscoverClient(ctx, cctx, opts...) if err != nil { return err } @@ -456,7 +487,12 @@ func cmdGroupStart(_ string) *cobra.Command { return err } - cl, err := aclient.DiscoverClient(ctx, cctx, cmd.Flags()) + opts, err := cltypes.ClientOptionsFromFlags(cmd.Flags()) + if err != nil { + return err + } + + cl, err := aclient.DiscoverClient(ctx, cctx, opts...) if err != nil { return err } @@ -526,7 +562,12 @@ Examples: return err } - cl, err := aclient.DiscoverClient(ctx, cctx, cmd.Flags()) + opts, err := cltypes.ClientOptionsFromFlags(cmd.Flags()) + if err != nil { + return err + } + + cl, err := aclient.DiscoverClient(ctx, cctx, opts...) if err != nil { return err } @@ -592,7 +633,12 @@ Example: return err } - cl, err := aclient.DiscoverClient(ctx, cctx, cmd.Flags()) + opts, err := cltypes.ClientOptionsFromFlags(cmd.Flags()) + if err != nil { + return err + } + + cl, err := aclient.DiscoverClient(ctx, cctx, opts...) if err != nil { return err } diff --git a/x/market/client/cli/tx.go b/x/market/client/cli/tx.go index 4fd2319bb0..271d17ce90 100644 --- a/x/market/client/cli/tx.go +++ b/x/market/client/cli/tx.go @@ -3,6 +3,7 @@ package cli import ( "fmt" + cltypes "github.com/akash-network/akash-api/go/node/client/types" sdkclient "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" sdk "github.com/cosmos/cosmos-sdk/types" @@ -57,7 +58,12 @@ func cmdBidCreate(key string) *cobra.Command { return err } - cl, err := aclient.DiscoverClient(ctx, cctx, cmd.Flags()) + opts, err := cltypes.ClientOptionsFromFlags(cmd.Flags()) + if err != nil { + return err + } + + cl, err := aclient.DiscoverClient(ctx, cctx, opts...) if err != nil { return err } @@ -123,7 +129,12 @@ func cmdBidClose(key string) *cobra.Command { return err } - cl, err := aclient.DiscoverClient(ctx, cctx, cmd.Flags()) + opts, err := cltypes.ClientOptionsFromFlags(cmd.Flags()) + if err != nil { + return err + } + + cl, err := aclient.DiscoverClient(ctx, cctx, opts...) if err != nil { return err } @@ -184,7 +195,12 @@ func cmdLeaseCreate(key string) *cobra.Command { return err } - cl, err := aclient.DiscoverClient(ctx, cctx, cmd.Flags()) + opts, err := cltypes.ClientOptionsFromFlags(cmd.Flags()) + if err != nil { + return err + } + + cl, err := aclient.DiscoverClient(ctx, cctx, opts...) if err != nil { return err } @@ -231,7 +247,12 @@ func cmdLeaseWithdraw(key string) *cobra.Command { return err } - cl, err := aclient.DiscoverClient(ctx, cctx, cmd.Flags()) + opts, err := cltypes.ClientOptionsFromFlags(cmd.Flags()) + if err != nil { + return err + } + + cl, err := aclient.DiscoverClient(ctx, cctx, opts...) if err != nil { return err } @@ -278,7 +299,12 @@ func cmdLeaseClose(key string) *cobra.Command { return err } - cl, err := aclient.DiscoverClient(ctx, cctx, cmd.Flags()) + opts, err := cltypes.ClientOptionsFromFlags(cmd.Flags()) + if err != nil { + return err + } + + cl, err := aclient.DiscoverClient(ctx, cctx, opts...) if err != nil { return err } diff --git a/x/provider/client/cli/tx.go b/x/provider/client/cli/tx.go index fe6efc6bdd..d1a327d1ab 100644 --- a/x/provider/client/cli/tx.go +++ b/x/provider/client/cli/tx.go @@ -3,6 +3,7 @@ package cli import ( "fmt" + cltypes "github.com/akash-network/akash-api/go/node/client/types" sdkclient "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" sdk "github.com/cosmos/cosmos-sdk/types" @@ -42,7 +43,12 @@ func cmdCreate(key string) *cobra.Command { return err } - cl, err := aclient.DiscoverClient(ctx, cctx, cmd.Flags()) + opts, err := cltypes.ClientOptionsFromFlags(cmd.Flags()) + if err != nil { + return err + } + + cl, err := aclient.DiscoverClient(ctx, cctx, opts...) if err != nil { return err } @@ -92,7 +98,12 @@ func cmdUpdate(key string) *cobra.Command { return err } - cl, err := aclient.DiscoverClient(ctx, cctx, cmd.Flags()) + opts, err := cltypes.ClientOptionsFromFlags(cmd.Flags()) + if err != nil { + return err + } + + cl, err := aclient.DiscoverClient(ctx, cctx, opts...) if err != nil { return err }