Skip to content

Commit

Permalink
allow mix match gogoproto / pulsar
Browse files Browse the repository at this point in the history
  • Loading branch information
julienrbrt committed Jul 19, 2024
1 parent f670435 commit 2d6491d
Show file tree
Hide file tree
Showing 6 changed files with 389 additions and 9 deletions.
27 changes: 21 additions & 6 deletions depinject/appconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,28 @@ 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)
if err != nil {
panic(err)
}
func WrapAny(config gogoproto.Message) *anypb.Any {
switch cfg := config.(type) {
case protoreflect.ProtoMessage:
cfg, err := anyutil.New(cfg)
if err != nil {
panic(err)
}

return cfg
return cfg.(*anypb.Any)
case gogoproto.Message:
pbz, err := gogoproto.Marshal(cfg)
if err != nil {
panic(err)
}

return &anypb.Any{
TypeUrl: "/" + gogoproto.MessageName(cfg),
Value: pbz,
}
default:
panic(fmt.Errorf("unexpected type %T", config))
}
}

// 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 module registration.
{
Name: countertypes.ModuleName,
Config: appconfig.WrapAny(&countertypes.Module{}),
},
},
})
)
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

0 comments on commit 2d6491d

Please sign in to comment.