Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: prepare depinject 1.0.0 #21001

Merged
merged 4 commits into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions depinject/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ Each entry must include the Github issue reference in the following format:

## [Unreleased]

### Features
## 1.0.0

- [#20540](https://github.com/cosmos/cosmos-sdk/pull/20540) add support for defining `appconfig` module configuration types using `github.com/cosmos/gogoproto/proto` in addition to `google.golang.org/protobuf` so that users can use gogo proto across their stack.
* [#20540](https://github.com/cosmos/cosmos-sdk/pull/20540) Add support for defining `appconfig` module configuration types using `github.com/cosmos/gogoproto/proto` in addition to `google.golang.org/protobuf` so that users can use gogo proto across their stack.
* Move `cosmossdk.io/core/appconfig` to `cosmossdk.io/depinject/appconfig`.

## 1.0.0-alpha.x

Expand Down
10 changes: 6 additions & 4 deletions depinject/appconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"reflect"
"strings"

"github.com/cosmos/cosmos-proto/anyutil"
gogoproto "github.com/cosmos/gogoproto/proto"
"google.golang.org/protobuf/encoding/protojson"
protov2 "google.golang.org/protobuf/proto"
Expand Down Expand Up @@ -52,13 +51,16 @@ func LoadYAML(bz []byte) depinject.Config {
}

// WrapAny marshals a proto message into a proto Any instance
func WrapAny(config protoreflect.ProtoMessage) *anypb.Any {
cfg, err := anyutil.New(config)
func WrapAny(config gogoproto.Message) *anypb.Any {
pbz, err := gogoproto.Marshal(config)
if err != nil {
panic(err)
}

return cfg
return &anypb.Any{
TypeUrl: "/" + gogoproto.MessageName(config),
Value: pbz,
}
}

// Compose composes an app config into a container option by resolving
Expand Down
7 changes: 7 additions & 0 deletions simapp/app_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ import (
upgradetypes "cosmossdk.io/x/upgrade/types"

"github.com/cosmos/cosmos-sdk/runtime"
_ "github.com/cosmos/cosmos-sdk/testutil/x/counter" // import for side-effects
countertypes "github.com/cosmos/cosmos-sdk/testutil/x/counter/types"
genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types"
)

Expand Down Expand Up @@ -279,6 +281,11 @@ var (
Name: epochstypes.ModuleName,
Config: appconfig.WrapAny(&epochsmodulev1.Module{}),
},
// This module is used for testing the depinject gogo x pulsar module registration.
{
Name: countertypes.ModuleName,
Config: appconfig.WrapAny(&countertypes.Module{}),
},
},
})
)
3 changes: 3 additions & 0 deletions simapp/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
epochstypes "cosmossdk.io/x/epochs/types"
protocolpooltypes "cosmossdk.io/x/protocolpool/types"
upgradetypes "cosmossdk.io/x/upgrade/types"

countertypes "github.com/cosmos/cosmos-sdk/testutil/x/counter/types"
)

// UpgradeName defines the on-chain upgrade name for the sample SimApp upgrade
Expand Down Expand Up @@ -45,6 +47,7 @@ func (app SimApp) RegisterUpgradeHandlers() {
accounts.StoreKey,
protocolpooltypes.StoreKey,
epochstypes.StoreKey,
countertypes.StoreKey, // This module is used for testing purposes only.
},
Deleted: []string{"crisis"}, // The SDK discontinued the crisis module in v0.52.0
}
Expand Down
34 changes: 34 additions & 0 deletions testutil/x/counter/autocli.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package counter

import (
autocliv1 "cosmossdk.io/api/cosmos/autocli/v1"
counterv1 "cosmossdk.io/api/cosmos/counter/v1"
)

// AutoCLIOptions implements the autocli.HasAutoCLIConfig interface.
func (am AppModule) AutoCLIOptions() *autocliv1.ModuleOptions {
return &autocliv1.ModuleOptions{
Query: &autocliv1.ServiceCommandDescriptor{
Service: counterv1.Query_ServiceDesc.ServiceName,
RpcCommandOptions: []*autocliv1.RpcCommandOptions{
{
RpcMethod: "GetCount",
Use: "count",
Short: "Query the current counter value",
},
},
},
Tx: &autocliv1.ServiceCommandDescriptor{
Service: counterv1.Msg_ServiceDesc.ServiceName,
RpcCommandOptions: []*autocliv1.RpcCommandOptions{
{
RpcMethod: "IncreaseCount",
Use: "increase-count [count]",
Alias: []string{"increase-counter", "increase", "inc", "bump"},
Short: "Increase the counter by the specified amount",
PositionalArgs: []*autocliv1.PositionalArgDescriptor{{ProtoField: "count"}},
},
},
},
}
}
6 changes: 3 additions & 3 deletions testutil/x/counter/depinject.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package counter

import (
modulev1 "cosmossdk.io/api/cosmos/counter/module/v1"
"cosmossdk.io/core/appmodule"
"cosmossdk.io/depinject"
"cosmossdk.io/depinject/appconfig"

"github.com/cosmos/cosmos-sdk/testutil/x/counter/keeper"
"github.com/cosmos/cosmos-sdk/testutil/x/counter/types"
)

var _ depinject.OnePerModuleType = AppModule{}
Expand All @@ -16,15 +16,15 @@ func (am AppModule) IsOnePerModuleType() {}

func init() {
appconfig.RegisterModule(
&modulev1.Module{},
&types.Module{},
appconfig.Provide(ProvideModule),
)
}

type ModuleInputs struct {
depinject.In

Config *modulev1.Module
Config *types.Module
Environment appmodule.Environment
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ package cosmos.counter.module.v1;

import "cosmos/app/v1alpha1/module.proto";

option go_package = "github.com/cosmos/cosmos-sdk/testutil/x/counter/types";

// Module is the config object of the counter module.
message Module {
option (cosmos.app.v1alpha1.module) = {
Expand Down
Loading
Loading