From d84d52924a2accd7d74da992a24dc66b5aeb49a7 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Thu, 2 Jun 2022 10:58:12 +0300 Subject: [PATCH] [#1467] pkg/util: Allow to load default account from a wallet Signed-off-by: Evgenii Stratonikov --- pkg/util/config/crypto.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/pkg/util/config/crypto.go b/pkg/util/config/crypto.go index 33fd245c3..a8974a56b 100644 --- a/pkg/util/config/crypto.go +++ b/pkg/util/config/crypto.go @@ -5,6 +5,7 @@ import ( "github.com/nspcc-dev/neo-go/pkg/crypto/keys" "github.com/nspcc-dev/neo-go/pkg/encoding/address" + "github.com/nspcc-dev/neo-go/pkg/util" "github.com/nspcc-dev/neo-go/pkg/wallet" ) @@ -17,9 +18,17 @@ func LoadAccount(path, addr, password string) (*wallet.Account, error) { defer w.Close() - h, err := address.StringToUint160(addr) - if err != nil { - return nil, err + var h util.Uint160 + if addr == "" { + h = w.GetChangeAddress() + if h.Equals(util.Uint160{}) { + return nil, errors.New("can't find a suitable account in the wallet") + } + } else { + h, err = address.StringToUint160(addr) + if err != nil { + return nil, err + } } acc := w.GetAccount(h)