From 1ea06e975749a2ddd2e5ec8e285916fceb7d981a Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Thu, 6 Oct 2022 21:52:40 +0300 Subject: [PATCH] cli/wallet: unify claim and candidate code Add -g option to claim which doesn't have a lot of sense, but can be used anyway. --- cli/wallet/wallet.go | 48 +++++++------------------------------------- 1 file changed, 7 insertions(+), 41 deletions(-) diff --git a/cli/wallet/wallet.go b/cli/wallet/wallet.go index 09479ef71..6a3cd93ac 100644 --- a/cli/wallet/wallet.go +++ b/cli/wallet/wallet.go @@ -15,12 +15,13 @@ import ( "github.com/nspcc-dev/neo-go/cli/input" "github.com/nspcc-dev/neo-go/cli/options" "github.com/nspcc-dev/neo-go/pkg/config" + "github.com/nspcc-dev/neo-go/pkg/core/transaction" "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/rpcclient/actor" "github.com/nspcc-dev/neo-go/pkg/rpcclient/neo" "github.com/nspcc-dev/neo-go/pkg/smartcontract" "github.com/nspcc-dev/neo-go/pkg/smartcontract/manifest" + "github.com/nspcc-dev/neo-go/pkg/util" "github.com/nspcc-dev/neo-go/pkg/vm" "github.com/nspcc-dev/neo-go/pkg/wallet" "github.com/urfave/cli" @@ -90,6 +91,7 @@ func NewCommands() []cli.Command { claimFlags := []cli.Flag{ walletPathFlag, walletConfigFlag, + gasFlag, flags.AddressFlag{ Name: "address, a", Usage: "Address to claim GAS for", @@ -114,7 +116,7 @@ func NewCommands() []cli.Command { { Name: "claim", Usage: "claim GAS", - UsageText: "neo-go wallet claim -w wallet [--wallet-config path] -a address -r endpoint [-s timeout]", + UsageText: "neo-go wallet claim -w wallet [--wallet-config path] [-g gas] -a address -r endpoint [-s timeout]", Action: claimGas, Flags: claimFlags, }, @@ -340,45 +342,9 @@ func NewCommands() []cli.Command { } func claimGas(ctx *cli.Context) error { - if err := cmdargs.EnsureNone(ctx); err != nil { - return err - } - wall, pass, err := readWallet(ctx) - if err != nil { - return cli.NewExitError(err, 1) - } - defer wall.Close() - - addrFlag := ctx.Generic("address").(*flags.Address) - if !addrFlag.IsSet { - return cli.NewExitError("address was not provided", 1) - } - scriptHash := addrFlag.Uint160() - acc, err := getDecryptedAccount(wall, scriptHash, pass) - if err != nil { - return cli.NewExitError(err, 1) - } - - gctx, cancel := options.GetTimeoutContext(ctx) - defer cancel() - - c, err := options.GetRPCClient(gctx, ctx) - if err != nil { - return cli.NewExitError(err, 1) - } - - act, err := actor.NewSimple(c, acc) - if err != nil { - return cli.NewExitError(err, 1) - } - neoToken := neo.New(act) - hash, _, err := neoToken.Transfer(scriptHash, scriptHash, big.NewInt(0), nil) - if err != nil { - return cli.NewExitError(err, 1) - } - - fmt.Fprintln(ctx.App.Writer, hash.StringLE()) - return nil + return handleNeoAction(ctx, func(contract *neo.Contract, shash util.Uint160, _ *wallet.Account) (*transaction.Transaction, error) { + return contract.TransferUnsigned(shash, shash, big.NewInt(0), nil) + }) } func changePassword(ctx *cli.Context) error {