mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2025-01-14 06:48:20 +00:00
0c91bfbf3e
* clean * save * pubsub * pubsub * pubsub * pubsub * pubsub * pubsub * save * tx pub-sub * tx pub-sub * clean * clean * save * save * save * save * save * Squashed 'interfaces/' content from commit c469f3ae0 git-subtree-dir: interfaces git-subtree-split: c469f3ae073b60c8821b61fed2910191080ef835 * save * save * save * save * Squashed 'interfaces/' changes from c469f3ae0..958dfc669 958dfc669 save git-subtree-dir: interfaces git-subtree-split: 958dfc669f8daeefe686a13aa852fb95f1537886 * save * save * up some deps * up some deps * clean * test * test * test * test * test * test * test * test * test * test * test * test
68 lines
2.1 KiB
Go
68 lines
2.1 KiB
Go
package rpchelper
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/ledgerwatch/turbo-geth/cmd/rpcdaemon/filters"
|
|
"github.com/ledgerwatch/turbo-geth/common"
|
|
"github.com/ledgerwatch/turbo-geth/core/rawdb"
|
|
"github.com/ledgerwatch/turbo-geth/core/types/accounts"
|
|
"github.com/ledgerwatch/turbo-geth/eth/stagedsync/stages"
|
|
"github.com/ledgerwatch/turbo-geth/ethdb"
|
|
"github.com/ledgerwatch/turbo-geth/rpc"
|
|
"github.com/ledgerwatch/turbo-geth/turbo/adapter"
|
|
)
|
|
|
|
func GetBlockNumber(blockNrOrHash rpc.BlockNumberOrHash, tx ethdb.Tx, filters *filters.Filters) (uint64, common.Hash, error) {
|
|
var blockNumber uint64
|
|
var err error
|
|
hash, ok := blockNrOrHash.Hash()
|
|
if !ok {
|
|
number := *blockNrOrHash.BlockNumber
|
|
if number == rpc.LatestBlockNumber {
|
|
blockNumber, err = stages.GetStageProgress(tx, stages.Execution)
|
|
if err != nil {
|
|
return 0, common.Hash{}, fmt.Errorf("getting latest block number: %w", err)
|
|
}
|
|
} else if number == rpc.EarliestBlockNumber {
|
|
blockNumber = 0
|
|
} else if number == rpc.PendingBlockNumber {
|
|
pendingBlock := filters.LastPendingBlock()
|
|
if pendingBlock == nil {
|
|
blockNumber, err = stages.GetStageProgress(tx, stages.Execution)
|
|
if err != nil {
|
|
return 0, common.Hash{}, fmt.Errorf("getting latest block number: %w", err)
|
|
}
|
|
} else {
|
|
return pendingBlock.NumberU64(), pendingBlock.Hash(), nil
|
|
}
|
|
} else {
|
|
blockNumber = uint64(number.Int64())
|
|
}
|
|
hash, err = rawdb.ReadCanonicalHash(tx, blockNumber)
|
|
if err != nil {
|
|
return 0, common.Hash{}, err
|
|
}
|
|
} else {
|
|
number := rawdb.ReadHeaderNumber(tx, hash)
|
|
if number == nil {
|
|
return 0, common.Hash{}, fmt.Errorf("block %x not found", hash)
|
|
}
|
|
blockNumber = *number
|
|
|
|
ch, err := rawdb.ReadCanonicalHash(tx, blockNumber)
|
|
if err != nil {
|
|
return 0, common.Hash{}, err
|
|
}
|
|
if blockNrOrHash.RequireCanonical && ch != hash {
|
|
return 0, common.Hash{}, fmt.Errorf("hash %q is not currently canonical", hash.String())
|
|
}
|
|
}
|
|
return blockNumber, hash, nil
|
|
}
|
|
|
|
func GetAccount(tx ethdb.Tx, blockNumber uint64, address common.Address) (*accounts.Account, error) {
|
|
reader := adapter.NewStateReader(tx, blockNumber)
|
|
return reader.ReadAccountData(address)
|
|
}
|