2022-10-11 12:34:32 +00:00
|
|
|
package requests
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2022-10-31 02:20:58 +00:00
|
|
|
|
2023-01-13 18:12:18 +00:00
|
|
|
libcommon "github.com/ledgerwatch/erigon-lib/common"
|
2023-05-20 20:57:32 +00:00
|
|
|
"github.com/ledgerwatch/log/v3"
|
2023-01-13 18:12:18 +00:00
|
|
|
|
2022-10-31 10:46:49 +00:00
|
|
|
"github.com/ledgerwatch/erigon/cmd/devnet/models"
|
2022-10-11 12:34:32 +00:00
|
|
|
)
|
|
|
|
|
2023-05-29 19:35:45 +00:00
|
|
|
func GetBalance(reqGen *RequestGenerator, address libcommon.Address, blockNum models.BlockNumber, logger log.Logger) (uint64, error) {
|
2023-05-31 18:47:32 +00:00
|
|
|
var b models.EthBalance
|
2022-10-11 12:34:32 +00:00
|
|
|
|
2022-10-31 10:46:49 +00:00
|
|
|
if res := reqGen.Erigon(models.ETHGetBalance, reqGen.GetBalance(address, blockNum), &b); res.Err != nil {
|
2022-10-11 12:34:32 +00:00
|
|
|
return 0, fmt.Errorf("failed to get balance: %v", res.Err)
|
|
|
|
}
|
2023-05-22 07:46:50 +00:00
|
|
|
if !b.Balance.ToInt().IsUint64() {
|
|
|
|
return 0, fmt.Errorf("balance is not uint64")
|
2022-10-11 12:34:32 +00:00
|
|
|
}
|
2023-05-22 07:46:50 +00:00
|
|
|
return b.Balance.ToInt().Uint64(), nil
|
2022-10-11 12:34:32 +00:00
|
|
|
}
|