Skip to content

Commit

Permalink
fix multicheck
Browse files Browse the repository at this point in the history
  • Loading branch information
omerlavanet committed Dec 23, 2024
1 parent c54db98 commit 0e2fe56
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions utils/cli/multicheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"github.com/cosmos/cosmos-sdk/client/flags"
sdk "github.com/cosmos/cosmos-sdk/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
"github.com/lavanet/lava/v4/utils"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -45,21 +44,26 @@ func NewMultiCheckCmd() *cobra.Command {
return err
}

queryBalanceWithRetries := func(addr sdk.AccAddress) (*banktypes.QueryBalanceResponse, error) {
queryBalanceWithRetries := func(addr sdk.AccAddress) (*banktypes.QueryAllBalancesResponse, error) {
for i := 0; i < retries; i++ {
res, err := bankQuerier.Balance(cmd.Context(), &banktypes.QueryBalanceRequest{Address: addr.String()})
res, err := bankQuerier.AllBalances(cmd.Context(), &banktypes.QueryAllBalancesRequest{Address: addr.String()})
if err == nil {
// utils.LavaFormatDebug("query balance", utils.Attribute{Key: "address", Value: addr.String()}, utils.Attribute{Key: "balance", Value: res.Balances})
return res, nil
}
// else {
// utils.LavaFormatError("failed to query balance", err, utils.Attribute{Key: "address", Value: addr.String()})
// }
}
return nil, err
}

recordsLen := len(records)
lessThan := 0
others := 0
errors := 0
for i := 0; i < len(records); i++ {
fmt.Printf("\rProgress: %d/%d", i+1, recordsLen)
fmt.Printf("\rProgress: %d/%d errors: %d, lessThan:%d, others:%d", i+1, recordsLen, errors, lessThan, others)
coins, err := sdk.ParseCoinsNormalized(records[i][1])
if err != nil {
fmt.Printf("failed decoding coins record %d\n", i)
Expand All @@ -76,18 +80,20 @@ func NewMultiCheckCmd() *cobra.Command {
}

res, err := queryBalanceWithRetries(toAddr)
if err != nil {
utils.LavaFormatError("failed to query balance", err, utils.Attribute{Key: "address", Value: toAddr.String()})
if err != nil || res == nil {
errors++
// utils.LavaFormatError("failed to query balance", err, utils.Attribute{Key: "address", Value: toAddr.String()})
continue
}
found, coin := coins.Find("ulava")
if found {
if res.Balance.IsLT(coin) {
// this wallet has less than expected
fmt.Printf("wallet %s has less than expected\n", toAddr.String())
lessThan++
} else {
found, resCoin := res.Balances.Find("ulava")
if found && !resCoin.IsNil() && resCoin.IsGTE(coin) {
// this wallet has enough balance
others++
} else {
// fmt.Printf("wallet %s has less than expected\n", toAddr.String())
lessThan++
}
}
}
Expand Down

0 comments on commit 0e2fe56

Please sign in to comment.