From 9aa6ab4fc9efeb9dd75f88aeb9f3fa6c5b1798ac Mon Sep 17 00:00:00 2001 From: Pavel Karpy Date: Thu, 22 Jul 2021 13:56:02 +0300 Subject: [PATCH] [#710] cli: Make `--address` flag optional If `--address` was not presented use default wallet address and do not require it. Signed-off-by: Pavel Karpy --- cmd/neofs-cli/modules/root.go | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/cmd/neofs-cli/modules/root.go b/cmd/neofs-cli/modules/root.go index 60a95b1ff..9ac8d515a 100644 --- a/cmd/neofs-cli/modules/root.go +++ b/cmd/neofs-cli/modules/root.go @@ -13,6 +13,7 @@ import ( "github.com/nspcc-dev/neo-go/cli/flags" "github.com/nspcc-dev/neo-go/cli/input" "github.com/nspcc-dev/neo-go/pkg/crypto/keys" + "github.com/nspcc-dev/neo-go/pkg/util" "github.com/nspcc-dev/neo-go/pkg/wallet" "github.com/nspcc-dev/neofs-api-go/pkg" "github.com/nspcc-dev/neofs-api-go/pkg/client" @@ -220,15 +221,20 @@ func getKeyFromNEP2(encryptedWif string) (*ecdsa.PrivateKey, error) { } func getKeyFromWallet(w *wallet.Wallet, addrStr string) (*ecdsa.PrivateKey, error) { - if addrStr == "" { - printVerbose("Address is empty") - return nil, errInvalidAddress - } + var ( + addr util.Uint160 + err error + ) - addr, err := flags.ParseAddress(addrStr) - if err != nil { - printVerbose("Can't parse address: %s", addrStr) - return nil, errInvalidAddress + if addrStr == "" { + printVerbose("Using default wallet address") + addr = w.GetChangeAddress() + } else { + addr, err = flags.ParseAddress(addrStr) + if err != nil { + printVerbose("Can't parse address: %s", addrStr) + return nil, errInvalidAddress + } } acc := w.GetAccount(addr)