forked from TrueCloudLab/neoneo-go
cli: add nep11 info
command
This commit is contained in:
parent
ba8b0fd7b0
commit
5fdb8e2a01
3 changed files with 49 additions and 4 deletions
|
@ -6,6 +6,8 @@ import (
|
|||
"testing"
|
||||
|
||||
"github.com/nspcc-dev/neo-go/pkg/core/native/nativenames"
|
||||
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
|
||||
"github.com/nspcc-dev/neo-go/pkg/smartcontract/manifest"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
|
@ -38,4 +40,25 @@ func TestNEP11Import(t *testing.T) {
|
|||
|
||||
// not a NEP11 token
|
||||
e.RunWithError(t, append(args, "--token", neoContractHash.StringLE())...)
|
||||
|
||||
t.Run("Info", func(t *testing.T) {
|
||||
checkNNSInfo := func(t *testing.T) {
|
||||
e.checkNextLine(t, "^Name:\\s*NameService")
|
||||
e.checkNextLine(t, "^Symbol:\\s*NNS")
|
||||
e.checkNextLine(t, "^Hash:\\s*"+nnsContractHash.StringLE())
|
||||
e.checkNextLine(t, "^Decimals:\\s*0")
|
||||
e.checkNextLine(t, "^Address:\\s*"+address.Uint160ToString(nnsContractHash))
|
||||
e.checkNextLine(t, "^Standard:\\s*"+string(manifest.NEP11StandardName))
|
||||
}
|
||||
t.Run("WithToken", func(t *testing.T) {
|
||||
e.Run(t, "neo-go", "wallet", "nep11", "info",
|
||||
"--wallet", walletPath, "--token", nnsContractHash.StringLE())
|
||||
checkNNSInfo(t)
|
||||
})
|
||||
t.Run("NoToken", func(t *testing.T) {
|
||||
e.Run(t, "neo-go", "wallet", "nep11", "info",
|
||||
"--wallet", walletPath)
|
||||
checkNNSInfo(t)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
|
|
@ -14,9 +14,23 @@ func newNEP11Commands() []cli.Command {
|
|||
Action: importNEP11Token,
|
||||
Flags: importFlags,
|
||||
},
|
||||
{
|
||||
Name: "info",
|
||||
Usage: "print imported NEP11 token info",
|
||||
UsageText: "print --wallet <path> [--token <hash-or-name>]",
|
||||
Action: printNEP11Info,
|
||||
Flags: []cli.Flag{
|
||||
walletPathFlag,
|
||||
tokenFlag,
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func importNEP11Token(ctx *cli.Context) error {
|
||||
return importNEPToken(ctx, manifest.NEP11StandardName)
|
||||
}
|
||||
|
||||
func printNEP11Info(ctx *cli.Context) error {
|
||||
return printNEPInfo(ctx, manifest.NEP11StandardName)
|
||||
}
|
||||
|
|
|
@ -312,6 +312,10 @@ func printTokenInfo(ctx *cli.Context, tok *wallet.Token) {
|
|||
}
|
||||
|
||||
func printNEP17Info(ctx *cli.Context) error {
|
||||
return printNEPInfo(ctx, manifest.NEP17StandardName)
|
||||
}
|
||||
|
||||
func printNEPInfo(ctx *cli.Context, standard string) error {
|
||||
wall, err := openWallet(ctx.String("wallet"))
|
||||
if err != nil {
|
||||
return cli.NewExitError(err, 1)
|
||||
|
@ -319,7 +323,7 @@ func printNEP17Info(ctx *cli.Context) error {
|
|||
defer wall.Close()
|
||||
|
||||
if name := ctx.String("token"); name != "" {
|
||||
token, err := getMatchingToken(ctx, wall, name, manifest.NEP17StandardName)
|
||||
token, err := getMatchingToken(ctx, wall, name, standard)
|
||||
if err != nil {
|
||||
return cli.NewExitError(err, 1)
|
||||
}
|
||||
|
@ -327,11 +331,15 @@ func printNEP17Info(ctx *cli.Context) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
for i, t := range wall.Extra.Tokens {
|
||||
if i > 0 {
|
||||
var count int
|
||||
for _, t := range wall.Extra.Tokens {
|
||||
if count > 0 {
|
||||
fmt.Fprintln(ctx.App.Writer)
|
||||
}
|
||||
printTokenInfo(ctx, t)
|
||||
if t.Standard == standard {
|
||||
printTokenInfo(ctx, t)
|
||||
count++
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue