github.com/okex/exchain@v1.8.0/libs/ibc-go/modules/apps/transfer/client/cli/query.go (about) 1 package cli 2 3 import ( 4 "fmt" 5 "github.com/okex/exchain/libs/cosmos-sdk/client" 6 "github.com/okex/exchain/libs/cosmos-sdk/client/context" 7 "github.com/okex/exchain/libs/cosmos-sdk/client/flags" 8 "github.com/okex/exchain/libs/cosmos-sdk/codec" 9 interfacetypes "github.com/okex/exchain/libs/cosmos-sdk/codec/types" 10 "github.com/okex/exchain/libs/cosmos-sdk/version" 11 "github.com/okex/exchain/libs/ibc-go/modules/apps/transfer/types" 12 "github.com/spf13/cobra" 13 ) 14 15 // GetCmdQueryDenomTrace defines the command to query a a denomination trace from a given hash. 16 func GetCmdQueryDenomTrace(m *codec.CodecProxy, reg interfacetypes.InterfaceRegistry) *cobra.Command { 17 cmd := &cobra.Command{ 18 Use: "denom-trace [hash]", 19 Short: "Query the denom trace info from a given trace hash", 20 Long: "Query the denom trace info from a given trace hash", 21 Example: fmt.Sprintf("%s query ibc-transfer denom-trace [hash]", version.ServerName), 22 Args: cobra.ExactArgs(1), 23 RunE: func(cmd *cobra.Command, args []string) error { 24 clientCtx := context.NewCLIContext().WithProxy(m).WithInterfaceRegistry(reg) 25 queryClient := types.NewQueryClient(clientCtx) 26 27 req := &types.QueryDenomTraceRequest{ 28 Hash: args[0], 29 } 30 31 res, err := queryClient.DenomTrace(cmd.Context(), req) 32 if err != nil { 33 return err 34 } 35 36 return clientCtx.PrintProto(res) 37 }, 38 } 39 40 flags.AddQueryFlagsToCmd(cmd) 41 return cmd 42 } 43 44 // GetCmdQueryDenomTraces defines the command to query all the denomination trace infos 45 // that this chain mantains. 46 func GetCmdQueryDenomTraces(m *codec.CodecProxy, reg interfacetypes.InterfaceRegistry) *cobra.Command { 47 cmd := &cobra.Command{ 48 Use: "denom-traces", 49 Short: "Query the trace info for all token denominations", 50 Long: "Query the trace info for all token denominations", 51 Example: fmt.Sprintf("%s query ibc-transfer denom-traces", version.ServerName), 52 Args: cobra.NoArgs, 53 RunE: func(cmd *cobra.Command, _ []string) error { 54 clientCtx := context.NewCLIContext().WithProxy(m).WithInterfaceRegistry(reg) 55 queryClient := types.NewQueryClient(clientCtx) 56 57 pageReq, err := client.ReadPageRequest(cmd.Flags()) 58 if err != nil { 59 return err 60 } 61 62 req := &types.QueryDenomTracesRequest{ 63 Pagination: pageReq, 64 } 65 66 res, err := queryClient.DenomTraces(cmd.Context(), req) 67 if err != nil { 68 return err 69 } 70 71 return clientCtx.PrintProto(res) 72 }, 73 } 74 flags.AddQueryFlagsToCmd(cmd) 75 flags.AddPaginationFlagsToCmd(cmd, "denominations trace") 76 77 return cmd 78 } 79 80 // GetCmdParams returns the command handler for ibc-transfer parameter querying. 81 func GetCmdParams(m *codec.CodecProxy, reg interfacetypes.InterfaceRegistry) *cobra.Command { 82 cmd := &cobra.Command{ 83 Use: "params", 84 Short: "Query the current ibc-transfer parameters", 85 Long: "Query the current ibc-transfer parameters", 86 Args: cobra.NoArgs, 87 Example: fmt.Sprintf("%s query ibc-transfer params", version.ServerName), 88 RunE: func(cmd *cobra.Command, _ []string) error { 89 clientCtx := context.NewCLIContext().WithProxy(m).WithInterfaceRegistry(reg) 90 queryClient := types.NewQueryClient(clientCtx) 91 92 res, _ := queryClient.Params(cmd.Context(), &types.QueryParamsRequest{}) 93 return clientCtx.PrintProto(res.Params) 94 }, 95 } 96 97 flags.AddQueryFlagsToCmd(cmd) 98 99 return cmd 100 } 101 102 // GetCmdParams returns the command handler for ibc-transfer parameter querying. 103 func GetCmdQueryEscrowAddress(m *codec.CodecProxy, reg interfacetypes.InterfaceRegistry) *cobra.Command { 104 cmd := &cobra.Command{ 105 Use: "escrow-address", 106 Short: "Get the escrow address for a channel", 107 Long: "Get the escrow address for a channel", 108 Args: cobra.ExactArgs(2), 109 Example: fmt.Sprintf("%s query ibc-transfer escrow-address [port] [channel-id]", version.ServerName), 110 RunE: func(cmd *cobra.Command, args []string) error { 111 clientCtx := context.NewCLIContext().WithProxy(m).WithInterfaceRegistry(reg) 112 port := args[0] 113 channel := args[1] 114 addr := types.GetEscrowAddress(port, channel) 115 return clientCtx.PrintOutput(fmt.Sprintf("%s\n", addr.String())) 116 }, 117 } 118 119 flags.AddQueryFlagsToCmd(cmd) 120 121 return cmd 122 }