github.com/MetalBlockchain/metalgo@v1.11.9/vms/example/xsvm/cmd/account/cmd.go (about)

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