From 82cb96dc528bc23eee9b5fe32ce8eda4eefd2285 Mon Sep 17 00:00:00 2001 From: LuttyYang Date: Tue, 20 Jul 2021 13:16:38 +0800 Subject: [PATCH] fix issue 247 (#263) * fix issue 247 * fix bug --- cmd/subcommands/root.go | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/cmd/subcommands/root.go b/cmd/subcommands/root.go index 635cfcf..fed40b1 100644 --- a/cmd/subcommands/root.go +++ b/cmd/subcommands/root.go @@ -4,6 +4,7 @@ import ( "bytes" "encoding/json" "fmt" + "github.com/harmony-one/go-sdk/pkg/address" "net/http" "os" "path" @@ -223,15 +224,21 @@ func endpointToChainID(nodeAddr string) chainIDWrapper { func validateAddress(cmd *cobra.Command, args []string) error { // Check if input valid one address - address := oneAddress{} - if err := address.Set(args[0]); err != nil { + tmpAddr := oneAddress{} + if err := tmpAddr.Set(args[0]); err != nil { // Check if input is valid account name if acc, err := store.AddressFromAccountName(args[0]); err == nil { addr = oneAddress{acc} return nil } - return fmt.Errorf("Invalid one address/Invalid account name: %s", args[0]) + + bech32Addr := address.ToBech32(address.Parse(args[0])) + if bech32Addr == "" { + return fmt.Errorf("Invalid one address/Invalid account name: %s", args[0]) + } + + tmpAddr = oneAddress{bech32Addr} } - addr = address + addr = tmpAddr return nil }