-
Notifications
You must be signed in to change notification settings - Fork 671
/
cmd.go
47 lines (37 loc) · 956 Bytes
/
cmd.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package account
import (
"log"
"github.com/spf13/cobra"
"github.com/ava-labs/avalanchego/vms/example/xsvm/api"
)
func Command() *cobra.Command {
c := &cobra.Command{
Use: "account",
Short: "Displays the state of the requested account",
RunE: accountFunc,
}
flags := c.Flags()
AddFlags(flags)
return c
}
func accountFunc(c *cobra.Command, args []string) error {
flags := c.Flags()
config, err := ParseFlags(flags, args)
if err != nil {
return err
}
ctx := c.Context()
client := api.NewClient(config.URI, config.ChainID)
nonce, err := client.Nonce(ctx, config.Address)
if err != nil {
return err
}
balance, err := client.Balance(ctx, config.Address, config.AssetID)
if err != nil {
return err
}
log.Printf("%s has %d of %s with nonce %d\n", config.Address, balance, config.AssetID, nonce)
return nil
}