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.
This commit is contained in:
Anna Shaleva 2021-04-19 17:46:27 +03:00
parent 0ccced2274
commit 2daae43eaf

View file

@ -193,11 +193,15 @@ func NewCommands() []cli.Command {
{ {
Name: "import-deployed", Name: "import-deployed",
Usage: "import deployed contract", Usage: "import deployed contract",
UsageText: "import-deployed --wallet <path> --wif <wif> --contract <hash>", UsageText: "import-deployed --wallet <path> --wif <wif> --contract <hash> [--name <account_name>]",
Action: importDeployed, Action: importDeployed,
Flags: append([]cli.Flag{ Flags: append([]cli.Flag{
walletPathFlag, walletPathFlag,
wifFlag, wifFlag,
cli.StringFlag{
Name: "name, n",
Usage: "Optional account name",
},
flags.AddressFlag{ flags.AddressFlag{
Name: "contract, c", Name: "contract, c",
Usage: "Contract hash or address", Usage: "Contract hash or address",
@ -466,6 +470,9 @@ func importDeployed(ctx *cli.Context) error {
} }
acc.Contract.Deployed = true acc.Contract.Deployed = true
if acc.Label == "" {
acc.Label = ctx.String("name")
}
if err := addAccountAndSave(wall, acc); err != nil { if err := addAccountAndSave(wall, acc); err != nil {
return cli.NewExitError(err, 1) return cli.NewExitError(err, 1)
} }