cli: add nep11 remove command

This commit is contained in:
Anna Shaleva 2021-04-23 18:08:47 +03:00
parent 5fdb8e2a01
commit 3742e38399
3 changed files with 31 additions and 1 deletions

View file

@ -1,6 +1,7 @@
package main
import (
"io"
"os"
"path"
"testing"
@ -61,4 +62,14 @@ func TestNEP11Import(t *testing.T) {
checkNNSInfo(t)
})
})
t.Run("Remove", func(t *testing.T) {
e.In.WriteString("y\r")
e.Run(t, "neo-go", "wallet", "nep11", "remove",
"--wallet", walletPath, "--token", nnsContractHash.StringLE())
e.Run(t, "neo-go", "wallet", "nep11", "info",
"--wallet", walletPath)
_, err := e.Out.ReadString('\n')
require.Equal(t, err, io.EOF)
})
}

View file

@ -24,6 +24,17 @@ func newNEP11Commands() []cli.Command {
tokenFlag,
},
},
{
Name: "remove",
Usage: "remove NEP11 token from the wallet",
UsageText: "remove --wallet <path> --token <hash-or-name>",
Action: removeNEP11Token,
Flags: []cli.Flag{
walletPathFlag,
tokenFlag,
forceFlag,
},
},
}
}
@ -34,3 +45,7 @@ func importNEP11Token(ctx *cli.Context) error {
func printNEP11Info(ctx *cli.Context) error {
return printNEPInfo(ctx, manifest.NEP11StandardName)
}
func removeNEP11Token(ctx *cli.Context) error {
return removeNEPToken(ctx, manifest.NEP11StandardName)
}

View file

@ -345,13 +345,17 @@ func printNEPInfo(ctx *cli.Context, standard string) error {
}
func removeNEP17Token(ctx *cli.Context) error {
return removeNEPToken(ctx, manifest.NEP17StandardName)
}
func removeNEPToken(ctx *cli.Context, standard string) error {
wall, err := openWallet(ctx.String("wallet"))
if err != nil {
return cli.NewExitError(err, 1)
}
defer wall.Close()
token, err := getMatchingToken(ctx, wall, ctx.String("token"), manifest.NEP17StandardName)
token, err := getMatchingToken(ctx, wall, ctx.String("token"), standard)
if err != nil {
return cli.NewExitError(err, 1)
}