From dc97f25e14a6e323cca7ccf8d5bbe0c0b5331f78 Mon Sep 17 00:00:00 2001 From: Damian Nolan Date: Mon, 23 Oct 2023 16:54:22 +0200 Subject: [PATCH] feat: add debug cmd for application codec types (#18219) (cherry picked from commit 3c9168d4606f6cd3d0740d288f4e171a3fad2e6b) --- client/debug/main.go | 49 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/client/debug/main.go b/client/debug/main.go index d3552880688a..3c907dd5e261 100644 --- a/client/debug/main.go +++ b/client/debug/main.go @@ -34,6 +34,7 @@ func Cmd() *cobra.Command { RunE: client.ValidateCmd, } + cmd.AddCommand(CodecCmd()) cmd.AddCommand(PubkeyCmd()) cmd.AddCommand(PubkeyRawCmd()) cmd.AddCommand(AddrCmd()) @@ -43,6 +44,54 @@ func Cmd() *cobra.Command { return cmd } +// CodecCmd creates and returns a new codec debug cmd. +func CodecCmd() *cobra.Command { + cmd := &cobra.Command{ + Use: "codec", + Short: "Tool for helping with debugging your application codec", + RunE: client.ValidateCmd, + } + + cmd.AddCommand(getCodecInterfaces()) + cmd.AddCommand(getCodecInterfaceImpls()) + + return cmd +} + +// getCodecInterfaces creates and returns a new cmd used for listing all registered interfaces on the application codec. +func getCodecInterfaces() *cobra.Command { + return &cobra.Command{ + Use: "list-interfaces", + Short: "List all registered interface type URLs", + Long: "List all registered interface type URLs using the application codec", + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx := client.GetClientContextFromCmd(cmd) + iFaces := clientCtx.Codec.InterfaceRegistry().ListAllInterfaces() + for _, iFace := range iFaces { + cmd.Println(iFace) + } + return nil + }, + } +} + +// getCodecInterfaceImpls creates and returns a new cmd used for listing all registered implemenations of a given interface on the application codec. +func getCodecInterfaceImpls() *cobra.Command { + return &cobra.Command{ + Use: "list-implementations [interface]", + Short: "List the registered type URLs for the provided interface", + Long: "List the registered type URLs that can be used for the provided interface name using the application codec", + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx := client.GetClientContextFromCmd(cmd) + impls := clientCtx.Codec.InterfaceRegistry().ListImplementations(args[0]) + for _, imp := range impls { + cmd.Println(imp) + } + return nil + }, + } +} + // getPubKeyFromString decodes SDK PubKey using JSON marshaler. func getPubKeyFromString(ctx client.Context, pkstr string) (cryptotypes.PubKey, error) { var pk cryptotypes.PubKey