2020-07-21 14:31:02 +00:00
|
|
|
package commands
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
2020-08-19 11:46:20 +00:00
|
|
|
"github.com/ledgerwatch/turbo-geth/turbo/rpchelper"
|
2020-07-21 14:31:02 +00:00
|
|
|
|
|
|
|
"github.com/ledgerwatch/turbo-geth/common"
|
|
|
|
"github.com/ledgerwatch/turbo-geth/common/hexutil"
|
|
|
|
"github.com/ledgerwatch/turbo-geth/rpc"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (api *APIImpl) GetBalance(_ context.Context, address common.Address, blockNrOrHash rpc.BlockNumberOrHash) (*hexutil.Big, error) {
|
2020-08-19 11:46:20 +00:00
|
|
|
blockNumber, _, err := rpchelper.GetBlockNumber(blockNrOrHash, api.dbReader)
|
2020-07-29 16:21:34 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2020-08-19 11:46:20 +00:00
|
|
|
acc, err := rpchelper.GetAccount(api.db, blockNumber, address)
|
2020-07-29 16:21:34 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("cant get a balance for account %q for block %v", address.String(), blockNumber)
|
|
|
|
}
|
|
|
|
|
|
|
|
return (*hexutil.Big)(acc.Balance.ToBig()), nil
|
|
|
|
}
|