From 3f7bea4e99a2da0159059ff1a8fee6e422305701 Mon Sep 17 00:00:00 2001 From: Evgeniy Stratonikov Date: Thu, 18 Feb 2021 12:50:12 +0300 Subject: [PATCH] cli/flags: allow to use hashes in address flag --- cli/flags/address.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/cli/flags/address.go b/cli/flags/address.go index 264c773ee..ce2276e63 100644 --- a/cli/flags/address.go +++ b/cli/flags/address.go @@ -35,7 +35,7 @@ func (a Address) String() string { // Set implements flag.Value interface. func (a *Address) Set(s string) error { - addr, err := address.StringToUint160(s) + addr, err := ParseAddress(s) if err != nil { return cli.NewExitError(err, 1) } @@ -89,3 +89,14 @@ func (f AddressFlag) Apply(set *flag.FlagSet) { set.Var(&f.Value, name, f.Usage) }) } + +// ParseAddress parses Uint160 form either LE string or address. +func ParseAddress(s string) (util.Uint160, error) { + const uint160size = 2 * util.Uint160Size + switch len(s) { + case uint160size, uint160size + 2: + return util.Uint160DecodeStringLE(strings.TrimPrefix(s, "0x")) + default: + return address.StringToUint160(s) + } +}