mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-11-29 23:33:37 +00:00
cli: implement wallet nep5 remove
Remove unused tokens from the wallet.
This commit is contained in:
parent
9a41ffb9fb
commit
325dc7d0e4
1 changed files with 42 additions and 0 deletions
|
@ -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",
|
||||
Usage: "transfer NEP5 tokens",
|
||||
|
@ -260,6 +274,34 @@ func printNEP5Info(ctx *cli.Context) error {
|
|||
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 {
|
||||
wall, err := openWallet(ctx.String("path"))
|
||||
if err != nil {
|
||||
|
|
Loading…
Reference in a new issue