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

support app wiring #127

Merged
merged 4 commits into from
Jul 19, 2023
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
578 changes: 578 additions & 0 deletions api/tibc/core/module/v1/module.pulsar.go

Large diffs are not rendered by default.

4 changes: 0 additions & 4 deletions modules/tibc/core/02-client/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"

"github.com/bianjieai/tibc-go/modules/tibc/core/02-client/types"
host "github.com/bianjieai/tibc-go/modules/tibc/core/24-host"
Expand All @@ -24,21 +23,18 @@ import (
type Keeper struct {
storeKey storetypes.StoreKey
cdc codec.BinaryCodec
paramSpace paramtypes.Subspace
stakingKeeper types.StakingKeeper
}

// NewKeeper creates a new NewKeeper instance
func NewKeeper(
cdc codec.BinaryCodec,
key storetypes.StoreKey,
paramSpace paramtypes.Subspace,
sk types.StakingKeeper,
) Keeper {
return Keeper{
storeKey: key,
cdc: cdc,
paramSpace: paramSpace,
stakingKeeper: sk,
}
}
Expand Down
65 changes: 65 additions & 0 deletions modules/tibc/core/depinject.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package tibc

import (
"cosmossdk.io/core/appmodule"
"cosmossdk.io/depinject"

"github.com/cosmos/cosmos-sdk/codec"
store "github.com/cosmos/cosmos-sdk/store/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"

modulev1 "github.com/bianjieai/tibc-go/api/tibc/core/module/v1"
clienttypes "github.com/bianjieai/tibc-go/modules/tibc/core/02-client/types"
"github.com/bianjieai/tibc-go/modules/tibc/core/keeper"
)

// App Wiring Setup
func init() {
appmodule.Register(&modulev1.Module{},
appmodule.Provide(ProvideModule),
)
}

var _ appmodule.AppModule = AppModule{}

// IsOnePerModuleType implements the depinject.OnePerModuleType interface.
func (am AppModule) IsOnePerModuleType() {}

// IsAppModule implements the appmodule.AppModule interface.
func (am AppModule) IsAppModule() {}

type TibcInputs struct {
depinject.In

Config *modulev1.Module
Cdc codec.Codec
Key *store.KVStoreKey

StakingKeeper clienttypes.StakingKeeper
}

type TibcOutputs struct {
depinject.Out

TibcKeeper *keeper.Keeper
Module appmodule.AppModule
}

func ProvideModule(in TibcInputs) TibcOutputs {
// default to governance authority if not provided
authority := authtypes.NewModuleAddress(govtypes.ModuleName)
if in.Config.Authority != "" {
authority = authtypes.NewModuleAddressOrBech32Address(in.Config.Authority)
}

keeper := keeper.NewKeeper(
in.Cdc,
in.Key,
in.StakingKeeper,
authority.String(),
)
m := NewAppModule(keeper)

return TibcOutputs{TibcKeeper: keeper, Module: m}
}
9 changes: 5 additions & 4 deletions modules/tibc/core/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package keeper
import (
"github.com/cosmos/cosmos-sdk/codec"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"

clientkeeper "github.com/bianjieai/tibc-go/modules/tibc/core/02-client/keeper"
clienttypes "github.com/bianjieai/tibc-go/modules/tibc/core/02-client/types"
Expand Down Expand Up @@ -31,10 +30,12 @@ type Keeper struct {

// NewKeeper creates a new tibc Keeper
func NewKeeper(
cdc codec.BinaryCodec, key storetypes.StoreKey, paramSpace paramtypes.Subspace,
stakingKeeper clienttypes.StakingKeeper, authority string,
cdc codec.BinaryCodec,
key storetypes.StoreKey,
stakingKeeper clienttypes.StakingKeeper,
authority string,
) *Keeper {
clientKeeper := clientkeeper.NewKeeper(cdc, key, paramSpace, stakingKeeper)
clientKeeper := clientkeeper.NewKeeper(cdc, key, stakingKeeper)
routingKeeper := routingkeeper.NewKeeper(key)
packetkeeper := packetkeeper.NewKeeper(cdc, key, clientKeeper, routingKeeper)

Expand Down
19 changes: 19 additions & 0 deletions proto/buf.gen.pulsar.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
version: v1
managed:
enabled: true
go_package_prefix:
default: cosmossdk.io/api
except:
- buf.build/googleapis/googleapis
- buf.build/cosmos/gogo-proto
- buf.build/cosmos/cosmos-proto
- buf.build/cosmos/ics23
override:
buf.build/irisnet/tibc-go: github.com/bianjieai/tibc-go/api
plugins:
- name: go-pulsar
out: ../api
opt: paths=source_relative
- name: go-grpc
out: ../api
opt: paths=source_relative
15 changes: 15 additions & 0 deletions proto/tibc/core/module/v1/module.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
syntax = "proto3";

package tibc.core.module.v1;

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

// Module is the config object of the tibc module.
message Module {
option (cosmos.app.v1alpha1.module) = {
go_import: "github.com/bianjieai/tibc-go/modules/tibc/core"
};

// authority defines the custom module authority. If not set, defaults to the governance module.
string authority = 1;
}
16 changes: 16 additions & 0 deletions scripts/protocgen-pulsar.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# this script is for generating protobuf files for the new google.golang.org/protobuf API

set -eo pipefail

protoc_install_gopulsar() {
go install github.com/cosmos/cosmos-proto/cmd/protoc-gen-go-pulsar@latest
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
}

protoc_install_gopulsar

echo "Cleaning API directory"
(cd api; find ./ -type f \( -iname \*.pulsar.go -o -iname \*.pb.go -o -iname \*.cosmos_orm.go -o -iname \*.pb.gw.go \) -delete; find . -empty -type d -delete; cd ..)

echo "Generating API module"
(cd proto; buf generate --template buf.gen.pulsar.yaml)
18 changes: 15 additions & 3 deletions scripts/protocgen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,22 @@ set -eo pipefail
echo "Generating gogo proto code"
cd proto

buf generate --template buf.gen.gogo.yaml $file
proto_dirs=$(find ./tibc -path -prune -o -name '*.proto' -print0 | xargs -0 -n1 dirname | sort | uniq)
for dir in $proto_dirs; do
for file in $(find "${dir}" -maxdepth 1 -name '*.proto'); do
# this regex checks if a proto file has its go_package set to cosmossdk.io/api/...
# gogo proto files SHOULD ONLY be generated if this is false
# we don't want gogo proto to run for proto files which are natively built for google.golang.org/protobuf
if grep -q "option go_package" "$file" && grep -H -o -c 'option go_package.*cosmossdk.io/api' "$file" | grep -q ':0$'; then
buf generate --template buf.gen.gogo.yaml $file
fi
done
done

cd ..

# move proto files to the right places
cp -r github.com/bianjieai/tibc-go/* ./
rm -rf github.com
# cp -r github.com/bianjieai/tibc-go/* ./
rm -rf github.com

./scripts/protocgen-pulsar.sh
1 change: 0 additions & 1 deletion simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,6 @@ func NewSimApp(
app.TIBCKeeper = tibckeeper.NewKeeper(
appCodec,
keys[tibchost.StoreKey],
app.GetSubspace(tibchost.ModuleName),
app.StakingKeeper,
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)
Expand Down