Skip to content

Commit

Permalink
feat: clean-up sdk deps (use core codec, server v2 auto grpc gateway)
Browse files Browse the repository at this point in the history
  • Loading branch information
julienrbrt committed Jan 19, 2025
1 parent 5261fd9 commit 592b7c5
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 377 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
> [!NOTE]
> This is an example module for the v0.52.x Cosmos SDK.
> Looking for the v0.50.x example? Check the [v0.50.x branch](https://go.cosmonity.xyz/example/tree/v0.50.x).
> Looking for the v0.50.x example? Check the [v0.50.x branch](https://github.com/cosmonity/example/tree/v0.50.x).
# `{Module Name}`

Expand Down
18 changes: 10 additions & 8 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module go.cosmonity.xyz/example
go 1.23.4

// SDK v0.52. integration
replace github.com/cosmos/cosmos-sdk => github.com/cosmos/cosmos-sdk v0.52.0-rc.1.0.20250107080912-2bcc7678255f
replace github.com/cosmos/cosmos-sdk => github.com/cosmos/cosmos-sdk v0.52.0-rc.1.0.20250117223216-2dc4cd5876ba

require (
cosmossdk.io/api v0.8.2 // main
Expand All @@ -12,18 +12,20 @@ require (
cosmossdk.io/depinject v1.1.0
cosmossdk.io/errors v1.0.1 // indirect
cosmossdk.io/errors/v2 v2.0.0
cosmossdk.io/store v1.10.0-rc.1.0.20241218084712-ca559989da43
cosmossdk.io/store v1.10.0-rc.1.0.20250117224339-f9bb1803f185
github.com/cosmos/cosmos-proto v1.0.0-beta.5
github.com/cosmos/cosmos-sdk v0.52.0
github.com/cosmos/gogoproto v1.7.0
github.com/golang/protobuf v1.5.4
github.com/grpc-ecosystem/grpc-gateway v1.16.0
github.com/golang/protobuf v1.5.4 // indirect
github.com/grpc-ecosystem/grpc-gateway v1.16.0 // indirect
github.com/stretchr/testify v1.10.0
google.golang.org/genproto/googleapis/api v0.0.0-20241015192408-796eee8c2d53
google.golang.org/grpc v1.69.4
google.golang.org/protobuf v1.36.2 // indirect
google.golang.org/protobuf v1.36.3 // indirect
)

require cosmossdk.io/collections/protocodec v0.0.2

require (
buf.build/gen/go/cometbft/cometbft/protocolbuffers/go v1.36.2-20241120201313-68e42a58b301.1 // indirect
buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.36.2-20240130113600-88ef6483f90f.1 // indirect
Expand Down Expand Up @@ -96,7 +98,7 @@ require (
github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c // indirect
github.com/hashicorp/go-hclog v1.6.3 // indirect
github.com/hashicorp/go-immutable-radix v1.3.1 // indirect
github.com/hashicorp/go-metrics v0.5.3 // indirect
github.com/hashicorp/go-metrics v0.5.4 // indirect
github.com/hashicorp/go-plugin v1.6.2 // indirect
github.com/hashicorp/golang-lru v1.0.2 // indirect
github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect
Expand Down Expand Up @@ -158,14 +160,14 @@ require (
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/arch v0.12.0 // indirect
golang.org/x/crypto v0.32.0 // indirect
golang.org/x/exp v0.0.0-20241108190413-2d47ceb2692f // indirect
golang.org/x/exp v0.0.0-20250106191152-7588d65b2ba8 // indirect
golang.org/x/mod v0.22.0 // indirect
golang.org/x/net v0.34.0 // indirect
golang.org/x/sync v0.10.0 // indirect
golang.org/x/sys v0.29.0 // indirect
golang.org/x/term v0.28.0 // indirect
golang.org/x/text v0.21.0 // indirect
golang.org/x/tools v0.27.0 // indirect
golang.org/x/tools v0.29.0 // indirect
google.golang.org/genproto v0.0.0-20240227224415-6ceb2ff114de // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20250106144421-5f5ef82da422 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
Expand Down
51 changes: 39 additions & 12 deletions go.sum

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import (
"fmt"

"cosmossdk.io/collections"
"cosmossdk.io/collections/protocodec"
"cosmossdk.io/core/address"
"cosmossdk.io/core/codec"
storetypes "cosmossdk.io/core/store"
"github.com/cosmos/cosmos-sdk/codec"

"go.cosmonity.xyz/example"
)
Expand Down Expand Up @@ -36,7 +37,7 @@ func NewKeeper(cdc codec.BinaryCodec, addressCodec address.Codec, storeService s
cdc: cdc,
addressCodec: addressCodec,
authority: authority,
Params: collections.NewItem(sb, example.ParamsKey, "params", codec.CollValue[example.Params](cdc)),
Params: collections.NewItem(sb, example.ParamsKey, "params", protocodec.CollValue[example.Params](cdc)),
Counter: collections.NewMap(sb, example.CounterKey, "counter", collections.StringKey, collections.Uint64Value),
}

Expand Down
3 changes: 2 additions & 1 deletion keeper/keeper_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package keeper_test

import (
"context"
"testing"

storetypes "cosmossdk.io/store/types"
Expand All @@ -17,7 +18,7 @@ import (
)

type testFixture struct {
ctx sdk.Context
ctx context.Context
k keeper.Keeper
msgServer example.MsgServer
queryServer example.QueryServer
Expand Down
2 changes: 1 addition & 1 deletion module/depinject.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ package module
import (
"cosmossdk.io/core/address"
"cosmossdk.io/core/appmodule"
"cosmossdk.io/core/codec"
"cosmossdk.io/core/store"
"cosmossdk.io/depinject"
"cosmossdk.io/depinject/appconfig"

"github.com/cosmos/cosmos-sdk/codec"
sdkaddress "github.com/cosmos/cosmos-sdk/types/address"

"go.cosmonity.xyz/example"
Expand Down
19 changes: 7 additions & 12 deletions module/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,10 @@ import (
"fmt"

appmodulev2 "cosmossdk.io/core/appmodule/v2"
"cosmossdk.io/core/codec"
"cosmossdk.io/core/registry"
gwruntime "github.com/grpc-ecosystem/grpc-gateway/runtime"
"google.golang.org/grpc"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec"

"go.cosmonity.xyz/example"
"go.cosmonity.xyz/example/keeper"
)
Expand Down Expand Up @@ -44,13 +41,6 @@ func NewAppModule(cdc codec.Codec, keeper keeper.Keeper) AppModule {
// RegisterLegacyAminoCodec registers the example module's types on the LegacyAmino codec.
func (AppModule) RegisterLegacyAminoCodec(registry.AminoRegistrar) {}

// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the example module.
func (AppModule) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *gwruntime.ServeMux) {
if err := example.RegisterQueryHandlerClient(context.Background(), mux, example.NewQueryClient(clientCtx)); err != nil {
panic(err)
}
}

// RegisterInterfaces registers interfaces and implementations of the example module.
func (AppModule) RegisterInterfaces(registrar registry.InterfaceRegistrar) {
example.RegisterInterfaces(registrar)
Expand All @@ -77,7 +67,12 @@ func (am AppModule) RegisterMigrations(mr appmodulev2.MigrationRegistrar) error

// DefaultGenesis returns default genesis state as raw bytes for the module.
func (am AppModule) DefaultGenesis() json.RawMessage {
return am.cdc.MustMarshalJSON(example.NewGenesisState())
genesis, err := am.cdc.MarshalJSON(example.NewGenesisState())
if err != nil {
panic(fmt.Errorf("failed to marshal default %s genesis state: %v", example.ModuleName, err))
}

return genesis
}

// ValidateGenesis performs genesis state validation for the circuit module.
Expand Down
3 changes: 0 additions & 3 deletions proto/buf.gen.gogo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,3 @@ plugins:
- name: gocosmos
out: ..
opt: plugins=grpc,Mgoogle/protobuf/any.proto=github.com/cosmos/gogoproto/types/any,Mcosmos/orm/v1/orm.proto=cosmossdk.io/orm,Mcosmos/app/v1alpha1/module.proto=cosmossdk.io/api/cosmos/app/v1alpha1
- name: grpc-gateway
out: ..
opt: logtostderr=true,allow_colon_final_segments=true
Loading

0 comments on commit 592b7c5

Please sign in to comment.