Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add debug cmd for application codec types #18219

Merged
merged 1 commit into from
Oct 23, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions client/debug/main.go
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reminder to myself, when calling mergify after v0.50.0 tag, add this change as well: https://github.com/cosmos/cosmos-sdk/pull/18309/files#diff-138125b0bd1d362882611450341f8ca83ca00dcc7473a3b13a792fc2a146cf78R89

Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ func Cmd() *cobra.Command {
RunE: client.ValidateCmd,
}

cmd.AddCommand(CodecCmd())
cmd.AddCommand(PubkeyCmd())
cmd.AddCommand(PubkeyRawCmd())
cmd.AddCommand(AddrCmd())
Expand All @@ -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
Expand Down
Loading