diff --git a/bridge/cmd/debug/vaa.go b/bridge/cmd/debug/vaa.go new file mode 100644 index 00000000..dac456ec --- /dev/null +++ b/bridge/cmd/debug/vaa.go @@ -0,0 +1,40 @@ +package debug + +import ( + "encoding/hex" + "github.com/certusone/wormhole/bridge/pkg/vaa" + "github.com/davecgh/go-spew/spew" + "github.com/spf13/cobra" + "log" + "strings" +) + +var DebugCmd = &cobra.Command{ + Use: "debug", + Short: "Debugging utilities", +} + +var decodeVaaCmd = &cobra.Command{ + Use: "decode-vaa [DATA]", + Short: "Decode a hex-encoded VAA", + Run: func(cmd *cobra.Command, args []string) { + for _, arg := range args { + arg = strings.TrimPrefix(arg, "0x") + b, err := hex.DecodeString(arg) + if err != nil { + log.Fatal(err) + } + + v, err := vaa.Unmarshal(b) + if err != nil { + log.Fatal(err) + } + + spew.Dump(v) + } + }, +} + +func init() { + DebugCmd.AddCommand(decodeVaaCmd) +} diff --git a/bridge/cmd/root.go b/bridge/cmd/root.go index 7d65fd2b..39a4b67c 100644 --- a/bridge/cmd/root.go +++ b/bridge/cmd/root.go @@ -2,6 +2,7 @@ package cmd import ( "fmt" + "github.com/certusone/wormhole/bridge/cmd/debug" "github.com/certusone/wormhole/bridge/pkg/version" "os" @@ -48,6 +49,7 @@ func init() { rootCmd.AddCommand(guardiand.AdminCmd) rootCmd.AddCommand(guardiand.TemplateCmd) rootCmd.AddCommand(versionCmd) + rootCmd.AddCommand(debug.DebugCmd) } // initConfig reads in config file and ENV variables if set.