From eb1211a38d557c57910394d5426d6050d62780f2 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Fri, 10 Jan 2025 18:46:42 +0100 Subject: [PATCH] fix(simapp/v2): correctly wire client/v2, clean-up api client/v2 (#23325) --- client/v2/CHANGELOG.md | 2 ++ client/v2/autocli/app.go | 50 ------------------------------------ client/v2/go.mod | 2 +- simapp/v2/simdv2/cmd/root.go | 19 ++++++-------- 4 files changed, 11 insertions(+), 62 deletions(-) diff --git a/client/v2/CHANGELOG.md b/client/v2/CHANGELOG.md index a1855ad0c00c..a35f040c627d 100644 --- a/client/v2/CHANGELOG.md +++ b/client/v2/CHANGELOG.md @@ -36,6 +36,8 @@ Ref: https://keepachangelog.com/en/1.0.0/ ## [Unreleased] +* [#23325](https://github.com/cosmos/cosmos-sdk/pull/23325) Remove `NewAppOptionsFromConfig` that isn't needed in normal wiring. + ## [v2.10.0-beta.1](https://github.com/cosmos/cosmos-sdk/releases/tag/client/v2/v2.10.0-beta.1) - 2024-12-18 ### Features diff --git a/client/v2/autocli/app.go b/client/v2/autocli/app.go index 5e1316b4127d..ce7c1eb3c551 100644 --- a/client/v2/autocli/app.go +++ b/client/v2/autocli/app.go @@ -1,7 +1,6 @@ package autocli import ( - "github.com/cosmos/gogoproto/proto" "github.com/spf13/cobra" "google.golang.org/protobuf/reflect/protoregistry" @@ -10,12 +9,9 @@ import ( "cosmossdk.io/core/address" "cosmossdk.io/core/appmodule" "cosmossdk.io/depinject" - "cosmossdk.io/log" - "cosmossdk.io/x/tx/signing" sdkflags "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/codec" - "github.com/cosmos/cosmos-sdk/codec/types" authtx "github.com/cosmos/cosmos-sdk/x/auth/tx" ) @@ -143,49 +139,3 @@ func (appOptions AppOptions) EnhanceRootCommandWithBuilder(rootCmd *cobra.Comman return nil } - -// NewAppOptionsFromConfig returns AppOptions for an app based on the provided modulesConfig and moduleOptions. -// It returns an AppOptions instance usable for CLI parsing but not execution. For an execution usable AppOptions -// see ProvideAppOptions, which expects input to be filled by depinject. -func NewAppOptionsFromConfig( - modulesConfig depinject.Config, - moduleOptions map[string]*autocliv1.ModuleOptions, -) (AppOptions, error) { - interfaceRegistry, err := types.NewInterfaceRegistryWithOptions(types.InterfaceRegistryOptions{ - ProtoFiles: proto.HybridResolver, - SigningOptions: signing.Options{ - AddressCodec: nopAddressCodec{}, - ValidatorAddressCodec: nopAddressCodec{}, - }, - }) - if err != nil { - return AppOptions{}, err - } - cfg := struct { - depinject.In - Modules map[string]appmodule.AppModule - }{ - Modules: nil, - } - err = depinject.Inject(depinject.Configs( - modulesConfig, - depinject.Supply( - log.NewNopLogger(), - )), &cfg) - if err != nil { - return AppOptions{}, err - } - - return AppOptions{ - Modules: cfg.Modules, - ModuleOptions: moduleOptions, - skipValidation: true, - Cdc: codec.NewProtoCodec(interfaceRegistry), - }, nil -} - -type nopAddressCodec struct{} - -func (nopAddressCodec) StringToBytes(_ string) ([]byte, error) { return nil, nil } - -func (nopAddressCodec) BytesToString(_ []byte) (string, error) { return "", nil } diff --git a/client/v2/go.mod b/client/v2/go.mod index 50be95119569..54efcd62112f 100644 --- a/client/v2/go.mod +++ b/client/v2/go.mod @@ -38,7 +38,7 @@ require ( cosmossdk.io/collections v1.0.0 // indirect cosmossdk.io/core/testing v0.0.1 // indirect cosmossdk.io/errors v1.0.1 - cosmossdk.io/log v1.5.0 + cosmossdk.io/log v1.5.0 // indirect cosmossdk.io/math v1.5.0 cosmossdk.io/schema v1.0.0 // indirect cosmossdk.io/store v1.10.0-rc.1 // indirect diff --git a/simapp/v2/simdv2/cmd/root.go b/simapp/v2/simdv2/cmd/root.go index c2dddc9992f2..61b7c029b4e5 100644 --- a/simapp/v2/simdv2/cmd/root.go +++ b/simapp/v2/simdv2/cmd/root.go @@ -6,7 +6,6 @@ import ( "github.com/spf13/cobra" "github.com/spf13/pflag" - autocliv1 "cosmossdk.io/api/cosmos/autocli/v1" "cosmossdk.io/client/v2/autocli" "cosmossdk.io/core/transaction" "cosmossdk.io/depinject" @@ -16,7 +15,6 @@ import ( "cosmossdk.io/simapp/v2" "github.com/cosmos/cosmos-sdk/client" - nodeservice "github.com/cosmos/cosmos-sdk/client/grpc/node" ) func NewRootCmd[T transaction.Tx]( @@ -39,14 +37,13 @@ func NewRootCmd[T transaction.Tx]( return nil, err } - nodeCmds := nodeservice.NewNodeCommands() - autoCLIModuleOpts := make(map[string]*autocliv1.ModuleOptions) - autoCLIModuleOpts[nodeCmds.Name()] = nodeCmds.AutoCLIOptions() - autoCliOpts, err := autocli.NewAppOptionsFromConfig( - depinject.Configs(simapp.AppConfig(), depinject.Supply(runtime.GlobalConfig{})), - autoCLIModuleOpts, - ) - if err != nil { + var autoCliOpts autocli.AppOptions + if err := depinject.Inject( + depinject.Configs( + simapp.AppConfig(), + depinject.Supply(runtime.GlobalConfig{}, log.NewNopLogger())), + &autoCliOpts, + ); err != nil { return nil, err } @@ -107,7 +104,7 @@ func NewRootCmd[T transaction.Tx]( if err != nil { return nil, err } - autoCliOpts.ModuleOptions = autoCLIModuleOpts + if err := autoCliOpts.EnhanceRootCommand(rootCommand); err != nil { return nil, err }