[#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 <carpawell@nspcc.ru>
This commit is contained in:
Pavel Karpy 2021-07-22 13:56:02 +03:00 committed by Alex Vanin
parent 62efa3f098
commit 9aa6ab4fc9

View file

@ -13,6 +13,7 @@ import (
"github.com/nspcc-dev/neo-go/cli/flags" "github.com/nspcc-dev/neo-go/cli/flags"
"github.com/nspcc-dev/neo-go/cli/input" "github.com/nspcc-dev/neo-go/cli/input"
"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/util"
"github.com/nspcc-dev/neo-go/pkg/wallet" "github.com/nspcc-dev/neo-go/pkg/wallet"
"github.com/nspcc-dev/neofs-api-go/pkg" "github.com/nspcc-dev/neofs-api-go/pkg"
"github.com/nspcc-dev/neofs-api-go/pkg/client" "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) { func getKeyFromWallet(w *wallet.Wallet, addrStr string) (*ecdsa.PrivateKey, error) {
if addrStr == "" { var (
printVerbose("Address is empty") addr util.Uint160
return nil, errInvalidAddress err error
} )
addr, err := flags.ParseAddress(addrStr) if addrStr == "" {
if err != nil { printVerbose("Using default wallet address")
printVerbose("Can't parse address: %s", addrStr) addr = w.GetChangeAddress()
return nil, errInvalidAddress } else {
addr, err = flags.ParseAddress(addrStr)
if err != nil {
printVerbose("Can't parse address: %s", addrStr)
return nil, errInvalidAddress
}
} }
acc := w.GetAccount(addr) acc := w.GetAccount(addr)