2022-01-14 13:08:41 +00:00
|
|
|
package commands
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2022-03-17 20:16:02 +00:00
|
|
|
"github.com/ledgerwatch/erigon/cmd/devnettest/services"
|
2022-01-14 13:08:41 +00:00
|
|
|
|
|
|
|
"github.com/ledgerwatch/erigon/cmd/devnettest/requests"
|
|
|
|
"github.com/ledgerwatch/erigon/common"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
addr string
|
|
|
|
blockNum string
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
getBalanceCmd.Flags().StringVar(&addr, "addr", "", "String address to check")
|
|
|
|
getBalanceCmd.MarkFlagRequired("addr")
|
|
|
|
getBalanceCmd.Flags().StringVar(&blockNum, "block-num", "latest", "String denoting block number")
|
|
|
|
|
|
|
|
rootCmd.AddCommand(getBalanceCmd)
|
|
|
|
}
|
|
|
|
|
|
|
|
var getBalanceCmd = &cobra.Command{
|
|
|
|
Use: "get-balance",
|
|
|
|
Short: "Checks balance by address",
|
|
|
|
Args: func(cmd *cobra.Command, args []string) error {
|
|
|
|
switch blockNum {
|
|
|
|
case "pending", "latest", "earliest":
|
|
|
|
default:
|
2022-03-17 20:16:02 +00:00
|
|
|
return fmt.Errorf("block number must be 'pending', 'latest' or 'earliest'")
|
2022-01-14 13:08:41 +00:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
|
|
if clearDev {
|
2022-03-17 20:16:02 +00:00
|
|
|
defer services.ClearDevDB()
|
2022-01-14 13:08:41 +00:00
|
|
|
}
|
|
|
|
toAddress := common.HexToAddress(addr)
|
2022-03-17 20:16:02 +00:00
|
|
|
if err := requests.GetBalance(reqId, toAddress, blockNum); err != nil {
|
|
|
|
fmt.Printf("could not get balance: %v", err)
|
|
|
|
}
|
2022-01-14 13:08:41 +00:00
|
|
|
},
|
|
|
|
}
|