diff --git a/cli/wallet/wallet.go b/cli/wallet/wallet.go index 5568ab23e..b0411ad4c 100644 --- a/cli/wallet/wallet.go +++ b/cli/wallet/wallet.go @@ -197,9 +197,9 @@ func NewCommands() []cli.Command { Flags: append([]cli.Flag{ walletPathFlag, wifFlag, - cli.StringFlag{ + flags.AddressFlag{ Name: "contract, c", - Usage: "Contract hash", + Usage: "Contract hash or address", }, }, options.RPC...), }, @@ -421,10 +421,9 @@ func importDeployed(ctx *cli.Context) error { defer wall.Close() - rawHash := ctx.String("contract") - h, err := flags.ParseAddress(rawHash) - if err != nil { - return cli.NewExitError(fmt.Errorf("invalid contract hash: %w", err), 1) + rawHash := ctx.Generic("contract").(*flags.Address) + if !rawHash.IsSet { + return cli.NewExitError("contract hash was not provided", 1) } acc, err := newAccountFromWIF(ctx.App.Writer, ctx.String("wif")) @@ -440,7 +439,7 @@ func importDeployed(ctx *cli.Context) error { return cli.NewExitError(err, 1) } - cs, err := c.GetContractStateByHash(h) + cs, err := c.GetContractStateByHash(rawHash.Uint160()) if err != nil { return cli.NewExitError(fmt.Errorf("can't fetch contract info: %w", err), 1) } diff --git a/cli/wallet_test.go b/cli/wallet_test.go index 67d44fa4b..e780e32f6 100644 --- a/cli/wallet_test.go +++ b/cli/wallet_test.go @@ -267,6 +267,11 @@ func TestImportDeployed(t *testing.T) { priv, err := keys.NewPrivateKey() require.NoError(t, err) + // missing contract sh + e.RunWithError(t, "neo-go", "wallet", "import-deployed", + "--rpc-endpoint", "http://"+e.RPC.Addr, + "--wallet", walletPath, "--wif", priv.WIF()) + e.In.WriteString("acc\rpass\rpass\r") e.Run(t, "neo-go", "wallet", "import-deployed", "--rpc-endpoint", "http://"+e.RPC.Addr,