diff --git a/CHANGELOG.md b/CHANGELOG.md index 9a5ddac6ac20..15c3165d2a29 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -91,6 +91,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### API Breaking Changes +* (container) [#12021](https://github.com/cosmos/cosmos-sdk/pull/12021) Rename `container.Option` to `container.Config` * (x/auth/ante) [#11985](https://github.com/cosmos/cosmos-sdk/pull/11985) The `MempoolFeeDecorator` has been removed. Instead, the `DeductFeeDecorator` takes a new argument of type `TxFeeChecker`, to define custom fee models. If `nil` is passed to this `TxFeeChecker` argument, then it will default to `checkTxFeeWithValidatorMinGasPrices`, which is the exact same behavior as the old `MempoolFeeDecorator` (i.e. checking fees against validator's own min gas price). * (x/auth/ante) [#11985](https://github.com/cosmos/cosmos-sdk/pull/11985) The `ExtensionOptionsDecorator` takes an argument of type `ExtensionOptionChecker`. For backwards-compatibility, you can pass `nil`, which defaults to the old behavior of rejecting all tx extensions. * (crypto/keyring) [#11932](https://github.com/cosmos/cosmos-sdk/pull/11932) Remove `Unsafe*` interfaces from keyring package. Please use interface casting if you wish to access those unsafe functions. diff --git a/container/build.go b/container/build.go index f40864ee211a..92a891a40565 100644 --- a/container/build.go +++ b/container/build.go @@ -1,6 +1,6 @@ package container -// Build builds the container specified by containerOption and extracts the +// Build builds the container specified by containerConfig and extracts the // requested outputs from the container or returns an error. It is the single // entry point for building and running a dependency injection container. // Each of the values specified as outputs must be pointers to types that @@ -13,19 +13,19 @@ package container // Build uses the debug mode provided by AutoDebug which means there will be // verbose debugging information if there is an error and nothing upon success. // Use BuildDebug to configure debug behavior. -func Build(containerOption Option, outputs ...interface{}) error { +func Build(containerConfig Config, outputs ...interface{}) error { loc := LocationFromCaller(1) - return build(loc, AutoDebug(), containerOption, outputs...) + return build(loc, AutoDebug(), containerConfig, outputs...) } // BuildDebug is a version of Build which takes an optional DebugOption for // logging and visualization. -func BuildDebug(debugOpt DebugOption, option Option, outputs ...interface{}) error { +func BuildDebug(debugOpt DebugOption, config Config, outputs ...interface{}) error { loc := LocationFromCaller(1) - return build(loc, debugOpt, option, outputs...) + return build(loc, debugOpt, config, outputs...) } -func build(loc Location, debugOpt DebugOption, option Option, outputs ...interface{}) error { +func build(loc Location, debugOpt DebugOption, config Config, outputs ...interface{}) error { cfg, err := newDebugConfig() if err != nil { return err @@ -38,7 +38,7 @@ func build(loc Location, debugOpt DebugOption, option Option, outputs ...interfa } }() - err = doBuild(cfg, loc, debugOpt, option, outputs...) + err = doBuild(cfg, loc, debugOpt, config, outputs...) if err != nil { cfg.logf("Error: %v", err) if cfg.onError != nil { @@ -59,7 +59,7 @@ func build(loc Location, debugOpt DebugOption, option Option, outputs ...interfa } } -func doBuild(cfg *debugConfig, loc Location, debugOpt DebugOption, option Option, outputs ...interface{}) error { +func doBuild(cfg *debugConfig, loc Location, debugOpt DebugOption, config Config, outputs ...interface{}) error { defer cfg.generateGraph() // always generate graph on exit if debugOpt != nil { @@ -72,7 +72,7 @@ func doBuild(cfg *debugConfig, loc Location, debugOpt DebugOption, option Option cfg.logf("Registering providers") cfg.indentLogger() ctr := newContainer(cfg) - err := option.apply(ctr) + err := config.apply(ctr) if err != nil { cfg.logf("Failed registering providers because of: %+v", err) return err diff --git a/container/option.go b/container/config.go similarity index 57% rename from container/option.go rename to container/config.go index 156a27cd6264..9440fab3026d 100644 --- a/container/option.go +++ b/container/config.go @@ -6,26 +6,26 @@ import ( "github.com/pkg/errors" ) -// Option is a functional option for a container. -type Option interface { +// Config is a functional configuration of a container. +type Config interface { apply(*container) error } -// Provide creates a container option which registers the provided dependency +// Provide defines a container configuration which registers the provided dependency // injection providers. Each provider will be called at most once with the // exception of module-scoped providers which are called at most once per module // (see ModuleKey). -func Provide(providers ...interface{}) Option { - return containerOption(func(ctr *container) error { +func Provide(providers ...interface{}) Config { + return containerConfig(func(ctr *container) error { return provide(ctr, nil, providers) }) } -// ProvideInModule creates a container option which registers the provided dependency +// ProvideInModule defines container configuration which registers the provided dependency // injection providers that are to be run in the named module. Each provider // will be called at most once. -func ProvideInModule(moduleName string, providers ...interface{}) Option { - return containerOption(func(ctr *container) error { +func ProvideInModule(moduleName string, providers ...interface{}) Config { + return containerConfig(func(ctr *container) error { if moduleName == "" { return errors.Errorf("expected non-empty module name") } @@ -48,9 +48,9 @@ func provide(ctr *container, key *moduleKey, providers []interface{}) error { return nil } -func Supply(values ...interface{}) Option { +func Supply(values ...interface{}) Config { loc := LocationFromCaller(1) - return containerOption(func(ctr *container) error { + return containerConfig(func(ctr *container) error { for _, v := range values { err := ctr.supply(reflect.ValueOf(v), loc) if err != nil { @@ -61,17 +61,17 @@ func Supply(values ...interface{}) Option { }) } -// Error creates an option which causes the dependency injection container to +// Error defines configuration which causes the dependency injection container to // fail immediately. -func Error(err error) Option { - return containerOption(func(*container) error { +func Error(err error) Config { + return containerConfig(func(*container) error { return errors.WithStack(err) }) } -// Options creates an option which bundles together other options. -func Options(opts ...Option) Option { - return containerOption(func(ctr *container) error { +// Configs defines a configuration which bundles together multiple Config definitions. +func Configs(opts ...Config) Config { + return containerConfig(func(ctr *container) error { for _, opt := range opts { err := opt.apply(ctr) if err != nil { @@ -82,10 +82,10 @@ func Options(opts ...Option) Option { }) } -type containerOption func(*container) error +type containerConfig func(*container) error -func (c containerOption) apply(ctr *container) error { +func (c containerConfig) apply(ctr *container) error { return c(ctr) } -var _ Option = (*containerOption)(nil) +var _ Config = (*containerConfig)(nil) diff --git a/container/container_test.go b/container/container_test.go index 8ead6b1caea6..19ca76a26c09 100644 --- a/container/container_test.go +++ b/container/container_test.go @@ -82,7 +82,7 @@ func (ModuleB) Provide(dependencies BDependencies) (BProvides, Handler, error) { }, Handler{}, nil } -var scenarioConfig = container.Options( +var scenarioConfig = container.Configs( container.Provide(ProvideMsgClientA), container.ProvideInModule("runtime", ProvideKVStoreKey), container.ProvideInModule("a", wrapMethod0(ModuleA{})), @@ -170,7 +170,7 @@ func TestBadCtr(t *testing.T) { } func TestTrivial(t *testing.T) { - require.NoError(t, container.Build(container.Options())) + require.NoError(t, container.Build(container.Configs())) } func TestErrorFunc(t *testing.T) { @@ -230,7 +230,7 @@ func TestModuleScoped(t *testing.T) { var y float64 require.Error(t, container.Build( - container.Options( + container.Configs( container.Provide( func(container.ModuleKey) int { return 0 }, func() int { return 1 }, @@ -245,7 +245,7 @@ func TestModuleScoped(t *testing.T) { require.Error(t, container.Build( - container.Options( + container.Configs( container.Provide( func() int { return 0 }, func(container.ModuleKey) int { return 1 }, @@ -260,7 +260,7 @@ func TestModuleScoped(t *testing.T) { require.Error(t, container.Build( - container.Options( + container.Configs( container.Provide( func(container.ModuleKey) int { return 0 }, func(container.ModuleKey) int { return 1 }, @@ -275,7 +275,7 @@ func TestModuleScoped(t *testing.T) { require.NoError(t, container.Build( - container.Options( + container.Configs( container.Provide( func(container.ModuleKey) int { return 0 }, ), @@ -289,7 +289,7 @@ func TestModuleScoped(t *testing.T) { require.Error(t, container.Build( - container.Options( + container.Configs( container.Provide( func(container.ModuleKey) int { return 0 }, ), @@ -304,7 +304,7 @@ func TestModuleScoped(t *testing.T) { var z float32 require.NoError(t, container.Build( - container.Options( + container.Configs( container.Provide( func(container.ModuleKey) int { return 0 }, ), @@ -326,7 +326,7 @@ func (OnePerModuleInt) IsOnePerModuleType() {} func TestOnePerModule(t *testing.T) { var x OnePerModuleInt require.Error(t, - container.Build(container.Options(), &x), + container.Build(container.Configs(), &x), "bad input type", ) @@ -334,7 +334,7 @@ func TestOnePerModule(t *testing.T) { var z string require.NoError(t, container.Build( - container.Options( + container.Configs( container.ProvideInModule("a", func() OnePerModuleInt { return 3 }, ), @@ -394,7 +394,7 @@ func TestOnePerModule(t *testing.T) { require.NoError(t, container.Build( - container.Options(), + container.Configs(), &m, ), "no providers", @@ -443,7 +443,7 @@ func TestManyPerContainer(t *testing.T) { require.NoError(t, container.Build( - container.Options(), + container.Configs(), &xs, ), "no providers", @@ -462,7 +462,7 @@ func TestSupply(t *testing.T) { require.Error(t, container.Build( - container.Options( + container.Configs( container.Supply(3), container.Provide(func() int { return 4 }), ), @@ -473,7 +473,7 @@ func TestSupply(t *testing.T) { require.Error(t, container.Build( - container.Options( + container.Configs( container.Supply(3), container.Provide(func() int { return 4 }), ), @@ -507,7 +507,7 @@ type TestOutput struct { func TestStructArgs(t *testing.T) { var input TestInput - require.Error(t, container.Build(container.Options(), &input)) + require.Error(t, container.Build(container.Configs(), &input)) require.NoError(t, container.Build( container.Supply(1.3), @@ -569,7 +569,7 @@ func TestDebugOptions(t *testing.T) { container.FileVisualizer(graphfile.Name()), container.StdoutLogger(), ), - container.Options(), + container.Configs(), )) require.Contains(t, logOut, "digraph") @@ -594,7 +594,7 @@ func TestGraphAndLogOutput(t *testing.T) { require.NoError(t, container.BuildDebug(debugOpts, scenarioConfig, &b)) golden.Assert(t, graphOut, "example.dot") - badConfig := container.Options( + badConfig := container.Configs( container.ProvideInModule("runtime", ProvideKVStoreKey), container.ProvideInModule("a", wrapMethod0(ModuleA{})), container.ProvideInModule("b", wrapMethod0(ModuleB{})), @@ -617,7 +617,7 @@ func TestConditionalDebugging(t *testing.T) { var input TestInput require.Error(t, container.BuildDebug( conditionalDebugOpt, - container.Options(), + container.Configs(), &input, )) require.Contains(t, logs, `Initializing logger`) @@ -629,7 +629,7 @@ func TestConditionalDebugging(t *testing.T) { success = false require.NoError(t, container.BuildDebug( conditionalDebugOpt, - container.Options(), + container.Configs(), )) require.Empty(t, logs) require.True(t, success)