From 5200765dab9420db6cdfaedb8aea4b08c0ee46a2 Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Thu, 6 Oct 2022 22:19:40 +0300 Subject: [PATCH] cli/wallet: add out/force flags to claim/candidate cmds Fixes #2669. --- cli/wallet/candidate_test.go | 12 ++++++++---- cli/wallet/validator.go | 23 ++++++++++------------- cli/wallet/wallet.go | 4 +++- cli/wallet/wallet_test.go | 3 ++- 4 files changed, 23 insertions(+), 19 deletions(-) diff --git a/cli/wallet/candidate_test.go b/cli/wallet/candidate_test.go index 9f59f870b..822d764f4 100644 --- a/cli/wallet/candidate_test.go +++ b/cli/wallet/candidate_test.go @@ -55,7 +55,8 @@ func TestRegisterCandidate(t *testing.T) { e.Run(t, "neo-go", "wallet", "candidate", "register", "--rpc-endpoint", "http://"+e.RPC.Addr, "--wallet", testcli.ValidatorWallet, - "--address", validatorAddress) + "--address", validatorAddress, + "--force") e.CheckTxPersisted(t) vs, err := e.Chain.GetEnrollments() @@ -77,7 +78,8 @@ func TestRegisterCandidate(t *testing.T) { "--rpc-endpoint", "http://"+e.RPC.Addr, "--wallet", testcli.ValidatorWallet, "--address", validatorAddress, - "--candidate", validatorHex) + "--candidate", validatorHex, + "--force") _, index := e.CheckTxPersisted(t) vs, err = e.Chain.GetEnrollments() @@ -110,7 +112,8 @@ func TestRegisterCandidate(t *testing.T) { e.Run(t, "neo-go", "wallet", "candidate", "vote", "--rpc-endpoint", "http://"+e.RPC.Addr, "--wallet", testcli.ValidatorWallet, - "--address", validatorAddress) + "--address", validatorAddress, + "--force") _, index = e.CheckTxPersisted(t) vs, err = e.Chain.GetEnrollments() @@ -143,7 +146,8 @@ func TestRegisterCandidate(t *testing.T) { e.Run(t, "neo-go", "wallet", "candidate", "unregister", "--rpc-endpoint", "http://"+e.RPC.Addr, "--wallet", testcli.ValidatorWallet, - "--address", validatorAddress) + "--address", validatorAddress, + "--force") e.CheckTxPersisted(t) vs, err = e.Chain.GetEnrollments() diff --git a/cli/wallet/validator.go b/cli/wallet/validator.go index 8f791dd26..e4a9e17ad 100644 --- a/cli/wallet/validator.go +++ b/cli/wallet/validator.go @@ -22,13 +22,15 @@ func newValidatorCommands() []cli.Command { { Name: "register", Usage: "register as a new candidate", - UsageText: "register -w -r -a [-g gas] [-e sysgas]", + UsageText: "register -w -r -a [-g gas] [-e sysgas] [--out file] [--force]", Action: handleRegister, Flags: append([]cli.Flag{ walletPathFlag, walletConfigFlag, gasFlag, sysGasFlag, + outFlag, + forceFlag, flags.AddressFlag{ Name: "address, a", Usage: "Address to register", @@ -38,13 +40,15 @@ func newValidatorCommands() []cli.Command { { Name: "unregister", Usage: "unregister self as a candidate", - UsageText: "unregister -w -r -a [-g gas] [-e sysgas]", + UsageText: "unregister -w -r -a [-g gas] [-e sysgas] [--out file] [--force]", Action: handleUnregister, Flags: append([]cli.Flag{ walletPathFlag, walletConfigFlag, gasFlag, sysGasFlag, + outFlag, + forceFlag, flags.AddressFlag{ Name: "address, a", Usage: "Address to unregister", @@ -54,7 +58,7 @@ func newValidatorCommands() []cli.Command { { Name: "vote", Usage: "vote for a validator", - UsageText: "vote -w -r [-s ] [-g gas] [-e sysgas] -a [-c ]", + UsageText: "vote -w -r [-s ] [-g gas] [-e sysgas] -a [-c ] [--out file] [--force]", Description: `Votes for a validator by calling "vote" method of a NEO native contract. Do not provide candidate argument to perform unvoting. `, @@ -64,6 +68,8 @@ func newValidatorCommands() []cli.Command { walletConfigFlag, gasFlag, sysGasFlag, + outFlag, + forceFlag, flags.AddressFlag{ Name: "address, a", Usage: "Address to vote from", @@ -121,21 +127,12 @@ func handleNeoAction(ctx *cli.Context, mkTx func(*neo.Contract, util.Uint160, *w return cli.NewExitError(fmt.Errorf("RPC actor issue: %w", err), 1) } - gas := flags.Fixed8FromContext(ctx, "gas") - sysgas := flags.Fixed8FromContext(ctx, "sysgas") contract := neo.New(act) tx, err := mkTx(contract, addr, acc) if err != nil { return cli.NewExitError(err, 1) } - tx.NetworkFee += int64(gas) - tx.SystemFee += int64(sysgas) - res, _, err := act.SignAndSend(tx) - if err != nil { - return cli.NewExitError(fmt.Errorf("failed to sign/send transaction: %w", err), 1) - } - fmt.Fprintln(ctx.App.Writer, res.StringLE()) - return nil + return signAndSendSomeTransaction(ctx, act, acc, tx) } func handleVote(ctx *cli.Context) error { diff --git a/cli/wallet/wallet.go b/cli/wallet/wallet.go index 40d826f7e..9e1c1e29f 100644 --- a/cli/wallet/wallet.go +++ b/cli/wallet/wallet.go @@ -93,6 +93,8 @@ func NewCommands() []cli.Command { walletConfigFlag, gasFlag, sysGasFlag, + outFlag, + forceFlag, flags.AddressFlag{ Name: "address, a", Usage: "Address to claim GAS for", @@ -117,7 +119,7 @@ func NewCommands() []cli.Command { { Name: "claim", Usage: "claim GAS", - UsageText: "neo-go wallet claim -w wallet [--wallet-config path] [-g gas] [-e sysgas] -a address -r endpoint [-s timeout]", + UsageText: "neo-go wallet claim -w wallet [--wallet-config path] [-g gas] [-e sysgas] -a address -r endpoint [-s timeout] [--out file] [--force]", Action: claimGas, Flags: claimFlags, }, diff --git a/cli/wallet/wallet_test.go b/cli/wallet/wallet_test.go index db1601b5c..bfab35d38 100644 --- a/cli/wallet/wallet_test.go +++ b/cli/wallet/wallet_test.go @@ -524,7 +524,8 @@ func TestWalletClaimGas(t *testing.T) { e.Run(t, "neo-go", "wallet", "claim", "--rpc-endpoint", "http://"+e.RPC.Addr, "--wallet", testcli.TestWalletPath, - "--address", testcli.TestWalletAccount) + "--address", testcli.TestWalletAccount, + "--force") tx, height := e.CheckTxPersisted(t) balanceBefore.Sub(balanceBefore, big.NewInt(tx.NetworkFee+tx.SystemFee)) balanceBefore.Add(balanceBefore, cl)