cli: implement wallet nep5 remove

Remove unused tokens from the wallet.
This commit is contained in:
Evgenii Stratonikov 2020-03-13 17:15:39 +03:00
parent 9a41ffb9fb
commit 325dc7d0e4

View file

@ -66,6 +66,20 @@ func newNEP5Commands() []cli.Command {
}, },
}, },
}, },
{
Name: "remove",
Usage: "remove NEP5 token from the wallet",
UsageText: "remove --path <path> <hash-or-name>",
Action: removeNEP5Token,
Flags: []cli.Flag{
walletPathFlag,
cli.StringFlag{
Name: "token",
Usage: "Token name or hash",
},
forceFlag,
},
},
{ {
Name: "transfer", Name: "transfer",
Usage: "transfer NEP5 tokens", Usage: "transfer NEP5 tokens",
@ -260,6 +274,34 @@ func printNEP5Info(ctx *cli.Context) error {
return nil return nil
} }
func removeNEP5Token(ctx *cli.Context) error {
wall, err := openWallet(ctx.String("path"))
if err != nil {
return cli.NewExitError(err, 1)
}
defer wall.Close()
name := ctx.Args().First()
if name == "" {
return cli.NewExitError("token must be specified", 1)
}
token, err := getMatchingToken(wall, name)
if err != nil {
return cli.NewExitError(err, 1)
}
if !ctx.Bool("force") {
if ok := askForConsent(); !ok {
return nil
}
}
if err := wall.RemoveToken(token.Hash); err != nil {
return cli.NewExitError(fmt.Errorf("can't remove token: %v", err), 1)
} else if err := wall.Save(); err != nil {
return cli.NewExitError(fmt.Errorf("error while saving wallet: %v", err), 1)
}
return nil
}
func transferNEP5(ctx *cli.Context) error { func transferNEP5(ctx *cli.Context) error {
wall, err := openWallet(ctx.String("path")) wall, err := openWallet(ctx.String("path"))
if err != nil { if err != nil {