-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
53 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package main | ||
|
||
// DONTCOVER | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
|
||
"github.com/cosmos/cosmos-sdk/types/bech32" | ||
) | ||
|
||
var flagBech32Prefix = "prefix" | ||
|
||
// get cmd to convert any bech32 address to an osmo prefix. | ||
func ConvertBech32Cmd() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "bech32-convert [bech32 string]", | ||
Short: "Convert any bech32 string to the osmo prefix", | ||
Long: `Convert any bech32 string to the osmo prefix | ||
Especially useful for converting cosmos addresses to osmo addresses | ||
Example: | ||
osmosisd bech32-convert cosmos1ey69r37gfxvxg62sh4r0ktpuc46pzjrmz29g45 | ||
`, | ||
Args: cobra.ExactArgs(1), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
bech32prefix, err := cmd.Flags().GetString(flagBech32Prefix) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
_, bz, err := bech32.DecodeAndConvert(args[0]) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
bech32Addr, err := bech32.ConvertAndEncode(bech32prefix, bz) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
cmd.Println(bech32Addr) | ||
|
||
return nil | ||
}, | ||
} | ||
|
||
cmd.Flags().StringP(flagBech32Prefix, "p", "n", "Bech32 Prefix to encode to") | ||
|
||
return cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters