erigon-pulse/cmd/rpcdaemon/commands/get_balance.go
ledgerwatch b747ab5324
[WIP] CallTraces index (#1157)
* Initial commit for CallTraces index

* Fix compilation

* fix lint, add comment

* Fix integration

* Add Close function to ethdb.Cursor, fix some compile errors

* Try to stop cursor leak in Get

* Fix compile errors in RPC daemon

* Fix compile errors

* fixing another way

* Some fixes

* More fixes

* More fixes

* More fixes

* Fixes to core/state

* Fix lint

* Fix lint

* Fixes

* Stage caching for call trace stage

* Add mem stats

* Try to stop the leak

* Turn off debug

* Chunks for 10k blocks

* Print

* Revert "Print"

This reverts commit 5ffada4828d61e00e5dad1ca12c98258dfbbad00.

* Revert "Chunks for 10k blocks"

This reverts commit cfb9d498e782e5583d41c30abf0e2137da27383e.

* Trying to fix the leak

* Don't compute receipts in re-tracing

* Not compose block

* Print speed, fix receipts, bigger caches

* Fix lint

* Utilise changeset info

* Counters

* Use NoReceipts and ReadOnly

* ReadOnly is incompatible with caching

* Skip test leaking transactions

* Fix block test

* Change disable message for call-traces stage

* Use block option for call traces integration

* Fix retracing due to incarnation
2020-10-12 09:39:04 +01:00

37 lines
1.0 KiB
Go

package commands
import (
"context"
"fmt"
"math/big"
"github.com/ledgerwatch/turbo-geth/turbo/rpchelper"
"github.com/ledgerwatch/turbo-geth/common"
"github.com/ledgerwatch/turbo-geth/common/hexutil"
"github.com/ledgerwatch/turbo-geth/rpc"
)
func (api *APIImpl) GetBalance(ctx context.Context, address common.Address, blockNrOrHash rpc.BlockNumberOrHash) (*hexutil.Big, error) {
blockNumber, _, err := rpchelper.GetBlockNumber(blockNrOrHash, api.dbReader)
if err != nil {
return nil, err
}
tx, err1 := api.db.Begin(ctx, nil, false)
if err1 != nil {
return nil, fmt.Errorf("getBalance cannot open tx: %v", err1)
}
defer tx.Rollback()
acc, err := rpchelper.GetAccount(tx, blockNumber, address)
if err != nil {
return nil, fmt.Errorf("cant get a balance for account %q for block %v", address.String(), blockNumber)
}
if acc == nil {
// Special case - non-existent account is assumed to have zero balance
return (*hexutil.Big)(big.NewInt(0)), nil
}
return (*hexutil.Big)(acc.Balance.ToBig()), nil
}