mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2024-12-25 04:57:17 +00:00
5b634a790e
* save * save * save * save * save * save * save * save * save * save * save * save * save * save * save * save * save * save * save * save * save * save * save * save * save * save * save * save * save * save * save * save * save * save * save * save * save * save
36 lines
970 B
Go
36 lines
970 B
Go
package snapshotsync
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/ledgerwatch/erigon-lib/kv"
|
|
"github.com/ledgerwatch/erigon/common"
|
|
"github.com/ledgerwatch/erigon/core/rawdb"
|
|
"github.com/ledgerwatch/erigon/core/types"
|
|
)
|
|
|
|
// BlockReader can read blocks from db and snapshots
|
|
type BlockReader struct {
|
|
}
|
|
|
|
func NewBlockReader() *BlockReader {
|
|
return &BlockReader{}
|
|
}
|
|
|
|
func (back *BlockReader) BlockWithSenders(ctx context.Context, tx kv.Tx, hash common.Hash, blockHeight uint64) (block *types.Block, senders []common.Address, err error) {
|
|
canonicalHash, err := rawdb.ReadCanonicalHash(tx, blockHeight)
|
|
if err != nil {
|
|
return nil, nil, fmt.Errorf("requested non-canonical hash %x. canonical=%x", hash, canonicalHash)
|
|
}
|
|
if canonicalHash == hash {
|
|
block, senders, err = rawdb.ReadBlockWithSenders(tx, hash, blockHeight)
|
|
if err != nil {
|
|
return nil, nil, err
|
|
}
|
|
return block, senders, nil
|
|
}
|
|
|
|
return rawdb.NonCanonicalBlockWithSenders(tx, hash, blockHeight)
|
|
}
|