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

introduce query rpc to get the fee config by channel and denom name #522

Merged
merged 1 commit into from
Jun 21, 2024
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
14 changes: 14 additions & 0 deletions proto/composable/ibctransfermiddleware/v1beta1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ service Query {
rpc Params(QueryParamsRequest) returns (QueryParamsResponse) {
option (google.api.http).get = "/composable/ibctransfermiddleware/params";
}

rpc FeeConfigByChannelAndDenom(QueryFeeConfigByChannelAndDenomRequest) returns (QueryFeeConfigByChannelAndDenomResponse) {
option (google.api.http).get = "/composable/ibctransfermiddleware/feeconfigbychannelanddenom";
}
}

// QueryParamsRequest is the request type for the Query/Params RPC method.
Expand All @@ -23,3 +27,13 @@ message QueryParamsResponse {
// params defines the parameters of the module.
Params params = 1 [ (gogoproto.nullable) = false ];
}

message QueryFeeConfigByChannelAndDenomRequest {
string channel = 1;
string denom = 2;
}

message QueryFeeConfigByChannelAndDenomResponse {
// params defines the parameters of the module.
CoinItem fees = 1 [ (gogoproto.nullable) = false ];
}
35 changes: 35 additions & 0 deletions x/ibctransfermiddleware/client/cli/query.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package cli

import (
"fmt"

"github.com/spf13/cobra"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/version"
"github.com/notional-labs/composable/v6/x/ibctransfermiddleware/types"
)

Expand All @@ -20,6 +23,7 @@ func GetQueryCmd() *cobra.Command {

ibctransfermiddlewareParamsQueryCmd.AddCommand(
GetCmdQueryParams(),
GetFeeConfigByChannelAndDenom(),
)

return ibctransfermiddlewareParamsQueryCmd
Expand Down Expand Up @@ -53,3 +57,34 @@ func GetCmdQueryParams() *cobra.Command {

return cmd
}

func GetFeeConfigByChannelAndDenom() *cobra.Command {
cmd := &cobra.Command{
Use: "FeeConfigByChannelAndDenom",
Short: "Query bridge fee config by channel and denom",
Args: cobra.MatchAll(cobra.ExactArgs(2), cobra.OnlyValidArgs),
Example: fmt.Sprintf("%s query ibctransfermiddleware FeeConfigByChannelAndDenom [channel] [denom]", version.AppName),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}
queryClient := types.NewQueryClient(clientCtx)

params := &types.QueryFeeConfigByChannelAndDenomRequest{
Channel: args[0],
Denom: args[1],
}
res, err := queryClient.FeeConfigByChannelAndDenom(cmd.Context(), params)
if err != nil {
return err
}

return clientCtx.PrintProto(&res.Fees)
},
}

flags.AddQueryFlagsToCmd(cmd)

return cmd
}
18 changes: 18 additions & 0 deletions x/ibctransfermiddleware/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import (
"context"
"fmt"

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

Expand All @@ -17,3 +18,20 @@

return &types.QueryParamsResponse{Params: params}, nil
}

// ChannelFees returns channel fees of the staking middleware module.
func (k Keeper) FeeConfigByChannelAndDenom(c context.Context, req *types.QueryFeeConfigByChannelAndDenomRequest) (*types.QueryFeeConfigByChannelAndDenomResponse, error) {
ctx := sdk.UnwrapSDKContext(c)
feeConfig := k.GetCoin(ctx, req.Channel, req.Denom)
if feeConfig == nil {
return nil, fmt.Errorf("fee configuration not found for channel %s and denom %s", req.Channel, req.Denom)
} else {
ret_fee_config := types.CoinItem{
MinFee: feeConfig.MinFee,
Percentage: feeConfig.Percentage,
TxPriorityFee: feeConfig.TxPriorityFee,
}
return &types.QueryFeeConfigByChannelAndDenomResponse{Fees: ret_fee_config}, nil
}

Check failure on line 36 in x/ibctransfermiddleware/keeper/grpc_query.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gofumpt`-ed with `-extra` (gofumpt)
}
Loading
Loading