gaiadebug: raw-bytes command

This commit is contained in:
Ethan Buchman 2018-06-12 22:59:33 -07:00
parent 2219548d0e
commit 47cc91e8e5
1 changed files with 30 additions and 0 deletions

View File

@ -7,6 +7,8 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"os" "os"
"strconv"
"strings"
gaia "github.com/cosmos/cosmos-sdk/cmd/gaia/app" gaia "github.com/cosmos/cosmos-sdk/cmd/gaia/app"
"github.com/cosmos/cosmos-sdk/x/auth" "github.com/cosmos/cosmos-sdk/x/auth"
@ -18,6 +20,7 @@ func init() {
rootCmd.AddCommand(txCmd) rootCmd.AddCommand(txCmd)
rootCmd.AddCommand(pubkeyCmd) rootCmd.AddCommand(pubkeyCmd)
rootCmd.AddCommand(hackCmd) rootCmd.AddCommand(hackCmd)
rootCmd.AddCommand(rawBytesCmd)
} }
var rootCmd = &cobra.Command{ var rootCmd = &cobra.Command{
@ -44,6 +47,33 @@ var hackCmd = &cobra.Command{
RunE: runHackCmd, RunE: runHackCmd,
} }
var rawBytesCmd = &cobra.Command{
Use: "raw-bytes",
Short: "Convert raw bytes output (eg. [10 21 13 255]) to hex",
RunE: runRawBytesCmd,
}
func runRawBytesCmd(cmd *cobra.Command, args []string) error {
if len(args) != 1 {
return fmt.Errorf("Expected single arg")
}
stringBytes := args[0]
stringBytes = strings.Trim(stringBytes, "[")
stringBytes = strings.Trim(stringBytes, "]")
spl := strings.Split(stringBytes, " ")
byteArray := []byte{}
for _, s := range spl {
b, err := strconv.Atoi(s)
if err != nil {
return err
}
byteArray = append(byteArray, byte(b))
}
fmt.Printf("%X\n", byteArray)
return nil
}
func runPubKeyCmd(cmd *cobra.Command, args []string) error { func runPubKeyCmd(cmd *cobra.Command, args []string) error {
if len(args) != 1 { if len(args) != 1 {
return fmt.Errorf("Expected single arg") return fmt.Errorf("Expected single arg")