Skip to content

Commit

Permalink
introduce query rpc to get the fee config by channel and denom name
Browse files Browse the repository at this point in the history
  • Loading branch information
RustNinja committed May 24, 2024
1 parent 6805a95 commit dd24310
Show file tree
Hide file tree
Showing 5 changed files with 612 additions and 19 deletions.
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 @@ package keeper

import (
"context"
"fmt"

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

Expand All @@ -17,3 +18,20 @@ func (k Keeper) Params(c context.Context, _ *types.QueryParamsRequest) (*types.Q

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

0 comments on commit dd24310

Please sign in to comment.