Skip to content

Commit

Permalink
feat: add debug cmd for application codec types (backport #18219) (#1…
Browse files Browse the repository at this point in the history
…8433)

Co-authored-by: Damian Nolan <[email protected]>
Co-authored-by: Julien Robert <[email protected]>
  • Loading branch information
3 people authored Nov 10, 2023
1 parent 8f25a61 commit b93bdea
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ Ref: https://keepachangelog.com/en/1.0.0/

### Features

* (debug) [#18219](https://github.com/cosmos/cosmos-sdk/pull/18219) Add debug commands for application codec types.
* (client/keys) [#17639](https://github.com/cosmos/cosmos-sdk/pull/17639) Allows using and saving public keys encoded as base64.
* (server) [#17094](https://github.com/cosmos/cosmos-sdk/pull/17094) Add a `shutdown-grace` flag for waiting a given time before exit.

Expand Down
50 changes: 50 additions & 0 deletions client/debug/main.go
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,55 @@ 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",
Args: cobra.ExactArgs(1),
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

0 comments on commit b93bdea

Please sign in to comment.