[#1467] pkg/util: Allow to load default account from a wallet

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
Evgenii Stratonikov 2022-06-02 10:58:12 +03:00 committed by fyrchik
parent 2da8396a9f
commit d84d52924a

View file

@ -5,6 +5,7 @@ import (
"github.com/nspcc-dev/neo-go/pkg/crypto/keys" "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/encoding/address"
"github.com/nspcc-dev/neo-go/pkg/util"
"github.com/nspcc-dev/neo-go/pkg/wallet" "github.com/nspcc-dev/neo-go/pkg/wallet"
) )
@ -17,9 +18,17 @@ func LoadAccount(path, addr, password string) (*wallet.Account, error) {
defer w.Close() defer w.Close()
h, err := address.StringToUint160(addr) var h util.Uint160
if err != nil { if addr == "" {
return nil, err 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) acc := w.GetAccount(h)