add a command to check wallet balance

This commit is contained in:
whyrusleeping
2019-07-18 13:26:04 -07:00
parent 27a7858055
commit f0841203a3
6 changed files with 64 additions and 2 deletions
+27
View File
@@ -3,6 +3,7 @@ package cli
import (
"fmt"
"github.com/filecoin-project/go-lotus/chain/address"
"gopkg.in/urfave/cli.v2"
)
@@ -12,6 +13,7 @@ var walletCmd = &cli.Command{
Subcommands: []*cli.Command{
walletNew,
walletList,
walletBalance,
},
}
@@ -62,3 +64,28 @@ var walletList = &cli.Command{
return nil
},
}
var walletBalance = &cli.Command{
Name: "balance",
Usage: "get account balance",
Action: func(cctx *cli.Context) error {
api, err := getAPI(cctx)
if err != nil {
return err
}
ctx := reqContext(cctx)
addr, err := address.NewFromString(cctx.Args().First())
if err != nil {
return err
}
balance, err := api.WalletBalance(ctx, addr)
if err != nil {
return err
}
fmt.Printf("%s\n", balance.String())
return nil
},
}