Skip to content

Commit

Permalink
override QueryFnName (#4132)
Browse files Browse the repository at this point in the history
* override QueryFnName

* duplicate prepareDescriptor

* add CustomFlagOverrides && make change for poolmanager cli
  • Loading branch information
vuong177 authored Jan 31, 2023
1 parent 90c753f commit e15fc6b
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 9 deletions.
1 change: 0 additions & 1 deletion osmoutils/osmocli/query_cmd_wrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ func QueryIndexCmd(moduleName string) *cobra.Command {

func AddQueryCmd[Q proto.Message, querier any](cmd *cobra.Command, newQueryClientFn func(grpc1.ClientConn) querier, f func() (*QueryDescriptor, Q)) {
desc, _ := f()
prepareDescriptor[Q](desc)
subCmd := BuildQueryCli[Q](desc, newQueryClientFn)
cmd.AddCommand(subCmd)
}
Expand Down
16 changes: 12 additions & 4 deletions x/gamm/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ func GetQueryCmd() *cobra.Command {
return cmd
}

var customRouterFlagOverride = map[string]string{
"router": FlagSwapRouteDenoms,
}

func GetCmdPool() (*osmocli.QueryDescriptor, *types.QueryPoolRequest) {
return &osmocli.QueryDescriptor{
Use: "pool [poolID]",
Expand Down Expand Up @@ -203,8 +207,10 @@ func GetCmdEstimateSwapExactAmountIn() (*osmocli.QueryDescriptor, *types.QuerySw
Short: "Query estimate-swap-exact-amount-in",
Long: `Query estimate-swap-exact-amount-in.{{.ExampleHeader}}
{{.CommandPrefix}} estimate-swap-exact-amount-in 1 osm11vmx8jtggpd9u7qr0t8vxclycz85u925sazglr7 stake --swap-route-pool-ids=2 --swap-route-pool-ids=3`,
ParseQuery: EstimateSwapExactAmountInParseArgs,
Flags: osmocli.FlagDesc{RequiredFlags: []*flag.FlagSet{FlagSetMultihopSwapRoutes()}},
ParseQuery: EstimateSwapExactAmountInParseArgs,
Flags: osmocli.FlagDesc{RequiredFlags: []*flag.FlagSet{FlagSetMultihopSwapRoutes()}},
QueryFnName: "EstimateSwapExactAmountIn",
CustomFlagOverrides: customRouterFlagOverride,
}, &types.QuerySwapExactAmountInRequest{}
}

Expand All @@ -216,8 +222,10 @@ func GetCmdEstimateSwapExactAmountOut() (*osmocli.QueryDescriptor, *types.QueryS
Short: "Query estimate-swap-exact-amount-out",
Long: `Query estimate-swap-exact-amount-out.{{.ExampleHeader}}
{{.CommandPrefix}} estimate-swap-exact-amount-out 1 osm11vmx8jtggpd9u7qr0t8vxclycz85u925sazglr7 stake --swap-route-pool-ids=2 --swap-route-pool-ids=3`,
ParseQuery: EstimateSwapExactAmountOutParseArgs,
Flags: osmocli.FlagDesc{RequiredFlags: []*flag.FlagSet{FlagSetMultihopSwapRoutes()}},
ParseQuery: EstimateSwapExactAmountOutParseArgs,
Flags: osmocli.FlagDesc{RequiredFlags: []*flag.FlagSet{FlagSetMultihopSwapRoutes()}},
QueryFnName: "EstimateSwapExactAmountOut",
CustomFlagOverrides: customRouterFlagOverride,
}, &types.QuerySwapExactAmountOutRequest{}
}

Expand Down
16 changes: 12 additions & 4 deletions x/poolmanager/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ import (
"github.com/osmosis-labs/osmosis/v14/x/poolmanager/types"
)

var customRouterFlagOverride = map[string]string{
"router": FlagSwapRouteDenoms,
}

// GetQueryCmd returns the cli query commands for this module.
func GetQueryCmd() *cobra.Command {
cmd := osmocli.QueryIndexCmd(types.ModuleName)
Expand All @@ -30,8 +34,10 @@ func GetCmdEstimateSwapExactAmountIn() (*osmocli.QueryDescriptor, *queryproto.Es
Short: "Query estimate-swap-exact-amount-in",
Long: `Query estimate-swap-exact-amount-in.{{.ExampleHeader}}
{{.CommandPrefix}} estimate-swap-exact-amount-in 1 osm11vmx8jtggpd9u7qr0t8vxclycz85u925sazglr7 stake --swap-route-pool-ids=2 --swap-route-pool-ids=3`,
ParseQuery: EstimateSwapExactAmountInParseArgs,
Flags: osmocli.FlagDesc{RequiredFlags: []*flag.FlagSet{FlagSetMultihopSwapRoutes()}},
ParseQuery: EstimateSwapExactAmountInParseArgs,
Flags: osmocli.FlagDesc{RequiredFlags: []*flag.FlagSet{FlagSetMultihopSwapRoutes()}},
QueryFnName: "EstimateSwapExactAmountIn",
CustomFlagOverrides: customRouterFlagOverride,
}, &queryproto.EstimateSwapExactAmountInRequest{}
}

Expand All @@ -42,8 +48,10 @@ func GetCmdEstimateSwapExactAmountOut() (*osmocli.QueryDescriptor, *queryproto.E
Short: "Query estimate-swap-exact-amount-out",
Long: `Query estimate-swap-exact-amount-out.{{.ExampleHeader}}
{{.CommandPrefix}} estimate-swap-exact-amount-out 1 osm11vmx8jtggpd9u7qr0t8vxclycz85u925sazglr7 stake --swap-route-pool-ids=2 --swap-route-pool-ids=3`,
ParseQuery: EstimateSwapExactAmountOutParseArgs,
Flags: osmocli.FlagDesc{RequiredFlags: []*flag.FlagSet{FlagSetMultihopSwapRoutes()}},
ParseQuery: EstimateSwapExactAmountOutParseArgs,
Flags: osmocli.FlagDesc{RequiredFlags: []*flag.FlagSet{FlagSetMultihopSwapRoutes()}},
QueryFnName: "EstimateSwapExactAmountOut",
CustomFlagOverrides: customRouterFlagOverride,
}, &queryproto.EstimateSwapExactAmountOutRequest{}
}

Expand Down

0 comments on commit e15fc6b

Please sign in to comment.