erigon-pulse/cmd/devnet/requests/account.go
Leonard Chinonso 3163f40e58
Added Mechanism For Sending Raw Transaction (#5825)
- Added new requests for sending raw transactions
- Made provisions for other types of transactions generated, including
contracts
- Modified the models and services to accommodate general values
2022-10-31 17:46:49 +07:00

34 lines
839 B
Go

package requests
import (
"encoding/json"
"fmt"
"strconv"
"github.com/ledgerwatch/erigon/cmd/devnet/models"
"github.com/ledgerwatch/erigon/cmd/rpctest/rpctest"
"github.com/ledgerwatch/erigon/common"
)
func GetBalance(reqId int, address common.Address, blockNum models.BlockNumber) (uint64, error) {
reqGen := initialiseRequestGenerator(reqId)
var b rpctest.EthBalance
if res := reqGen.Erigon(models.ETHGetBalance, reqGen.GetBalance(address, blockNum), &b); res.Err != nil {
return 0, fmt.Errorf("failed to get balance: %v", res.Err)
}
bal, err := json.Marshal(b.Balance)
if err != nil {
fmt.Println(err)
}
balStr := string(bal)[3 : len(bal)-1]
balance, err := strconv.ParseInt(balStr, 16, 64)
if err != nil {
return 0, fmt.Errorf("cannot convert balance to decimal: %v", err)
}
return uint64(balance), nil
}