Skip to content

Commit

Permalink
fix(simapp/v2): correctly wire client/v2, clean-up api client/v2 (#23325
Browse files Browse the repository at this point in the history
)
  • Loading branch information
julienrbrt authored Jan 10, 2025
1 parent a6b0924 commit eb1211a
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 62 deletions.
2 changes: 2 additions & 0 deletions client/v2/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
50 changes: 0 additions & 50 deletions client/v2/autocli/app.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package autocli

import (
"github.com/cosmos/gogoproto/proto"
"github.com/spf13/cobra"
"google.golang.org/protobuf/reflect/protoregistry"

Expand All @@ -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"
)

Expand Down Expand Up @@ -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 }
2 changes: 1 addition & 1 deletion client/v2/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 8 additions & 11 deletions simapp/v2/simdv2/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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](
Expand All @@ -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
}

Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit eb1211a

Please sign in to comment.