Skip to content

Commit

Permalink
add support for encode/decode other bech32 prefixes (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
cameroncooper authored Dec 24, 2024
1 parent 4ca8cde commit 0330074
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
5 changes: 1 addition & 4 deletions internal/cmd/coinset/address_decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@ var addressDecodeCmd = &cobra.Command{
if err := cobra.ExactArgs(1)(cmd, args); err != nil {
return err
}
if isAddress(args[0]) {
return nil
}
return fmt.Errorf("invalid address value specified: %s", args[0])
return nil
},
Short: "Decode address to puzzle hash",
Long: `Decode address to puzzle hash`,
Expand Down
11 changes: 8 additions & 3 deletions internal/cmd/coinset/address_encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
)

func init() {
addressEncodeCmd.Flags().StringP("prefix", "p", "", "Bech32 prefix")
addressCmd.AddCommand(addressEncodeCmd)
}

Expand All @@ -27,9 +28,13 @@ var addressEncodeCmd = &cobra.Command{
Short: "Encode puzzle hash to address",
Long: `Encode puzzle hash to address`,
Run: func(cmd *cobra.Command, args []string) {
prefix := "xch"
if testnet {
prefix = "txch"
prefix, _ := cmd.Flags().GetString("prefix")
if prefix == "" {
if testnet {
prefix = "txch"
} else {
prefix = "xch"
}
}
var puzzleHash = formatHex(args[0])
hexBytes, err := hex.DecodeString(puzzleHash[2:])
Expand Down

0 comments on commit 0330074

Please sign in to comment.