Skip to content

Commit

Permalink
fix and wire to core
Browse files Browse the repository at this point in the history
  • Loading branch information
aljo242 committed Feb 7, 2025
1 parent 315d66e commit 3360b99
Show file tree
Hide file tree
Showing 8 changed files with 144 additions and 92 deletions.
2 changes: 1 addition & 1 deletion modules/core/02-client/migrations/v7/solomachine.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

76 changes: 7 additions & 69 deletions modules/core/04-channel/v2/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,98 +2,36 @@ package client

import (
"context"
"encoding/json"
"fmt"

"github.com/spf13/cobra"

"cosmossdk.io/core/appmodule"

"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"

"github.com/cosmos/ibc-go/v9/modules/core/04-channel/v2/client/cli"
"github.com/cosmos/ibc-go/v9/modules/core/04-channel/v2/keeper"
"github.com/cosmos/ibc-go/v9/modules/core/04-channel/v2/types"
)

var (
_ appmodule.AppModule = (*AppModule)(nil)

_ module.AppModule = (*AppModule)(nil)
_ module.HasGenesis = (*AppModule)(nil)
)

// AppModule represents the AppModule for this module
type AppModule struct {
cdc codec.Codec
keeper *keeper.Keeper
}

func (AppModule) IsAppModule() {}

func (AppModule) IsOnePerModuleType() {}

func (m AppModule) DefaultGenesis() json.RawMessage {
gs := types.DefaultGenesisState()
return m.cdc.MustMarshalJSON(&gs)
}

func (m AppModule) ValidateGenesis(data json.RawMessage) error {
gs := &types.GenesisState{}
err := m.cdc.UnmarshalJSON(data, gs)
if err != nil {
return err
}

return gs.Validate()
}

func (m AppModule) InitGenesis(ctx context.Context, data json.RawMessage) error {
gs := &types.GenesisState{}
err := m.cdc.UnmarshalJSON(data, gs)
if err != nil {
return fmt.Errorf("failed to unmarshal genesis state: %w", err)
}

func InitGenesis(ctx context.Context, k *keeper.Keeper, gs types.GenesisState) {
sdkCtx := sdk.UnwrapSDKContext(ctx)
m.keeper.InitGenesis(sdkCtx, *gs)

return nil
k.InitGenesis(sdkCtx, gs)
}

func (m AppModule) ExportGenesis(ctx context.Context) (json.RawMessage, error) {
func ExportGenesis(ctx context.Context, k *keeper.Keeper) types.GenesisState {
sdkCtx := sdk.UnwrapSDKContext(ctx)
gs := m.keeper.ExportGenesis(sdkCtx)
return json.Marshal(gs)
}

// Name returns the IBC channel/v2 name
func (AppModule) Name() string {
return types.SubModuleName
return k.ExportGenesis(sdkCtx)
}

func Name() string {
return AppModule{}.Name()
}

// GetQueryCmd returns the root query command for IBC channels v2.
func (AppModule) GetQueryCmd() *cobra.Command {
return cli.GetQueryCmd()
return types.SubModuleName
}

// GetQueryCmd returns the root query command for IBC channels v2.
func GetQueryCmd() *cobra.Command {
return AppModule{}.GetQueryCmd()
}

// GetTxCmd returns the root tx command for IBC channels v2.
func (AppModule) GetTxCmd() *cobra.Command {
return cli.NewTxCmd()
return cli.GetQueryCmd()
}

// GetTxCmd returns the root tx command for IBC channels v2.
func GetTxCmd() *cobra.Command {
return AppModule{}.GetTxCmd()
return cli.NewTxCmd()
}
3 changes: 3 additions & 0 deletions modules/core/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
client "github.com/cosmos/ibc-go/v9/modules/core/02-client"
connection "github.com/cosmos/ibc-go/v9/modules/core/03-connection"
channel "github.com/cosmos/ibc-go/v9/modules/core/04-channel"
channelv2 "github.com/cosmos/ibc-go/v9/modules/core/04-channel/v2"
"github.com/cosmos/ibc-go/v9/modules/core/keeper"
"github.com/cosmos/ibc-go/v9/modules/core/types"
)
Expand All @@ -18,6 +19,7 @@ func InitGenesis(ctx context.Context, k keeper.Keeper, gs *types.GenesisState) e
}
connection.InitGenesis(ctx, k.ConnectionKeeper, gs.ConnectionGenesis)
channel.InitGenesis(ctx, k.ChannelKeeper, gs.ChannelGenesis)
channelv2.InitGenesis(ctx, k.ChannelKeeperV2, gs.ChannelV2Genesis)
return nil
}

Expand All @@ -31,5 +33,6 @@ func ExportGenesis(ctx context.Context, k keeper.Keeper) (*types.GenesisState, e
ClientGenesis: gs,
ConnectionGenesis: connection.ExportGenesis(ctx, k.ConnectionKeeper),
ChannelGenesis: channel.ExportGenesis(ctx, k.ChannelKeeper),
ChannelV2Genesis: channelv2.ExportGenesis(ctx, k.ChannelKeeperV2),
}, nil
}
46 changes: 46 additions & 0 deletions modules/core/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
clienttypes "github.com/cosmos/ibc-go/v9/modules/core/02-client/types"
connectiontypes "github.com/cosmos/ibc-go/v9/modules/core/03-connection/types"
channeltypes "github.com/cosmos/ibc-go/v9/modules/core/04-channel/types"
channelv2types "github.com/cosmos/ibc-go/v9/modules/core/04-channel/v2/types"
commitmenttypes "github.com/cosmos/ibc-go/v9/modules/core/23-commitment/types"
"github.com/cosmos/ibc-go/v9/modules/core/exported"
"github.com/cosmos/ibc-go/v9/modules/core/types"
Expand Down Expand Up @@ -145,6 +146,20 @@ func (suite *IBCTestSuite) TestValidateGenesis() {
0,
channeltypes.Params{UpgradeTimeout: channeltypes.DefaultTimeout},
),
ChannelV2Genesis: channelv2types.NewGenesisState(
[]channelv2types.PacketState{
channelv2types.NewPacketState(channel2, 1, []byte("ack")),
},
[]channelv2types.PacketState{
channelv2types.NewPacketState(channel2, 1, []byte("")),
},
[]channelv2types.PacketState{
channelv2types.NewPacketState(channel1, 1, []byte("commit_hash")),
},
[]channelv2types.PacketSequence{
channelv2types.NewPacketSequence(channel1, 1),
},
),
},
expError: nil,
},
Expand Down Expand Up @@ -172,6 +187,7 @@ func (suite *IBCTestSuite) TestValidateGenesis() {
2,
),
ConnectionGenesis: connectiontypes.DefaultGenesisState(),
ChannelV2Genesis: channelv2types.DefaultGenesisState(),
},
expError: errors.New("genesis metadata key cannot be empty"),
},
Expand All @@ -189,6 +205,7 @@ func (suite *IBCTestSuite) TestValidateGenesis() {
0,
connectiontypes.Params{},
),
ChannelV2Genesis: channelv2types.DefaultGenesisState(),
},
expError: errors.New("invalid connection"),
},
Expand All @@ -202,6 +219,21 @@ func (suite *IBCTestSuite) TestValidateGenesis() {
channeltypes.NewPacketState("(portID)", channel1, 1, []byte("ack")),
},
},
ChannelV2Genesis: channelv2types.DefaultGenesisState(),
},
expError: errors.New("invalid acknowledgement"),
},
{
name: "invalid channel v2 genesis",
genState: &types.GenesisState{
ClientGenesis: clienttypes.DefaultGenesisState(),
ConnectionGenesis: connectiontypes.DefaultGenesisState(),
ChannelGenesis: channeltypes.DefaultGenesisState(),
ChannelV2Genesis: channelv2types.GenesisState{
Acknowledgements: []channelv2types.PacketState{
channelv2types.NewPacketState(channel1, 1, nil),
},
},
},
expError: errors.New("invalid acknowledgement"),
},
Expand Down Expand Up @@ -305,6 +337,20 @@ func (suite *IBCTestSuite) TestInitGenesis() {
0,
channeltypes.Params{UpgradeTimeout: channeltypes.DefaultTimeout},
),
ChannelV2Genesis: channelv2types.NewGenesisState(
[]channelv2types.PacketState{
channelv2types.NewPacketState(channel2, 1, []byte("ack")),
},
[]channelv2types.PacketState{
channelv2types.NewPacketState(channel2, 1, []byte("")),
},
[]channelv2types.PacketState{
channelv2types.NewPacketState(channel1, 1, []byte("commit_hash")),
},
[]channelv2types.PacketSequence{
channelv2types.NewPacketSequence(channel1, 1),
},
),
},
},
}
Expand Down
8 changes: 7 additions & 1 deletion modules/core/types/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
clienttypes "github.com/cosmos/ibc-go/v9/modules/core/02-client/types"
connectiontypes "github.com/cosmos/ibc-go/v9/modules/core/03-connection/types"
channeltypes "github.com/cosmos/ibc-go/v9/modules/core/04-channel/types"
channelv2types "github.com/cosmos/ibc-go/v9/modules/core/04-channel/v2/types"
)

var _ gogoprotoany.UnpackInterfacesMessage = (*GenesisState)(nil)
Expand All @@ -16,6 +17,7 @@ func DefaultGenesisState() *GenesisState {
ClientGenesis: clienttypes.DefaultGenesisState(),
ConnectionGenesis: connectiontypes.DefaultGenesisState(),
ChannelGenesis: channeltypes.DefaultGenesisState(),
ChannelV2Genesis: channelv2types.DefaultGenesisState(),
}
}

Expand All @@ -35,5 +37,9 @@ func (gs *GenesisState) Validate() error {
return err
}

return gs.ChannelGenesis.Validate()
if err := gs.ChannelGenesis.Validate(); err != nil {
return err
}

return gs.ChannelV2Genesis.Validate()
}
96 changes: 76 additions & 20 deletions modules/core/types/genesis.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 3360b99

Please sign in to comment.