-
Notifications
You must be signed in to change notification settings - Fork 663
/
bech32_convert.go
53 lines (40 loc) · 1.31 KB
/
bech32_convert.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package cmd
import (
"fmt"
"github.com/spf13/cobra"
addressutil "github.com/cosmos/gaia/v11/pkg/address"
)
var flagBech32Prefix = "prefix"
// AddBech32ConvertCommand returns bech32-convert cobra Command.
func AddBech32ConvertCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "bech32-convert [address]",
Short: "Convert any bech32 string to the cosmos prefix",
Long: `Convert any bech32 string to the cosmos prefix
Example:
gaiad debug bech32-convert akash1a6zlyvpnksx8wr6wz8wemur2xe8zyh0ytz6d88
gaiad debug bech32-convert stride1673f0t8p893rqyqe420mgwwz92ac4qv6synvx2 --prefix osmo
`,
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
bech32prefix, err := cmd.Flags().GetString(flagBech32Prefix)
if err != nil {
return err
}
address := args[0]
convertedAddress, err := addressutil.ConvertBech32Prefix(address, bech32prefix)
if err != nil {
return fmt.Errorf("convertation failed: %s", err)
}
cmd.Println(convertedAddress)
return nil
},
}
cmd.Flags().StringP(flagBech32Prefix, "p", "cosmos", "Bech32 Prefix to encode to")
return cmd
}
// addDebugCommands injects custom debug commands into another command as children.
func addDebugCommands(cmd *cobra.Command) *cobra.Command {
cmd.AddCommand(AddBech32ConvertCommand())
return cmd
}