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

feat: ics29 fee enabled channel queries #1225

Merged
merged 8 commits into from
Apr 7, 2022
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ Ref: https://keepachangelog.com/en/1.0.0/

* (apps/29-fee) [\#1224](https://github.com/cosmos/ibc-go/pull/1224) Adding Query/CounterpartyAddress and CLI to ICS29 fee middleware

* (apps/29-fee) [\#1225](https://github.com/cosmos/ibc-go/pull/1225) Adding Query/FeeEnabledChannel and Query/FeeEnabledChannels with CLIs to ICS29 fee middleware.

### Bug Fixes

* (modules/core/04-channel) [\#1130](https://github.com/cosmos/ibc-go/pull/1130) Call `packet.GetSequence()` rather than passing func in `WriteAcknowledgement` log output
Expand Down
68 changes: 68 additions & 0 deletions docs/ibc/proto-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@
- [ibc/applications/fee/v1/query.proto](#ibc/applications/fee/v1/query.proto)
- [QueryCounterpartyAddressRequest](#ibc.applications.fee.v1.QueryCounterpartyAddressRequest)
- [QueryCounterpartyAddressResponse](#ibc.applications.fee.v1.QueryCounterpartyAddressResponse)
- [QueryFeeEnabledChannelRequest](#ibc.applications.fee.v1.QueryFeeEnabledChannelRequest)
- [QueryFeeEnabledChannelResponse](#ibc.applications.fee.v1.QueryFeeEnabledChannelResponse)
- [QueryFeeEnabledChannelsRequest](#ibc.applications.fee.v1.QueryFeeEnabledChannelsRequest)
- [QueryFeeEnabledChannelsResponse](#ibc.applications.fee.v1.QueryFeeEnabledChannelsResponse)
- [QueryIncentivizedPacketRequest](#ibc.applications.fee.v1.QueryIncentivizedPacketRequest)
- [QueryIncentivizedPacketResponse](#ibc.applications.fee.v1.QueryIncentivizedPacketResponse)
- [QueryIncentivizedPacketsForChannelRequest](#ibc.applications.fee.v1.QueryIncentivizedPacketsForChannelRequest)
Expand Down Expand Up @@ -939,6 +943,68 @@ QueryCounterpartyAddressResponse defines the response type for the CounterpartyA



<a name="ibc.applications.fee.v1.QueryFeeEnabledChannelRequest"></a>

### QueryFeeEnabledChannelRequest
QueryFeeEnabledChannelRequest defines the request type for the FeeEnabledChannel rpc


| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `port_id` | [string](#string) | | unique port identifier |
| `channel_id` | [string](#string) | | unique channel identifier |






<a name="ibc.applications.fee.v1.QueryFeeEnabledChannelResponse"></a>

### QueryFeeEnabledChannelResponse
QueryFeeEnabledChannelResponse defines the response type for the FeeEnabledChannel rpc


| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `fee_enabled` | [bool](#bool) | | boolean flag representing the fee enabled channel status |






<a name="ibc.applications.fee.v1.QueryFeeEnabledChannelsRequest"></a>

### QueryFeeEnabledChannelsRequest
QueryFeeEnabledChannelsRequest defines the request type for the FeeEnabledChannels rpc


| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `pagination` | [cosmos.base.query.v1beta1.PageRequest](#cosmos.base.query.v1beta1.PageRequest) | | pagination defines an optional pagination for the request. |
| `query_height` | [uint64](#uint64) | | block height at which to query |






<a name="ibc.applications.fee.v1.QueryFeeEnabledChannelsResponse"></a>

### QueryFeeEnabledChannelsResponse
QueryFeeEnabledChannelsResponse defines the response type for the FeeEnabledChannels rpc


| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `fee_enabled_channels` | [FeeEnabledChannel](#ibc.applications.fee.v1.FeeEnabledChannel) | repeated | list of fee enabled channels |






<a name="ibc.applications.fee.v1.QueryIncentivizedPacketRequest"></a>

### QueryIncentivizedPacketRequest
Expand Down Expand Up @@ -1145,6 +1211,8 @@ Query defines the ICS29 gRPC querier service.
| `TotalAckFees` | [QueryTotalAckFeesRequest](#ibc.applications.fee.v1.QueryTotalAckFeesRequest) | [QueryTotalAckFeesResponse](#ibc.applications.fee.v1.QueryTotalAckFeesResponse) | TotalAckFees returns the total acknowledgement fees for a packet given its identifier | GET|/ibc/apps/fee/v1/total_ack_fees/port/{packet_id.port_id}/channel/{packet_id.channel_id}/sequence/{packet_id.sequence}|
| `TotalTimeoutFees` | [QueryTotalTimeoutFeesRequest](#ibc.applications.fee.v1.QueryTotalTimeoutFeesRequest) | [QueryTotalTimeoutFeesResponse](#ibc.applications.fee.v1.QueryTotalTimeoutFeesResponse) | TotalTimeoutFees returns the total timeout fees for a packet given its identifier | GET|/ibc/apps/fee/v1/total_timeout_fees/port/{packet_id.port_id}/channel/{packet_id.channel_id}/sequence/{packet_id.sequence}|
| `CounterpartyAddress` | [QueryCounterpartyAddressRequest](#ibc.applications.fee.v1.QueryCounterpartyAddressRequest) | [QueryCounterpartyAddressResponse](#ibc.applications.fee.v1.QueryCounterpartyAddressResponse) | CounterpartyAddress returns the registered counterparty address for forward relaying | GET|/ibc/apps/fee/v1/counterparty_address/{relayer_address}/channel/{channel_id}|
| `FeeEnabledChannels` | [QueryFeeEnabledChannelsRequest](#ibc.applications.fee.v1.QueryFeeEnabledChannelsRequest) | [QueryFeeEnabledChannelsResponse](#ibc.applications.fee.v1.QueryFeeEnabledChannelsResponse) | FeeEnabledChannels returns a list of all fee enabled channels | GET|/ibc/apps/fee/v1/fee_enabled|
| `FeeEnabledChannel` | [QueryFeeEnabledChannelRequest](#ibc.applications.fee.v1.QueryFeeEnabledChannelRequest) | [QueryFeeEnabledChannelResponse](#ibc.applications.fee.v1.QueryFeeEnabledChannelResponse) | FeeEnabledChannel returns true if the provided port and channel identifiers belong to a fee enabled channel | GET|/ibc/apps/fee/v1/fee_enabled/port/{port_id}/channel/{channel_id}|

<!-- end services -->

Expand Down
2 changes: 2 additions & 0 deletions modules/apps/29-fee/client/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ func GetQueryCmd() *cobra.Command {
GetCmdTotalAckFees(),
GetCmdTotalTimeoutFees(),
GetCmdCounterpartyAddress(),
GetCmdFeeEnabledChannel(),
GetCmdFeeEnabledChannels(),
)

return queryCmd
Expand Down
76 changes: 76 additions & 0 deletions modules/apps/29-fee/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,3 +274,79 @@ func GetCmdCounterpartyAddress() *cobra.Command {

return cmd
}

// GetCmdFeeEnabledChannels returns the command handler for the Query/FeeEnabledChannels rpc.
func GetCmdFeeEnabledChannels() *cobra.Command {
cmd := &cobra.Command{
Use: "channels",
Short: "Query the ibc-fee enabled channels",
Long: "Query the ibc-fee enabled channels",
Args: cobra.NoArgs,
Example: fmt.Sprintf("%s query ibc-fee channels", version.AppName),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}

pageReq, err := client.ReadPageRequest(cmd.Flags())
if err != nil {
return err
}

req := &types.QueryFeeEnabledChannelsRequest{
Pagination: pageReq,
QueryHeight: uint64(clientCtx.Height),
}

queryClient := types.NewQueryClient(clientCtx)

res, err := queryClient.FeeEnabledChannels(cmd.Context(), req)
if err != nil {
return err
}

return clientCtx.PrintProto(res)
},
}

flags.AddQueryFlagsToCmd(cmd)
flags.AddPaginationFlagsToCmd(cmd, "channels")

return cmd
}

// GetCmdFeeEnabledChannel returns the command handler for the Query/FeeEnabledChannel rpc.
func GetCmdFeeEnabledChannel() *cobra.Command {
cmd := &cobra.Command{
Use: "channel [port-id] [channel-id]",
Short: "Query the ibc-fee enabled status of a channel",
Long: "Query the ibc-fee enabled status of a channel",
Args: cobra.ExactArgs(2),
Example: fmt.Sprintf("%s query ibc-fee channel transfer channel-6", version.AppName),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}

req := &types.QueryFeeEnabledChannelRequest{
PortId: args[0],
ChannelId: args[1],
}

queryClient := types.NewQueryClient(clientCtx)

res, err := queryClient.FeeEnabledChannel(cmd.Context(), req)
if err != nil {
return err
}

return clientCtx.PrintProto(res)
},
}

flags.AddQueryFlagsToCmd(cmd)

return cmd
}
51 changes: 51 additions & 0 deletions modules/apps/29-fee/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,3 +191,54 @@ func (k Keeper) CounterpartyAddress(goCtx context.Context, req *types.QueryCount
CounterpartyAddress: counterpartyAddr,
}, nil
}

// FeeEnabledChannels implements the Query/FeeEnabledChannels gRPC method and returns a list of fee enabled channels
func (k Keeper) FeeEnabledChannels(goCtx context.Context, req *types.QueryFeeEnabledChannelsRequest) (*types.QueryFeeEnabledChannelsResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "empty request")
}

ctx := sdk.UnwrapSDKContext(goCtx).WithBlockHeight(int64(req.QueryHeight))

var feeEnabledChannels []types.FeeEnabledChannel
store := prefix.NewStore(ctx.KVStore(k.storeKey), []byte(types.FeeEnabledKeyPrefix))
_, err := query.Paginate(store, req.Pagination, func(key, value []byte) error {
portID, channelID, err := types.ParseKeyFeeEnabled(types.FeeEnabledKeyPrefix + string(key))
if err != nil {
return err
}

feeEnabledChannel := types.FeeEnabledChannel{
PortId: portID,
ChannelId: channelID,
}

feeEnabledChannels = append(feeEnabledChannels, feeEnabledChannel)

return nil
})

if err != nil {
return nil, status.Error(codes.NotFound, err.Error())
}

return &types.QueryFeeEnabledChannelsResponse{
FeeEnabledChannels: feeEnabledChannels,
}, nil
}

// FeeEnabledChannel implements the Query/FeeEnabledChannel gRPC method and returns true if the provided
// port and channel identifiers belong to a fee enabled channel
func (k Keeper) FeeEnabledChannel(goCtx context.Context, req *types.QueryFeeEnabledChannelRequest) (*types.QueryFeeEnabledChannelResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "empty request")
}

ctx := sdk.UnwrapSDKContext(goCtx)

isFeeEnabled := k.IsFeeEnabled(ctx, req.PortId, req.ChannelId)

return &types.QueryFeeEnabledChannelResponse{
FeeEnabled: isFeeEnabled,
}, nil
}
Loading