indexer

package
v1.7.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 30, 2022 License: GPL-3.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrGetLastRetainedRound = errors.New("get last retained round error in db")
View Source
var ErrNotHealthy = errors.New("not healthy")

ErrNotHealthy is the error returned if the gateway is unhealthy.

Functions

func Logs2EthLogs

func Logs2EthLogs(logs []*Log, round uint64, blockHash, txHash common.Hash, startIndex uint, txIndex uint32) []*ethtypes.Log

Logs2EthLogs converts logs in db to ethereum logs.

func New

func New(
	ctxBackend context.Context,
	backendFactory BackendFactory,
	client client.RuntimeClient,
	runtimeID common.Namespace,
	storage storage.Storage,
	enablePruning bool,
	pruningStep uint64,
	indexingStart uint64,
) (*Service, Backend, filters.SubscribeBackend, error)

New creates a new indexer service.

Types

type Backend

type Backend interface {
	QueryableBackend
	GetEthInfoBackend

	// Index indexes a block.
	Index(
		oasisBlock *block.Block,
		txResults []*client.TransactionWithResults,
		blockGasLimit uint64,
	) error

	// Prune removes indexed data for rounds equal to or earlier than the passed round.
	Prune(round uint64) error

	// Close performs backend-specific cleanup. The backend should not be used anymore after calling
	// this method.
	Close()
}

Backend is the indexer backend interface.

type BackendFactory

type BackendFactory func(ctx context.Context, runtimeID common.Namespace, storage storage.Storage, sb filters.SubscribeBackend) (Backend, error)

BackendFactory is the indexer backend factory interface.

func NewIndexBackend

func NewIndexBackend() BackendFactory

NewIndexBackend returns a PsqlBackend.

type GetEthInfoBackend

type GetEthInfoBackend interface {
	GetBlockByRound(round uint64) (*model.Block, error)
	GetBlockByHash(blockHash ethcommon.Hash) (*model.Block, error)
	GetBlockTransactionCountByRound(round uint64) (int, error)
	GetBlockTransactionCountByHash(blockHash ethcommon.Hash) (int, error)
	GetTransactionByBlockHashAndIndex(blockHash ethcommon.Hash, txIndex int) (*model.Transaction, error)
	GetTransactionReceipt(txHash ethcommon.Hash) (map[string]interface{}, error)
	BlockNumber() (uint64, error)
	GetLogs(startRound, endRound uint64) ([]*model.Log, error)
}

GetEthInfoBackend is a backend for handling ethereum data.

type Log

type Log struct {
	Address common.Address `json:"address"`
	Topics  []common.Hash  `json:"topics"`
	Data    []byte         `json:"data"`
}

Log is the Oasis Log.

type QueryableBackend

type QueryableBackend interface {
	// QueryBlockRound queries block round by block hash.
	QueryBlockRound(blockHash ethcommon.Hash) (uint64, error)

	// QueryBlockHash queries block hash by round.
	QueryBlockHash(round uint64) (ethcommon.Hash, error)

	// QueryLastIndexedRound query continues indexed block round.
	QueryLastIndexedRound() (uint64, error)

	// QueryLastRetainedRound query the minimum round not pruned.
	QueryLastRetainedRound() (uint64, error)

	// QueryTransaction queries ethereum transaction by hash.
	QueryTransaction(ethTxHash ethcommon.Hash) (*model.Transaction, error)
}

QueryableBackend is the read-only indexer backend interface.

type Result

type Result struct {
	// TxHash is the hash of the matched transaction.
	TxHash hash.Hash
	// TxIndex is the index of the matched transaction within the block.
	TxIndex uint32
}

Result is a query result.

type Results

type Results map[uint64][]Result

Results are query results.

Map key is the round number and value is a list of transaction hashes that match the query.

type Service

type Service struct {
	service.BaseBackgroundService
	// contains filtered or unexported fields
}

Service is an indexer service.

func (*Service) Health

func (s *Service) Health() error

Implements server.HealthCheck.

func (*Service) Start

func (s *Service) Start()

Start starts service.

func (*Service) Stop

func (s *Service) Stop()

Stop stops service.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL