cli: add nep11 ownerOf
command
This commit is contained in:
parent
946e940ce0
commit
4e55b1a9ed
2 changed files with 59 additions and 1 deletions
|
@ -85,7 +85,7 @@ func TestNEP11Import(t *testing.T) {
|
|||
})
|
||||
}
|
||||
|
||||
func TestNEP11_BalanceOf_Transfer(t *testing.T) {
|
||||
func TestNEP11_OwnerOf_BalanceOf_Transfer(t *testing.T) {
|
||||
e := newExecutor(t, true)
|
||||
|
||||
tmpDir, err := ioutil.TempDir(os.TempDir(), "neogo.test.nftwallet*")
|
||||
|
@ -176,6 +176,21 @@ func TestNEP11_BalanceOf_Transfer(t *testing.T) {
|
|||
e.Run(t, "neo-go", "wallet", "nep11", "remove",
|
||||
"--wallet", wall, "--token", h.StringLE())
|
||||
|
||||
// ownerOf: missing contract hash
|
||||
cmdOwnerOf := []string{"neo-go", "wallet", "nep11", "ownerOf",
|
||||
"--rpc-endpoint", "http://" + e.RPC.Addr,
|
||||
}
|
||||
e.RunWithError(t, cmdOwnerOf...)
|
||||
cmdOwnerOf = append(cmdOwnerOf, "--token", h.StringLE())
|
||||
|
||||
// ownerOf: missing token ID
|
||||
e.RunWithError(t, cmdOwnerOf...)
|
||||
cmdOwnerOf = append(cmdOwnerOf, "--id", string(tokenID))
|
||||
|
||||
// ownerOf: good
|
||||
e.Run(t, cmdOwnerOf...)
|
||||
e.checkNextLine(t, nftOwnerAddr)
|
||||
|
||||
cmdTransfer := []string{
|
||||
"neo-go", "wallet", "nep11", "transfer",
|
||||
"--rpc-endpoint", "http://" + e.RPC.Addr,
|
||||
|
|
|
@ -19,6 +19,10 @@ import (
|
|||
)
|
||||
|
||||
func newNEP11Commands() []cli.Command {
|
||||
tokenAddressFlag := flags.AddressFlag{
|
||||
Name: "token",
|
||||
Usage: "Token contract address or hash in LE",
|
||||
}
|
||||
tokenID := cli.StringFlag{
|
||||
Name: "id",
|
||||
Usage: "Token ID",
|
||||
|
@ -83,6 +87,16 @@ func newNEP11Commands() []cli.Command {
|
|||
signer.
|
||||
`,
|
||||
},
|
||||
{
|
||||
Name: "ownerOf",
|
||||
Usage: "print owner of non-divisible NEP11 token with the specified ID",
|
||||
UsageText: "ownerOf --rpc-endpoint <node> --timeout <time> --token <hash> --id <token-id>",
|
||||
Action: printNEP11Owner,
|
||||
Flags: append([]cli.Flag{
|
||||
tokenAddressFlag,
|
||||
tokenID,
|
||||
}, options.RPC...),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -221,3 +235,32 @@ func signAndSendNEP11Transfer(ctx *cli.Context, c *client.Client, acc *wallet.Ac
|
|||
fmt.Fprintln(ctx.App.Writer, tx.Hash().StringLE())
|
||||
return nil
|
||||
}
|
||||
|
||||
func printNEP11Owner(ctx *cli.Context) error {
|
||||
var err error
|
||||
tokenHash := ctx.Generic("token").(*flags.Address)
|
||||
if !tokenHash.IsSet {
|
||||
return cli.NewExitError("token contract hash was not set", 1)
|
||||
}
|
||||
|
||||
tokenID := ctx.String("id")
|
||||
if tokenID == "" {
|
||||
return cli.NewExitError(errors.New("token ID should be specified"), 1)
|
||||
}
|
||||
|
||||
gctx, cancel := options.GetTimeoutContext(ctx)
|
||||
defer cancel()
|
||||
|
||||
c, err := options.GetRPCClient(gctx, ctx)
|
||||
if err != nil {
|
||||
return cli.NewExitError(err, 1)
|
||||
}
|
||||
|
||||
result, err := c.NEP11NDOwnerOf(tokenHash.Uint160(), tokenID)
|
||||
if err != nil {
|
||||
return cli.NewExitError(fmt.Sprintf("failed to call NEP11 `ownerOf` method: %s", err.Error()), 1)
|
||||
}
|
||||
|
||||
fmt.Fprintln(ctx.App.Writer, address.Uint160ToString(result))
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue