Add `resolve addr-to-b64` command
A simple utility command to convert a hex encoded local address to base64.
@@ -5,10 +5,29 @@ import (
"fmt"
loom "github.com/loomnetwork/go-loom"
+ "github.com/pkg/errors"
"github.com/spf13/cobra"
)
-func PubkeyToAddress() *cobra.Command {
+func newAddressToB64Command() *cobra.Command {
+ return &cobra.Command{
+ Use: "addr-to-b64",
+ Short: "convert hexstring address to base 64 address",
+ Example: "loom resolve addr-to-b64 0x9F5137fF296469cdc3D137273fF9A4Df76044758",
+ Args: cobra.MinimumNArgs(1),
+ RunE: func(cmd *cobra.Command, args []string) error {
+ addr, err := loom.LocalAddressFromHexString(args[0])
+ if err != nil {
+ return errors.Wrap(err, "invalid account address")
+ }
+
+ fmt.Printf("Address in base64: %s\n", base64.StdEncoding.EncodeToString([]byte(addr)))
+ return nil
+ },
+ }
+}
+
+func newPubkeyToAddressCommand() *cobra.Command {
return &cobra.Command{
Use: "pubkey [public key]",
Short: "Converts a public key to an address",
@@ -26,6 +45,7 @@ func PubkeyToAddress() *cobra.Command {
func AddGeneralCommands(root *cobra.Command) {
root.AddCommand(
- PubkeyToAddress(),
+ newPubkeyToAddressCommand(),
+ newAddressToB64Command(),
)
}
