From 42bfd413e3bb8618ab70c0d6fac68b38a8cb53da Mon Sep 17 00:00:00 2001 From: Anna Shaleva Date: Mon, 19 Apr 2021 16:23:53 +0300 Subject: [PATCH 1/7] cli: fix UsageText for 'wallet import-deployed' command --- cli/wallet/wallet.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/wallet/wallet.go b/cli/wallet/wallet.go index b0411ad4c..c263dfff7 100644 --- a/cli/wallet/wallet.go +++ b/cli/wallet/wallet.go @@ -192,7 +192,7 @@ func NewCommands() []cli.Command { { Name: "import-deployed", Usage: "import deployed contract", - UsageText: "import-multisig --wallet --wif --contract ", + UsageText: "import-deployed --wallet --wif --contract ", Action: importDeployed, Flags: append([]cli.Flag{ walletPathFlag, From 6af2f3fdecde11fb89728df6b6d0f7983c5284a1 Mon Sep 17 00:00:00 2001 From: Anna Shaleva Date: Mon, 19 Apr 2021 16:45:40 +0300 Subject: [PATCH 2/7] cli: use AddressFlag for 'wallet remove' command --- cli/wallet/wallet.go | 17 ++++++++++------- cli/wallet_test.go | 2 +- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/cli/wallet/wallet.go b/cli/wallet/wallet.go index c263dfff7..ad7ee8489 100644 --- a/cli/wallet/wallet.go +++ b/cli/wallet/wallet.go @@ -206,11 +206,15 @@ func NewCommands() []cli.Command { { Name: "remove", Usage: "remove an account from the wallet", - UsageText: "remove --wallet [--force] ", + UsageText: "remove --wallet [--force] --address ", Action: removeAccount, Flags: []cli.Flag{ walletPathFlag, forceFlag, + flags.AddressFlag{ + Name: "address, a", + Usage: "Account address or hash in LE form to be removed", + }, }, }, { @@ -502,18 +506,17 @@ func removeAccount(ctx *cli.Context) error { } defer wall.Close() - addrArg := ctx.Args().First() - addr, err := address.StringToUint160(addrArg) - if err != nil { - return cli.NewExitError("valid address must be provided", 1) + addr := ctx.Generic("address").(*flags.Address) + if !addr.IsSet { + cli.NewExitError("valid account address must be provided", 1) } - acc := wall.GetAccount(addr) + acc := wall.GetAccount(addr.Uint160()) if acc == nil { return cli.NewExitError("account wasn't found", 1) } if !ctx.Bool("force") { - fmt.Fprintf(ctx.App.Writer, "Account %s will be removed. This action is irreversible.\n", addrArg) + fmt.Fprintf(ctx.App.Writer, "Account %s will be removed. This action is irreversible.\n", addr.Uint160()) if ok := askForConsent(ctx.App.Writer); !ok { return nil } diff --git a/cli/wallet_test.go b/cli/wallet_test.go index e780e32f6..d91d49448 100644 --- a/cli/wallet_test.go +++ b/cli/wallet_test.go @@ -71,7 +71,7 @@ func TestWalletInit(t *testing.T) { addr := w.Accounts[0].Address e.In.WriteString("y\r") e.Run(t, "neo-go", "wallet", "remove", - "--wallet", walletPath, addr) + "--wallet", walletPath, "--address", addr) w, err := wallet.NewWalletFromFile(walletPath) require.NoError(t, err) require.Nil(t, w.GetAccount(sh)) From 08e88ce5b2c7cf5b8e0c15a5d086163a5f360682 Mon Sep 17 00:00:00 2001 From: Anna Shaleva Date: Mon, 19 Apr 2021 17:10:53 +0300 Subject: [PATCH 3/7] cli: handle 'name' named argument in 'wallet import-multisig' If the provided WIF is encrypted, then we won't get account name from readAccountInfo. --- cli/wallet/wallet.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/cli/wallet/wallet.go b/cli/wallet/wallet.go index ad7ee8489..ece110e69 100644 --- a/cli/wallet/wallet.go +++ b/cli/wallet/wallet.go @@ -173,7 +173,7 @@ func NewCommands() []cli.Command { { Name: "import-multisig", Usage: "import multisig contract", - UsageText: "import-multisig --wallet --wif --min " + + UsageText: "import-multisig --wallet --wif [--name ] --min " + " [ [ [...]]]", Action: importMultisig, Flags: []cli.Flag{ @@ -410,6 +410,9 @@ func importMultisig(ctx *cli.Context) error { return cli.NewExitError(err, 1) } + if acc.Label == "" { + acc.Label = ctx.String("name") + } if err := addAccountAndSave(wall, acc); err != nil { return cli.NewExitError(err, 1) } From 0ccced2274014e3d775edc401885c3c678ededbd Mon Sep 17 00:00:00 2001 From: Anna Shaleva Date: Mon, 19 Apr 2021 17:38:13 +0300 Subject: [PATCH 4/7] cli: add usage description to 'wallet import' command --- cli/wallet/wallet.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/cli/wallet/wallet.go b/cli/wallet/wallet.go index ece110e69..95d97bf32 100644 --- a/cli/wallet/wallet.go +++ b/cli/wallet/wallet.go @@ -154,9 +154,10 @@ func NewCommands() []cli.Command { }, }, { - Name: "import", - Usage: "import WIF", - Action: importWallet, + Name: "import", + Usage: "import WIF of a standard signature contract", + UsageText: "import --wallet --wif [--name ]", + Action: importWallet, Flags: []cli.Flag{ walletPathFlag, wifFlag, From 2daae43eafdf04d5c6df7f5df2d2adde58a4aeca Mon Sep 17 00:00:00 2001 From: Anna Shaleva Date: Mon, 19 Apr 2021 17:46:27 +0300 Subject: [PATCH 5/7] cli: add optional 'name' argument to 'wallet import-deployed' command If the provided WIF is encrypted then we have no way to set the account name. Fixed. --- cli/wallet/wallet.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/cli/wallet/wallet.go b/cli/wallet/wallet.go index 95d97bf32..ecb30072e 100644 --- a/cli/wallet/wallet.go +++ b/cli/wallet/wallet.go @@ -193,11 +193,15 @@ func NewCommands() []cli.Command { { Name: "import-deployed", Usage: "import deployed contract", - UsageText: "import-deployed --wallet --wif --contract ", + UsageText: "import-deployed --wallet --wif --contract [--name ]", Action: importDeployed, Flags: append([]cli.Flag{ walletPathFlag, wifFlag, + cli.StringFlag{ + Name: "name, n", + Usage: "Optional account name", + }, flags.AddressFlag{ Name: "contract, c", Usage: "Contract hash or address", @@ -466,6 +470,9 @@ func importDeployed(ctx *cli.Context) error { } acc.Contract.Deployed = true + if acc.Label == "" { + acc.Label = ctx.String("name") + } if err := addAccountAndSave(wall, acc); err != nil { return cli.NewExitError(err, 1) } From a348347fe883ba8030ea6817cc5bb6d01da11bdd Mon Sep 17 00:00:00 2001 From: Anna Shaleva Date: Mon, 19 Apr 2021 17:51:11 +0300 Subject: [PATCH 6/7] cli: refactor readAccountInfo method It doesn't require binwriter. --- cli/wallet/wallet.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/cli/wallet/wallet.go b/cli/wallet/wallet.go index ecb30072e..f1d96b630 100644 --- a/cli/wallet/wallet.go +++ b/cli/wallet/wallet.go @@ -318,7 +318,7 @@ func addAccount(ctx *cli.Context) error { defer wall.Close() - if err := createAccount(ctx, wall); err != nil { + if err := createAccount(wall); err != nil { return cli.NewExitError(err, 1) } @@ -636,7 +636,7 @@ func createWallet(ctx *cli.Context) error { } if ctx.Bool("account") { - if err := createAccount(ctx, wall); err != nil { + if err := createAccount(wall); err != nil { return cli.NewExitError(err, 1) } } @@ -646,7 +646,7 @@ func createWallet(ctx *cli.Context) error { return nil } -func readAccountInfo(w io.Writer) (string, string, error) { +func readAccountInfo() (string, string, error) { rawName, _ := input.ReadLine("Enter the name of the account > ") phrase, err := input.ReadPassword("Enter passphrase > ") if err != nil { @@ -661,12 +661,12 @@ func readAccountInfo(w io.Writer) (string, string, error) { return "", "", errPhraseMismatch } - name := strings.TrimRight(string(rawName), "\n") + name := strings.TrimRight(rawName, "\n") return name, phrase, nil } -func createAccount(ctx *cli.Context, wall *wallet.Wallet) error { - name, phrase, err := readAccountInfo(ctx.App.Writer) +func createAccount(wall *wallet.Wallet) error { + name, phrase, err := readAccountInfo() if err != nil { return err } @@ -698,7 +698,7 @@ func newAccountFromWIF(w io.Writer, wif string) (*wallet.Account, error) { } fmt.Fprintln(w, "Provided WIF was unencrypted. Wallet can contain only encrypted keys.") - name, pass, err := readAccountInfo(w) + name, pass, err := readAccountInfo() if err != nil { return nil, err } From 70fc78b768df83e6d180c8be67ab6e59d6e24b3b Mon Sep 17 00:00:00 2001 From: Anna Shaleva Date: Tue, 20 Apr 2021 10:59:13 +0300 Subject: [PATCH 7/7] cli: update usage text for 'wallet sign' command RPC endpoint can be provided. --- cli/wallet/wallet.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/wallet/wallet.go b/cli/wallet/wallet.go index f1d96b630..0913d5a1c 100644 --- a/cli/wallet/wallet.go +++ b/cli/wallet/wallet.go @@ -225,7 +225,7 @@ func NewCommands() []cli.Command { { Name: "sign", Usage: "cosign transaction with multisig/contract/additional account", - UsageText: "sign --wallet --address
--in --out ", + UsageText: "sign --wallet --address
--in --out [-r ]", Action: signStoredTransaction, Flags: signFlags, },