From 7b199af3b7b854b0c1b459b15eae2071afe5ebb6 Mon Sep 17 00:00:00 2001 From: Ekaterina Pavlova Date: Fri, 12 Jul 2024 11:57:59 +0300 Subject: [PATCH] cli: change StringFlag to AddressFlag For passing address or hash AddressFlag is more suitable. Signed-off-by: Ekaterina Pavlova --- cli/smartcontract/contract_test.go | 2 +- cli/smartcontract/manifest.go | 8 ++------ cli/smartcontract/smart_contract.go | 3 +-- cli/vm/cli.go | 9 +++------ 4 files changed, 7 insertions(+), 15 deletions(-) diff --git a/cli/smartcontract/contract_test.go b/cli/smartcontract/contract_test.go index e0fff3540..ac4648eb7 100644 --- a/cli/smartcontract/contract_test.go +++ b/cli/smartcontract/contract_test.go @@ -556,7 +556,7 @@ func TestContractManifestGroups(t *testing.T) { "--nef", nefName, "--manifest", manifestName) }) t.Run("invalid sender", func(t *testing.T) { - e.RunWithError(t, "neo-go", "contract", "manifest", "add-group", + e.RunWithErrorCheck(t, `invalid value "not-a-sender" for flag -sender: invalid base58 digit ('-')`, "neo-go", "contract", "manifest", "add-group", "--wallet", testcli.TestWalletPath, "--address", testcli.TestWalletAccount, "--sender", "not-a-sender", "--nef", nefName, "--manifest", manifestName) }) diff --git a/cli/smartcontract/manifest.go b/cli/smartcontract/manifest.go index 3d71c4ddb..8d65fcc05 100644 --- a/cli/smartcontract/manifest.go +++ b/cli/smartcontract/manifest.go @@ -19,11 +19,7 @@ func manifestAddGroup(ctx *cli.Context) error { if err := cmdargs.EnsureNone(ctx); err != nil { return err } - sender, err := flags.ParseAddress(ctx.String("sender")) - if err != nil { - return cli.Exit(fmt.Errorf("invalid sender: %w", err), 1) - } - + sender := ctx.Generic("sender").(*flags.Address) nf, _, err := readNEFFile(ctx.String("nef")) if err != nil { return cli.Exit(fmt.Errorf("can't read NEF file: %w", err), 1) @@ -35,7 +31,7 @@ func manifestAddGroup(ctx *cli.Context) error { return cli.Exit(fmt.Errorf("can't read contract manifest: %w", err), 1) } - h := state.CreateContractHash(sender, nf.Checksum, m.Name) + h := state.CreateContractHash(sender.Uint160(), nf.Checksum, m.Name) gAcc, w, err := options.GetAccFromContext(ctx) if err != nil { diff --git a/cli/smartcontract/smart_contract.go b/cli/smartcontract/smart_contract.go index 4ad20ea72..c3c8d4032 100644 --- a/cli/smartcontract/smart_contract.go +++ b/cli/smartcontract/smart_contract.go @@ -117,12 +117,11 @@ func NewCommands() []*cli.Command { }, }...) manifestAddGroupFlags := append([]cli.Flag{ - &cli.StringFlag{ + &flags.AddressFlag{ Name: "sender", Aliases: []string{"s"}, Required: true, Usage: "Deploy transaction sender", - Action: cmdargs.EnsureNotEmpty("sender"), }, &flags.AddressFlag{ Name: addressFlagName, // use the same name for handler code unification. diff --git a/cli/vm/cli.go b/cli/vm/cli.go index d8a95bcf0..2c742d6a8 100644 --- a/cli/vm/cli.go +++ b/cli/vm/cli.go @@ -79,7 +79,7 @@ var ( Name: gasFlagFullName, Usage: "GAS limit for this execution (integer number, satoshi).", } - hashFlag = &cli.StringFlag{ + hashFlag = &flags.AddressFlag{ Name: hashFlagFullName, Usage: "Smart-contract hash in LE form or address", } @@ -685,11 +685,8 @@ func getHashFlag(c *cli.Context) (util.Uint160, error) { if !c.IsSet(hashFlagFullName) { return util.Uint160{}, nil } - h, err := flags.ParseAddress(c.String(hashFlagFullName)) - if err != nil { - return util.Uint160{}, fmt.Errorf("failed to parse contract hash: %w", err) - } - return h, nil + h := c.Generic(hashFlagFullName).(*flags.Address) + return h.Uint160(), nil } func handleLoadNEF(c *cli.Context) error {