diff --git a/docs/ibc/proto-docs.md b/docs/ibc/proto-docs.md index 11f3ab0479b..4b05a167c58 100644 --- a/docs/ibc/proto-docs.md +++ b/docs/ibc/proto-docs.md @@ -30,7 +30,9 @@ - [IdentifiedPacketFee](#ibc.applications.fee.v1.IdentifiedPacketFee) - [ibc/applications/fee/v1/genesis.proto](#ibc/applications/fee/v1/genesis.proto) + - [FeeEnabledChannel](#ibc.applications.fee.v1.FeeEnabledChannel) - [GenesisState](#ibc.applications.fee.v1.GenesisState) + - [RegisteredRelayerAddress](#ibc.applications.fee.v1.RegisteredRelayerAddress) - [ibc/applications/fee/v1/query.proto](#ibc/applications/fee/v1/query.proto) - [QueryIncentivizedPacketRequest](#ibc.applications.fee.v1.QueryIncentivizedPacketRequest) @@ -670,12 +672,51 @@ and an optional list of relayers that are permitted to receive the fee. + + +### FeeEnabledChannel +Contains the PortID & ChannelID for a fee enabled channel + + +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| `port_id` | [string](#string) | | | +| `channel_id` | [string](#string) | | | + + + + + + ### GenesisState GenesisState defines the fee middleware genesis state +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| `identified_fees` | [IdentifiedPacketFee](#ibc.applications.fee.v1.IdentifiedPacketFee) | repeated | | +| `fee_enabled_channels` | [FeeEnabledChannel](#ibc.applications.fee.v1.FeeEnabledChannel) | repeated | | +| `registered_relayers` | [RegisteredRelayerAddress](#ibc.applications.fee.v1.RegisteredRelayerAddress) | repeated | | + + + + + + + + +### RegisteredRelayerAddress +Contains the address and counterparty address for a specific relayer (for distributing fees) + + +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| `address` | [string](#string) | | | +| `counterparty_address` | [string](#string) | | | + + diff --git a/modules/apps/29-fee/keeper/escrow.go b/modules/apps/29-fee/keeper/escrow.go index 1f46d16bbf9..ce7c73db8ce 100644 --- a/modules/apps/29-fee/keeper/escrow.go +++ b/modules/apps/29-fee/keeper/escrow.go @@ -4,7 +4,6 @@ import ( "fmt" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/ibc-go/modules/apps/29-fee/types" diff --git a/modules/apps/29-fee/keeper/escrow_test.go b/modules/apps/29-fee/keeper/escrow_test.go index 91cd66a2a14..f9622bc3259 100644 --- a/modules/apps/29-fee/keeper/escrow_test.go +++ b/modules/apps/29-fee/keeper/escrow_test.go @@ -70,7 +70,7 @@ func (suite *KeeperTestSuite) TestEscrowPacketFee() { ackFee = validCoins receiveFee = validCoins2 timeoutFee = validCoins3 - packetId := &channeltypes.PacketId{ChannelId: validChannelId, PortId: types.PortKey, Sequence: uint64(1)} + packetId := &channeltypes.PacketId{ChannelId: validChannelId, PortId: types.PortID, Sequence: uint64(1)} tc.malleate() fee := types.Fee{ackFee, receiveFee, timeoutFee} @@ -130,7 +130,7 @@ func (suite *KeeperTestSuite) TestDistributeFee() { { "fee not found for packet", func() { // setting packetId with an invalid sequence of 2 - packetId = &channeltypes.PacketId{ChannelId: validChannelId, PortId: types.PortKey, Sequence: uint64(2)} + packetId = &channeltypes.PacketId{ChannelId: validChannelId, PortId: types.PortID, Sequence: uint64(2)} }, false, }, } @@ -149,7 +149,7 @@ func (suite *KeeperTestSuite) TestDistributeFee() { ackFee = validCoins receiveFee = validCoins2 timeoutFee = validCoins3 - packetId = &channeltypes.PacketId{ChannelId: validChannelId, PortId: types.PortKey, Sequence: validSeq} + packetId = &channeltypes.PacketId{ChannelId: validChannelId, PortId: types.PortID, Sequence: validSeq} fee := types.Fee{receiveFee, ackFee, timeoutFee} // escrow the packet fee & store the fee in state @@ -188,7 +188,7 @@ func (suite *KeeperTestSuite) TestDistributeFee() { } else { suite.Require().Error(err) - invalidPacketID := &channeltypes.PacketId{PortId: types.PortKey, ChannelId: validChannelId, Sequence: 1} + invalidPacketID := &channeltypes.PacketId{PortId: types.PortID, ChannelId: validChannelId, Sequence: 1} hasFeeInEscrow := suite.chainA.GetSimApp().IBCFeeKeeper.HasFeeInEscrow(suite.chainA.GetContext(), invalidPacketID) // there should still be a fee in escrow for this packet suite.Require().True(hasFeeInEscrow) @@ -222,7 +222,7 @@ func (suite *KeeperTestSuite) TestDistributeTimeoutFee() { { "fee not found for packet", func() { // setting packetId with an invalid sequence of 2 - packetId = &channeltypes.PacketId{ChannelId: validChannelId, PortId: types.PortKey, Sequence: uint64(2)} + packetId = &channeltypes.PacketId{ChannelId: validChannelId, PortId: types.PortID, Sequence: uint64(2)} }, false, }, } @@ -240,7 +240,7 @@ func (suite *KeeperTestSuite) TestDistributeTimeoutFee() { ackFee = validCoins receiveFee = validCoins2 timeoutFee = validCoins3 - packetId = &channeltypes.PacketId{ChannelId: validChannelId, PortId: types.PortKey, Sequence: validSeq} + packetId = &channeltypes.PacketId{ChannelId: validChannelId, PortId: types.PortID, Sequence: validSeq} fee := types.Fee{receiveFee, ackFee, timeoutFee} // escrow the packet fee & store the fee in state @@ -274,7 +274,7 @@ func (suite *KeeperTestSuite) TestDistributeTimeoutFee() { } else { suite.Require().Error(err) - invalidPacketID := &channeltypes.PacketId{PortId: types.PortKey, ChannelId: validChannelId, Sequence: 1} + invalidPacketID := &channeltypes.PacketId{PortId: types.PortID, ChannelId: validChannelId, Sequence: 1} hasFeeInEscrow := suite.chainA.GetSimApp().IBCFeeKeeper.HasFeeInEscrow(suite.chainA.GetContext(), invalidPacketID) // there should still be a fee in escrow for this packet suite.Require().True(hasFeeInEscrow) diff --git a/modules/apps/29-fee/keeper/genesis.go b/modules/apps/29-fee/keeper/genesis.go index cb500443231..7ce7f11970f 100644 --- a/modules/apps/29-fee/keeper/genesis.go +++ b/modules/apps/29-fee/keeper/genesis.go @@ -1,16 +1,31 @@ package keeper -/* import ( sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/cosmos/ibc-go/modules/apps/29-fee/types" ) // InitGenesis func (k Keeper) InitGenesis(ctx sdk.Context, state types.GenesisState) { + for _, fee := range state.IdentifiedFees { + k.SetFeeInEscrow(ctx, fee) + } + + for _, addr := range state.RegisteredRelayers { + k.SetCounterpartyAddress(ctx, addr.Address, addr.CounterpartyAddress) + } + + for _, enabledChan := range state.FeeEnabledChannels { + k.SetFeeEnabled(ctx, enabledChan.PortId, enabledChan.ChannelId) + } } // ExportGenesis func (k Keeper) ExportGenesis(ctx sdk.Context) *types.GenesisState { - return &types.GenesisState{} + return &types.GenesisState{ + IdentifiedFees: k.GetAllIdentifiedPacketFees(ctx), + FeeEnabledChannels: k.GetAllFeeEnabledChannels(ctx), + RegisteredRelayers: k.GetAllRelayerAddresses(ctx), + } } -*/ diff --git a/modules/apps/29-fee/keeper/genesis_test.go b/modules/apps/29-fee/keeper/genesis_test.go new file mode 100644 index 00000000000..4119891d380 --- /dev/null +++ b/modules/apps/29-fee/keeper/genesis_test.go @@ -0,0 +1,112 @@ +package keeper_test + +import ( + "github.com/cosmos/ibc-go/modules/apps/29-fee/types" + transfertypes "github.com/cosmos/ibc-go/modules/apps/transfer/types" + ibctesting "github.com/cosmos/ibc-go/testing" +) + +func (suite *KeeperTestSuite) TestInitGenesis() { + suite.SetupTest() + + // build PacketId & Fee + refundAcc := suite.chainA.SenderAccount.GetAddress() + packetId := types.NewPacketId( + ibctesting.FirstChannelID, + types.PortID, + uint64(1), + ) + fee := types.Fee{ + validCoins, + validCoins2, + validCoins3, + } + + // relayer addresses + sender := suite.chainA.SenderAccount.GetAddress().String() + counterparty := suite.chainB.SenderAccount.GetAddress().String() + + genesisState := types.GenesisState{ + IdentifiedFees: []*types.IdentifiedPacketFee{ + { + PacketId: packetId, + Fee: fee, + RefundAddress: refundAcc.String(), + Relayers: nil, + }, + }, + FeeEnabledChannels: []*types.FeeEnabledChannel{ + { + PortId: transfertypes.PortID, + ChannelId: ibctesting.FirstChannelID, + }, + }, + RegisteredRelayers: []*types.RegisteredRelayerAddress{ + { + Address: sender, + CounterpartyAddress: counterparty, + }, + }, + } + + suite.chainA.GetSimApp().IBCFeeKeeper.InitGenesis(suite.chainA.GetContext(), genesisState) + + // check fee + identifiedFee, found := suite.chainA.GetSimApp().IBCFeeKeeper.GetFeeInEscrow(suite.chainA.GetContext(), packetId) + suite.Require().True(found) + suite.Require().Equal(genesisState.IdentifiedFees[0], &identifiedFee) + + // check fee is enabled + isEnabled := suite.chainA.GetSimApp().IBCFeeKeeper.IsFeeEnabled(suite.chainA.GetContext(), transfertypes.PortID, ibctesting.FirstChannelID) + suite.Require().True(isEnabled) + + // check relayers + addr, found := suite.chainA.GetSimApp().IBCFeeKeeper.GetCounterpartyAddress(suite.chainA.GetContext(), sender) + suite.Require().True(found) + suite.Require().Equal(genesisState.RegisteredRelayers[0].CounterpartyAddress, addr) +} + +func (suite *KeeperTestSuite) TestExportGenesis() { + suite.SetupTest() + // set fee enabled + suite.chainA.GetSimApp().IBCFeeKeeper.SetFeeEnabled(suite.chainA.GetContext(), transfertypes.PortID, ibctesting.FirstChannelID) + + // setup & escrow the packet fee + refundAcc := suite.chainA.SenderAccount.GetAddress() + packetId := types.NewPacketId( + ibctesting.FirstChannelID, + types.PortID, + uint64(1), + ) + fee := types.Fee{ + validCoins, + validCoins2, + validCoins3, + } + identifiedPacketFee := &types.IdentifiedPacketFee{PacketId: packetId, Fee: fee, RefundAddress: refundAcc.String(), Relayers: []string{}} + err := suite.chainA.GetSimApp().IBCFeeKeeper.EscrowPacketFee(suite.chainA.GetContext(), identifiedPacketFee) + suite.Require().NoError(err) + + // relayer addresses + sender := suite.chainA.SenderAccount.GetAddress().String() + counterparty := suite.chainB.SenderAccount.GetAddress().String() + // set counterparty address + suite.chainA.GetSimApp().IBCFeeKeeper.SetCounterpartyAddress(suite.chainA.GetContext(), sender, counterparty) + + // export genesis + genesisState := suite.chainA.GetSimApp().IBCFeeKeeper.ExportGenesis(suite.chainA.GetContext()) + + // check fee enabled + suite.Require().Equal(ibctesting.FirstChannelID, genesisState.FeeEnabledChannels[0].ChannelId) + suite.Require().Equal(transfertypes.PortID, genesisState.FeeEnabledChannels[0].PortId) + + // check fee + suite.Require().Equal(packetId, genesisState.IdentifiedFees[0].PacketId) + suite.Require().Equal(fee, genesisState.IdentifiedFees[0].Fee) + suite.Require().Equal(refundAcc.String(), genesisState.IdentifiedFees[0].RefundAddress) + suite.Require().Equal([]string(nil), genesisState.IdentifiedFees[0].Relayers) + + // check registered relayer addresses + suite.Require().Equal(sender, genesisState.RegisteredRelayers[0].Address) + suite.Require().Equal(counterparty, genesisState.RegisteredRelayers[0].CounterpartyAddress) +} diff --git a/modules/apps/29-fee/keeper/grpc_query_test.go b/modules/apps/29-fee/keeper/grpc_query_test.go index 899df77d5bd..1403326837a 100644 --- a/modules/apps/29-fee/keeper/grpc_query_test.go +++ b/modules/apps/29-fee/keeper/grpc_query_test.go @@ -17,8 +17,8 @@ func (suite *KeeperTestSuite) TestQueryIncentivizedPacket() { ) // setup - validPacketId := types.NewPacketId(ibctesting.FirstChannelID, 1) - invalidPacketId := types.NewPacketId(ibctesting.FirstChannelID, 2) + validPacketId := types.NewPacketId(ibctesting.FirstChannelID, types.PortID, 1) + invalidPacketId := types.NewPacketId(ibctesting.FirstChannelID, types.PortID, 2) identifiedPacketFee := types.NewIdentifiedPacketFee( validPacketId, types.Fee{ @@ -110,9 +110,9 @@ func (suite *KeeperTestSuite) TestQueryIncentivizedPackets() { func() { refundAcc := suite.chainA.SenderAccount.GetAddress() - fee1 := types.NewIdentifiedPacketFee(types.NewPacketId(ibctesting.FirstChannelID, 1), fee, refundAcc.String(), []string(nil)) - fee2 := types.NewIdentifiedPacketFee(types.NewPacketId(ibctesting.FirstChannelID, 2), fee, refundAcc.String(), []string(nil)) - fee3 := types.NewIdentifiedPacketFee(types.NewPacketId(ibctesting.FirstChannelID, 3), fee, refundAcc.String(), []string(nil)) + fee1 := types.NewIdentifiedPacketFee(types.NewPacketId(ibctesting.FirstChannelID, types.PortID, 1), fee, refundAcc.String(), []string(nil)) + fee2 := types.NewIdentifiedPacketFee(types.NewPacketId(ibctesting.FirstChannelID, types.PortID, 2), fee, refundAcc.String(), []string(nil)) + fee3 := types.NewIdentifiedPacketFee(types.NewPacketId(ibctesting.FirstChannelID, types.PortID, 3), fee, refundAcc.String(), []string(nil)) expPackets = []*types.IdentifiedPacketFee{} expPackets = append(expPackets, fee1, fee2, fee3) diff --git a/modules/apps/29-fee/keeper/keeper.go b/modules/apps/29-fee/keeper/keeper.go index 3691204d2a6..1fda4910bc2 100644 --- a/modules/apps/29-fee/keeper/keeper.go +++ b/modules/apps/29-fee/keeper/keeper.go @@ -1,11 +1,12 @@ package keeper import ( + "strings" + "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" - "github.com/tendermint/tendermint/libs/log" "github.com/cosmos/ibc-go/modules/apps/29-fee/types" @@ -53,17 +54,17 @@ func (k Keeper) Logger(ctx sdk.Context) log.Logger { return ctx.Logger().With("module", "x/"+host.ModuleName+"-"+types.ModuleName) } +// ChanCloseInit wraps the channel keeper's function in order to expose it to underlying app. +func (k Keeper) ChanCloseInit(ctx sdk.Context, portID, channelID string, chanCap *capabilitytypes.Capability) error { + return k.channelKeeper.ChanCloseInit(ctx, portID, channelID, chanCap) +} + // BindPort defines a wrapper function for the port Keeper's function in // order to expose it to module's InitGenesis function func (k Keeper) BindPort(ctx sdk.Context, portID string) *capabilitytypes.Capability { return k.portKeeper.BindPort(ctx, portID) } -// ChanCloseInit wraps the channel keeper's function in order to expose it to underlying app. -func (k Keeper) ChanCloseInit(ctx sdk.Context, portID, channelID string, chanCap *capabilitytypes.Capability) error { - return k.channelKeeper.ChanCloseInit(ctx, portID, channelID, chanCap) -} - // GetChannel wraps IBC ChannelKeeper's GetChannel function func (k Keeper) GetChannel(ctx sdk.Context, portID, channelID string) (channeltypes.Channel, bool) { return k.channelKeeper.GetChannel(ctx, portID, channelID) @@ -104,6 +105,27 @@ func (k Keeper) IsFeeEnabled(ctx sdk.Context, portID, channelID string) bool { return store.Get(types.FeeEnabledKey(portID, channelID)) != nil } +// GetAllFeeEnabledChannels returns a list of all ics29 enabled channels containing portID & channelID that are stored in state +func (k Keeper) GetAllFeeEnabledChannels(ctx sdk.Context) []*types.FeeEnabledChannel { + store := ctx.KVStore(k.storeKey) + iterator := sdk.KVStorePrefixIterator(store, []byte(types.FeeEnabledKeyPrefix)) + defer iterator.Close() + + var enabledChArr []*types.FeeEnabledChannel + for ; iterator.Valid(); iterator.Next() { + keySplit := strings.Split(string(iterator.Key()), "/") + + ch := &types.FeeEnabledChannel{ + PortId: keySplit[1], + ChannelId: keySplit[2], + } + + enabledChArr = append(enabledChArr, ch) + } + + return enabledChArr +} + // SetCounterpartyAddress maps the destination chain relayer address to the source relayer address // The receiving chain must store the mapping from: address -> counterpartyAddress for the given channel func (k Keeper) SetCounterpartyAddress(ctx sdk.Context, address, counterpartyAddress string) { @@ -124,6 +146,26 @@ func (k Keeper) GetCounterpartyAddress(ctx sdk.Context, address string) (string, return addr, true } +func (k Keeper) GetAllRelayerAddresses(ctx sdk.Context) []*types.RegisteredRelayerAddress { + store := ctx.KVStore(k.storeKey) + iterator := sdk.KVStorePrefixIterator(store, []byte(types.RelayerAddressKeyPrefix)) + defer iterator.Close() + + var registeredAddrArr []*types.RegisteredRelayerAddress + for ; iterator.Valid(); iterator.Next() { + keySplit := strings.Split(string(iterator.Key()), "/") + + addr := &types.RegisteredRelayerAddress{ + Address: keySplit[1], + CounterpartyAddress: string(iterator.Value()), + } + + registeredAddrArr = append(registeredAddrArr, addr) + } + + return registeredAddrArr +} + // Stores a Fee for a given packet in state func (k Keeper) SetFeeInEscrow(ctx sdk.Context, fee *types.IdentifiedPacketFee) { store := ctx.KVStore(k.storeKey) @@ -159,6 +201,21 @@ func (k Keeper) HasFeeInEscrow(ctx sdk.Context, packetId *channeltypes.PacketId) return store.Has(key) } +// GetAllIdentifiedPacketFees returns a list of all IdentifiedPacketFees that are stored in state +func (k Keeper) GetAllIdentifiedPacketFees(ctx sdk.Context) []*types.IdentifiedPacketFee { + store := ctx.KVStore(k.storeKey) + iterator := sdk.KVStorePrefixIterator(store, []byte(types.FeeInEscrowPrefix)) + defer iterator.Close() + + var identifiedFees []*types.IdentifiedPacketFee + for ; iterator.Valid(); iterator.Next() { + fee := k.MustUnmarshalFee(iterator.Value()) + identifiedFees = append(identifiedFees, &fee) + } + + return identifiedFees +} + // MustMarshalFee attempts to encode a Fee object and returns the // raw encoded bytes. It panics on error. func (k Keeper) MustMarshalFee(fee *types.IdentifiedPacketFee) []byte { diff --git a/modules/apps/29-fee/keeper/keeper_test.go b/modules/apps/29-fee/keeper/keeper_test.go index 476a14698b0..f4315baa3b6 100644 --- a/modules/apps/29-fee/keeper/keeper_test.go +++ b/modules/apps/29-fee/keeper/keeper_test.go @@ -66,3 +66,75 @@ func SetupFeePath(path *ibctesting.Path) error { func TestKeeperTestSuite(t *testing.T) { suite.Run(t, new(KeeperTestSuite)) } + +func (suite *KeeperTestSuite) TestGetAllIdentifiedPacketFees() { + // escrow a fee + refundAcc := suite.chainA.SenderAccount.GetAddress() + ackFee := validCoins + receiveFee := validCoins2 + timeoutFee := validCoins3 + packetId := &channeltypes.PacketId{ChannelId: ibctesting.FirstChannelID, PortId: types.PortID, Sequence: uint64(1)} + fee := types.Fee{ackFee, receiveFee, timeoutFee} + identifiedPacketFee := &types.IdentifiedPacketFee{PacketId: packetId, Fee: fee, RefundAddress: refundAcc.String(), Relayers: []string{}} + + // escrow the packet fee + err := suite.chainA.GetSimApp().IBCFeeKeeper.EscrowPacketFee(suite.chainA.GetContext(), identifiedPacketFee) + suite.Require().NoError(err) + + expectedFees := []*types.IdentifiedPacketFee{ + { + PacketId: packetId, + Fee: fee, + RefundAddress: refundAcc.String(), + Relayers: nil, + }, + } + + fees := suite.chainA.GetSimApp().IBCFeeKeeper.GetAllIdentifiedPacketFees(suite.chainA.GetContext()) + suite.Require().Len(fees, len(expectedFees)) + suite.Require().Equal(fees, expectedFees) +} + +func (suite *KeeperTestSuite) TestGetAllFeeEnabledChannels() { + suite.SetupTest() // reset + + validPortId := "ibcmoduleport" + // set two channels enabled + suite.chainA.GetSimApp().IBCFeeKeeper.SetFeeEnabled(suite.chainA.GetContext(), transfertypes.PortID, ibctesting.FirstChannelID) + suite.chainA.GetSimApp().IBCFeeKeeper.SetFeeEnabled(suite.chainA.GetContext(), validPortId, ibctesting.FirstChannelID) + + expectedCh := []*types.FeeEnabledChannel{ + { + PortId: validPortId, + ChannelId: ibctesting.FirstChannelID, + }, + { + PortId: transfertypes.PortID, + ChannelId: ibctesting.FirstChannelID, + }, + } + + ch := suite.chainA.GetSimApp().IBCFeeKeeper.GetAllFeeEnabledChannels(suite.chainA.GetContext()) + suite.Require().Len(ch, len(expectedCh)) + suite.Require().Equal(ch, expectedCh) +} + +func (suite *KeeperTestSuite) TestGetAllRelayerAddresses() { + suite.SetupTest() // reset + + sender := suite.chainA.SenderAccount.GetAddress().String() + counterparty := suite.chainB.SenderAccount.GetAddress().String() + + suite.chainA.GetSimApp().IBCFeeKeeper.SetCounterpartyAddress(suite.chainA.GetContext(), sender, counterparty) + + expectedAddr := []*types.RegisteredRelayerAddress{ + { + Address: sender, + CounterpartyAddress: counterparty, + }, + } + + addr := suite.chainA.GetSimApp().IBCFeeKeeper.GetAllRelayerAddresses(suite.chainA.GetContext()) + suite.Require().Len(addr, len(expectedAddr)) + suite.Require().Equal(addr, expectedAddr) +} diff --git a/modules/apps/29-fee/module.go b/modules/apps/29-fee/module.go index 61e39846584..78b9dc6d091 100644 --- a/modules/apps/29-fee/module.go +++ b/modules/apps/29-fee/module.go @@ -3,6 +3,7 @@ package fee import ( "context" "encoding/json" + "fmt" "math/rand" "github.com/cosmos/cosmos-sdk/client" @@ -51,19 +52,18 @@ func (AppModuleBasic) RegisterInterfaces(registry codectypes.InterfaceRegistry) // DefaultGenesis returns default genesis state as raw bytes for the ibc // 29-fee module. func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage { - // return cdc.MustMarshalJSON(types.DefaultGenesisState()) + return cdc.MustMarshalJSON(types.DefaultGenesisState()) return nil } // ValidateGenesis performs genesis state validation for the 29-fee module. func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, config client.TxEncodingConfig, bz json.RawMessage) error { - // var gs types.GenesisState - // if err := cdc.UnmarshalJSON(bz, &gs); err != nil { - // return fmt.Errorf("failed to unmarshal %s genesis state: %w", types.ModuleName, err) - // } + var gs types.GenesisState + if err := cdc.UnmarshalJSON(bz, &gs); err != nil { + return fmt.Errorf("failed to unmarshal %s genesis state: %w", types.ModuleName, err) + } - // return gs.Validate() - return nil + return gs.Validate() } // RegisterRESTRoutes implements AppModuleBasic interface @@ -127,18 +127,17 @@ func (am AppModule) RegisterServices(cfg module.Configurator) { // InitGenesis performs genesis initialization for the ibc-29-fee module. It returns // no validator updates. func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, data json.RawMessage) []abci.ValidatorUpdate { - // var genesisState types.GenesisState - // cdc.MustUnmarshalJSON(data, &genesisState) - // am.keeper.InitGenesis(ctx, genesisState) + var genesisState types.GenesisState + cdc.MustUnmarshalJSON(data, &genesisState) + am.keeper.InitGenesis(ctx, genesisState) return []abci.ValidatorUpdate{} } // ExportGenesis returns the exported genesis state as raw bytes for the ibc-29-fee // module. func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.RawMessage { - // gs := am.keeper.ExportGenesis(ctx) - // return cdc.MustMarshalJSON(gs) - return nil + gs := am.keeper.ExportGenesis(ctx) + return cdc.MustMarshalJSON(gs) } // ConsensusVersion implements AppModule/ConsensusVersion. diff --git a/modules/apps/29-fee/types/genesis.go b/modules/apps/29-fee/types/genesis.go index 4086325bebb..3f85192d930 100644 --- a/modules/apps/29-fee/types/genesis.go +++ b/modules/apps/29-fee/types/genesis.go @@ -1,29 +1,25 @@ package types -/* -import ( - host "github.com/cosmos/ibc-go/modules/core/24-host" -) - // NewGenesisState creates a 29-fee GenesisState instance. -func NewGenesisState(portID string, denomTraces Traces, params Params) *GenesisState { +func NewGenesisState(identifiedFees []*IdentifiedPacketFee, feeEnabledChannels []*FeeEnabledChannel, registeredRelayers []*RegisteredRelayerAddress) *GenesisState { return &GenesisState{ - Params: params, + IdentifiedFees: identifiedFees, + FeeEnabledChannels: feeEnabledChannels, + RegisteredRelayers: registeredRelayers, } } // DefaultGenesisState returns a GenesisState with "transfer" as the default PortID. func DefaultGenesisState() *GenesisState { return &GenesisState{ + IdentifiedFees: []*IdentifiedPacketFee{}, + FeeEnabledChannels: []*FeeEnabledChannel{}, + RegisteredRelayers: []*RegisteredRelayerAddress{}, } } // Validate performs basic genesis state validation returning an error upon any // failure. func (gs GenesisState) Validate() error { - if err := host.PortIdentifierValidator(gs.PortId); err != nil { - return err - } return nil } -*/ diff --git a/modules/apps/29-fee/types/genesis.pb.go b/modules/apps/29-fee/types/genesis.pb.go index b07a497011f..80a2e44d3df 100644 --- a/modules/apps/29-fee/types/genesis.pb.go +++ b/modules/apps/29-fee/types/genesis.pb.go @@ -25,6 +25,9 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package // GenesisState defines the fee middleware genesis state type GenesisState struct { + IdentifiedFees []*IdentifiedPacketFee `protobuf:"bytes,1,rep,name=identified_fees,json=identifiedFees,proto3" json:"identified_fees,omitempty" yaml:"identified_fees"` + FeeEnabledChannels []*FeeEnabledChannel `protobuf:"bytes,2,rep,name=fee_enabled_channels,json=feeEnabledChannels,proto3" json:"fee_enabled_channels,omitempty" yaml:"fee_enabled_channels"` + RegisteredRelayers []*RegisteredRelayerAddress `protobuf:"bytes,3,rep,name=registered_relayers,json=registeredRelayers,proto3" json:"registered_relayers,omitempty" yaml:"registered_relayers"` } func (m *GenesisState) Reset() { *m = GenesisState{} } @@ -60,8 +63,137 @@ func (m *GenesisState) XXX_DiscardUnknown() { var xxx_messageInfo_GenesisState proto.InternalMessageInfo +func (m *GenesisState) GetIdentifiedFees() []*IdentifiedPacketFee { + if m != nil { + return m.IdentifiedFees + } + return nil +} + +func (m *GenesisState) GetFeeEnabledChannels() []*FeeEnabledChannel { + if m != nil { + return m.FeeEnabledChannels + } + return nil +} + +func (m *GenesisState) GetRegisteredRelayers() []*RegisteredRelayerAddress { + if m != nil { + return m.RegisteredRelayers + } + return nil +} + +// Contains the PortID & ChannelID for a fee enabled channel +type FeeEnabledChannel struct { + PortId string `protobuf:"bytes,1,opt,name=port_id,json=portId,proto3" json:"port_id,omitempty" yaml:"port_id"` + ChannelId string `protobuf:"bytes,2,opt,name=channel_id,json=channelId,proto3" json:"channel_id,omitempty" yaml:"channel_id"` +} + +func (m *FeeEnabledChannel) Reset() { *m = FeeEnabledChannel{} } +func (m *FeeEnabledChannel) String() string { return proto.CompactTextString(m) } +func (*FeeEnabledChannel) ProtoMessage() {} +func (*FeeEnabledChannel) Descriptor() ([]byte, []int) { + return fileDescriptor_7191992e856dff95, []int{1} +} +func (m *FeeEnabledChannel) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *FeeEnabledChannel) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_FeeEnabledChannel.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *FeeEnabledChannel) XXX_Merge(src proto.Message) { + xxx_messageInfo_FeeEnabledChannel.Merge(m, src) +} +func (m *FeeEnabledChannel) XXX_Size() int { + return m.Size() +} +func (m *FeeEnabledChannel) XXX_DiscardUnknown() { + xxx_messageInfo_FeeEnabledChannel.DiscardUnknown(m) +} + +var xxx_messageInfo_FeeEnabledChannel proto.InternalMessageInfo + +func (m *FeeEnabledChannel) GetPortId() string { + if m != nil { + return m.PortId + } + return "" +} + +func (m *FeeEnabledChannel) GetChannelId() string { + if m != nil { + return m.ChannelId + } + return "" +} + +// Contains the address and counterparty address for a specific relayer (for distributing fees) +type RegisteredRelayerAddress struct { + Address string `protobuf:"bytes,1,opt,name=address,proto3" json:"address,omitempty"` + CounterpartyAddress string `protobuf:"bytes,2,opt,name=counterparty_address,json=counterpartyAddress,proto3" json:"counterparty_address,omitempty" yaml:"counterparty_address"` +} + +func (m *RegisteredRelayerAddress) Reset() { *m = RegisteredRelayerAddress{} } +func (m *RegisteredRelayerAddress) String() string { return proto.CompactTextString(m) } +func (*RegisteredRelayerAddress) ProtoMessage() {} +func (*RegisteredRelayerAddress) Descriptor() ([]byte, []int) { + return fileDescriptor_7191992e856dff95, []int{2} +} +func (m *RegisteredRelayerAddress) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *RegisteredRelayerAddress) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_RegisteredRelayerAddress.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *RegisteredRelayerAddress) XXX_Merge(src proto.Message) { + xxx_messageInfo_RegisteredRelayerAddress.Merge(m, src) +} +func (m *RegisteredRelayerAddress) XXX_Size() int { + return m.Size() +} +func (m *RegisteredRelayerAddress) XXX_DiscardUnknown() { + xxx_messageInfo_RegisteredRelayerAddress.DiscardUnknown(m) +} + +var xxx_messageInfo_RegisteredRelayerAddress proto.InternalMessageInfo + +func (m *RegisteredRelayerAddress) GetAddress() string { + if m != nil { + return m.Address + } + return "" +} + +func (m *RegisteredRelayerAddress) GetCounterpartyAddress() string { + if m != nil { + return m.CounterpartyAddress + } + return "" +} + func init() { proto.RegisterType((*GenesisState)(nil), "ibc.applications.fee.v1.GenesisState") + proto.RegisterType((*FeeEnabledChannel)(nil), "ibc.applications.fee.v1.FeeEnabledChannel") + proto.RegisterType((*RegisteredRelayerAddress)(nil), "ibc.applications.fee.v1.RegisteredRelayerAddress") } func init() { @@ -69,19 +201,37 @@ func init() { } var fileDescriptor_7191992e856dff95 = []byte{ - // 192 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0xcd, 0x4c, 0x4a, 0xd6, - 0x4f, 0x2c, 0x28, 0xc8, 0xc9, 0x4c, 0x4e, 0x2c, 0xc9, 0xcc, 0xcf, 0x2b, 0xd6, 0x4f, 0x4b, 0x4d, - 0xd5, 0x2f, 0x33, 0xd4, 0x4f, 0x4f, 0xcd, 0x4b, 0x2d, 0xce, 0x2c, 0xd6, 0x2b, 0x28, 0xca, 0x2f, - 0xc9, 0x17, 0x12, 0xcf, 0x4c, 0x4a, 0xd6, 0x43, 0x56, 0xa6, 0x97, 0x96, 0x9a, 0xaa, 0x57, 0x66, - 0x28, 0x25, 0x92, 0x9e, 0x9f, 0x9e, 0x0f, 0x56, 0xa3, 0x0f, 0x62, 0x41, 0x94, 0x4b, 0x29, 0xe2, - 0x32, 0x15, 0xa4, 0x0b, 0xac, 0x44, 0x89, 0x8f, 0x8b, 0xc7, 0x1d, 0x62, 0x45, 0x70, 0x49, 0x62, - 0x49, 0xaa, 0x93, 0xcf, 0x89, 0x47, 0x72, 0x8c, 0x17, 0x1e, 0xc9, 0x31, 0x3e, 0x78, 0x24, 0xc7, - 0x38, 0xe1, 0xb1, 0x1c, 0xc3, 0x85, 0xc7, 0x72, 0x0c, 0x37, 0x1e, 0xcb, 0x31, 0x44, 0x19, 0xa5, - 0x67, 0x96, 0x64, 0x94, 0x26, 0xe9, 0x25, 0xe7, 0xe7, 0xea, 0x27, 0xe7, 0x17, 0xe7, 0xe6, 0x17, - 0xeb, 0x67, 0x26, 0x25, 0xeb, 0xa6, 0xe7, 0xeb, 0xe7, 0xe6, 0xa7, 0x94, 0xe6, 0xa4, 0x16, 0x83, - 0x6c, 0x2a, 0xd6, 0x37, 0xb2, 0xd4, 0x05, 0x59, 0x52, 0x52, 0x59, 0x90, 0x5a, 0x9c, 0xc4, 0x06, - 0xb6, 0xc4, 0x18, 0x10, 0x00, 0x00, 0xff, 0xff, 0x90, 0xf8, 0xaf, 0x33, 0xdf, 0x00, 0x00, 0x00, + // 470 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x92, 0x41, 0x8b, 0xd3, 0x40, + 0x14, 0xc7, 0x9b, 0x2d, 0xec, 0xb2, 0xa3, 0xac, 0xec, 0x6c, 0xd5, 0x50, 0x21, 0x59, 0x07, 0x84, + 0x45, 0xdd, 0x84, 0x56, 0x2f, 0x7a, 0xb3, 0x62, 0xa5, 0xe0, 0x41, 0xc6, 0x9b, 0x97, 0x30, 0xc9, + 0xbc, 0x64, 0x07, 0xd3, 0x4c, 0x9c, 0x99, 0x16, 0x7a, 0xf0, 0x22, 0x08, 0x1e, 0xfd, 0x58, 0x1e, + 0xf7, 0xe8, 0xa9, 0x48, 0xfb, 0x0d, 0xfa, 0x09, 0x24, 0x99, 0x76, 0xb7, 0xd4, 0xe6, 0xf6, 0x66, + 0xde, 0xef, 0xff, 0xff, 0xe7, 0x65, 0x1e, 0x7a, 0x22, 0xe2, 0x24, 0x64, 0x65, 0x99, 0x8b, 0x84, + 0x19, 0x21, 0x0b, 0x1d, 0xa6, 0x00, 0xe1, 0xb4, 0x17, 0x66, 0x50, 0x80, 0x16, 0x3a, 0x28, 0x95, + 0x34, 0x12, 0x3f, 0x14, 0x71, 0x12, 0x6c, 0x63, 0x41, 0x0a, 0x10, 0x4c, 0x7b, 0xdd, 0x4e, 0x26, + 0x33, 0x59, 0x33, 0x61, 0x55, 0x59, 0xbc, 0xfb, 0xb8, 0xc9, 0xb5, 0x52, 0xd5, 0x08, 0xf9, 0xd1, + 0x46, 0x77, 0xdf, 0xdb, 0x8c, 0x4f, 0x86, 0x19, 0xc0, 0x5f, 0xd1, 0x3d, 0xc1, 0xa1, 0x30, 0x22, + 0x15, 0xc0, 0xa3, 0x14, 0x40, 0xbb, 0xce, 0x79, 0xfb, 0xe2, 0x4e, 0xff, 0x79, 0xd0, 0x10, 0x1e, + 0x8c, 0x6e, 0xf8, 0x8f, 0x2c, 0xf9, 0x02, 0x66, 0x08, 0x30, 0xe8, 0xae, 0xe6, 0xfe, 0x83, 0x19, + 0x1b, 0xe7, 0xaf, 0xc9, 0x8e, 0x1d, 0xa1, 0x27, 0xb7, 0x37, 0x43, 0x00, 0x8d, 0xbf, 0xa1, 0x4e, + 0x0a, 0x10, 0x41, 0xc1, 0xe2, 0x1c, 0x78, 0x94, 0x5c, 0xb1, 0xa2, 0x80, 0x5c, 0xbb, 0x07, 0x75, + 0xee, 0xd3, 0xc6, 0xdc, 0x21, 0xc0, 0x3b, 0xab, 0x79, 0x6b, 0x25, 0x03, 0x7f, 0x35, 0xf7, 0x1f, + 0xd9, 0xd4, 0x7d, 0x8e, 0x84, 0xe2, 0x74, 0x57, 0xa3, 0xf1, 0x77, 0x07, 0x9d, 0x29, 0xc8, 0x84, + 0x36, 0xa0, 0x80, 0x47, 0x0a, 0x72, 0x36, 0x03, 0xa5, 0xdd, 0x76, 0x1d, 0xdf, 0x6b, 0x8c, 0xa7, + 0x37, 0x1a, 0x6a, 0x25, 0x6f, 0x38, 0x57, 0xa0, 0xf5, 0xc0, 0x5b, 0xcd, 0xfd, 0xae, 0xfd, 0x8a, + 0x3d, 0xbe, 0x84, 0x62, 0xb5, 0xab, 0xd4, 0x64, 0x8a, 0x4e, 0xff, 0x1b, 0x07, 0x3f, 0x43, 0x47, + 0xa5, 0x54, 0x26, 0x12, 0xdc, 0x75, 0xce, 0x9d, 0x8b, 0xe3, 0x01, 0x5e, 0xcd, 0xfd, 0x13, 0xeb, + 0xbc, 0x6e, 0x10, 0x7a, 0x58, 0x55, 0x23, 0x8e, 0x5f, 0x22, 0xb4, 0x9e, 0xb3, 0xe2, 0x0f, 0x6a, + 0xfe, 0xfe, 0x6a, 0xee, 0x9f, 0x5a, 0xfe, 0xb6, 0x47, 0xe8, 0xf1, 0xfa, 0x30, 0xe2, 0xe4, 0xa7, + 0x83, 0xdc, 0xa6, 0x41, 0xb0, 0x8b, 0x8e, 0x98, 0x2d, 0x6d, 0x3e, 0xdd, 0x1c, 0x31, 0x45, 0x9d, + 0x44, 0x4e, 0x0a, 0x03, 0xaa, 0x64, 0xca, 0xcc, 0xa2, 0x0d, 0x66, 0x63, 0xb7, 0x9e, 0x61, 0x1f, + 0x45, 0xe8, 0xd9, 0xf6, 0xf5, 0xe6, 0xb7, 0x7d, 0xf8, 0xbd, 0xf0, 0x9c, 0xeb, 0x85, 0xe7, 0xfc, + 0x5d, 0x78, 0xce, 0xaf, 0xa5, 0xd7, 0xba, 0x5e, 0x7a, 0xad, 0x3f, 0x4b, 0xaf, 0xf5, 0xb9, 0x9f, + 0x09, 0x73, 0x35, 0x89, 0x83, 0x44, 0x8e, 0xc3, 0x44, 0xea, 0xb1, 0xd4, 0xa1, 0x88, 0x93, 0xcb, + 0x4c, 0x86, 0x63, 0xc9, 0x27, 0x39, 0xe8, 0x6a, 0xc9, 0x75, 0xd8, 0x7f, 0x75, 0x59, 0xed, 0xb7, + 0x99, 0x95, 0xa0, 0xe3, 0xc3, 0x7a, 0xbf, 0x5f, 0xfc, 0x0b, 0x00, 0x00, 0xff, 0xff, 0x14, 0xf8, + 0xcc, 0x98, 0x5a, 0x03, 0x00, 0x00, } func (m *GenesisState) Marshal() (dAtA []byte, err error) { @@ -104,6 +254,122 @@ func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if len(m.RegisteredRelayers) > 0 { + for iNdEx := len(m.RegisteredRelayers) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.RegisteredRelayers[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + } + } + if len(m.FeeEnabledChannels) > 0 { + for iNdEx := len(m.FeeEnabledChannels) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.FeeEnabledChannels[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + } + if len(m.IdentifiedFees) > 0 { + for iNdEx := len(m.IdentifiedFees) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.IdentifiedFees[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + } + return len(dAtA) - i, nil +} + +func (m *FeeEnabledChannel) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *FeeEnabledChannel) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *FeeEnabledChannel) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.ChannelId) > 0 { + i -= len(m.ChannelId) + copy(dAtA[i:], m.ChannelId) + i = encodeVarintGenesis(dAtA, i, uint64(len(m.ChannelId))) + i-- + dAtA[i] = 0x12 + } + if len(m.PortId) > 0 { + i -= len(m.PortId) + copy(dAtA[i:], m.PortId) + i = encodeVarintGenesis(dAtA, i, uint64(len(m.PortId))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *RegisteredRelayerAddress) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *RegisteredRelayerAddress) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *RegisteredRelayerAddress) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.CounterpartyAddress) > 0 { + i -= len(m.CounterpartyAddress) + copy(dAtA[i:], m.CounterpartyAddress) + i = encodeVarintGenesis(dAtA, i, uint64(len(m.CounterpartyAddress))) + i-- + dAtA[i] = 0x12 + } + if len(m.Address) > 0 { + i -= len(m.Address) + copy(dAtA[i:], m.Address) + i = encodeVarintGenesis(dAtA, i, uint64(len(m.Address))) + i-- + dAtA[i] = 0xa + } return len(dAtA) - i, nil } @@ -124,6 +390,58 @@ func (m *GenesisState) Size() (n int) { } var l int _ = l + if len(m.IdentifiedFees) > 0 { + for _, e := range m.IdentifiedFees { + l = e.Size() + n += 1 + l + sovGenesis(uint64(l)) + } + } + if len(m.FeeEnabledChannels) > 0 { + for _, e := range m.FeeEnabledChannels { + l = e.Size() + n += 1 + l + sovGenesis(uint64(l)) + } + } + if len(m.RegisteredRelayers) > 0 { + for _, e := range m.RegisteredRelayers { + l = e.Size() + n += 1 + l + sovGenesis(uint64(l)) + } + } + return n +} + +func (m *FeeEnabledChannel) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.PortId) + if l > 0 { + n += 1 + l + sovGenesis(uint64(l)) + } + l = len(m.ChannelId) + if l > 0 { + n += 1 + l + sovGenesis(uint64(l)) + } + return n +} + +func (m *RegisteredRelayerAddress) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Address) + if l > 0 { + n += 1 + l + sovGenesis(uint64(l)) + } + l = len(m.CounterpartyAddress) + if l > 0 { + n += 1 + l + sovGenesis(uint64(l)) + } return n } @@ -162,6 +480,336 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error { return fmt.Errorf("proto: GenesisState: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field IdentifiedFees", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.IdentifiedFees = append(m.IdentifiedFees, &IdentifiedPacketFee{}) + if err := m.IdentifiedFees[len(m.IdentifiedFees)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field FeeEnabledChannels", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.FeeEnabledChannels = append(m.FeeEnabledChannels, &FeeEnabledChannel{}) + if err := m.FeeEnabledChannels[len(m.FeeEnabledChannels)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field RegisteredRelayers", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.RegisteredRelayers = append(m.RegisteredRelayers, &RegisteredRelayerAddress{}) + if err := m.RegisteredRelayers[len(m.RegisteredRelayers)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipGenesis(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthGenesis + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *FeeEnabledChannel) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: FeeEnabledChannel: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: FeeEnabledChannel: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field PortId", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.PortId = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ChannelId", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ChannelId = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipGenesis(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthGenesis + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *RegisteredRelayerAddress) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: RegisteredRelayerAddress: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: RegisteredRelayerAddress: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Address", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Address = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field CounterpartyAddress", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.CounterpartyAddress = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipGenesis(dAtA[iNdEx:]) diff --git a/modules/apps/29-fee/types/keys.go b/modules/apps/29-fee/types/keys.go index 3df1f637a6c..522177c9aff 100644 --- a/modules/apps/29-fee/types/keys.go +++ b/modules/apps/29-fee/types/keys.go @@ -13,8 +13,8 @@ const ( // StoreKey is the store key string for IBC fee module StoreKey = ModuleName - // PortKey is the port id that is wrapped by fee middleware - PortKey = "feetransfer" + // PortID is the port id that is wrapped by fee middleware + PortID = "feetransfer" // RouterKey is the message route for IBC fee module RouterKey = ModuleName diff --git a/modules/apps/29-fee/types/msgs.go b/modules/apps/29-fee/types/msgs.go index 53bcc0b5b74..bd04c041bb5 100644 --- a/modules/apps/29-fee/types/msgs.go +++ b/modules/apps/29-fee/types/msgs.go @@ -171,6 +171,8 @@ func NewIdentifiedPacketFee(packetId *channeltypes.PacketId, fee Fee, refundAddr } } -func NewPacketId(channelId string, id uint64) *channeltypes.PacketId { - return &channeltypes.PacketId{ChannelId: channelId, PortId: PortKey, Sequence: id} +// NewPacketId returns a new instance of PacketId +// TODO: move to channeltypes +func NewPacketId(channelId, portId string, seq uint64) *channeltypes.PacketId { + return &channeltypes.PacketId{ChannelId: channelId, PortId: portId, Sequence: seq} } diff --git a/proto/ibc/applications/fee/v1/genesis.proto b/proto/ibc/applications/fee/v1/genesis.proto index 4006b5fdc9d..cef33b501a0 100644 --- a/proto/ibc/applications/fee/v1/genesis.proto +++ b/proto/ibc/applications/fee/v1/genesis.proto @@ -7,5 +7,19 @@ option go_package = "github.com/cosmos/ibc-go/modules/apps/29-fee/types"; // GenesisState defines the fee middleware genesis state message GenesisState { - // TODO + repeated IdentifiedPacketFee identified_fees = 1 [(gogoproto.moretags) = "yaml:\"identified_fees\""]; + repeated FeeEnabledChannel fee_enabled_channels = 2 [(gogoproto.moretags) = "yaml:\"fee_enabled_channels\""]; + repeated RegisteredRelayerAddress registered_relayers = 3 [(gogoproto.moretags) = "yaml:\"registered_relayers\""]; +} + +// Contains the PortID & ChannelID for a fee enabled channel +message FeeEnabledChannel { + string port_id = 1 [(gogoproto.moretags) = "yaml:\"port_id\""]; + string channel_id = 2 [(gogoproto.moretags) = "yaml:\"channel_id\""]; +} + +// Contains the address and counterparty address for a specific relayer (for distributing fees) +message RegisteredRelayerAddress { + string address = 1; + string counterparty_address = 2 [(gogoproto.moretags) = "yaml:\"counterparty_address\""]; }