feat: add debug cmd for application codec types (#18219)

This commit is contained in:
Damian Nolan 2023-10-23 16:54:22 +02:00 committed by GitHub
parent 511db52381
commit 3c9168d460
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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