bloomservice

package
v0.0.0-...-24e5678 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2023 License: LGPL-3.0 Imports: 54 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidType   = errors.New("invalid Type")
	ErrFileRead      = errors.New("File Read Error")
	ErrNotFoundEvent = errors.New("Event Not Found")
	ErrArgument      = errors.New("Argument Error")
)
View Source
var (
	Zero       = big.NewInt(0)
	ZeroAmount = amount.NewAmount(0, 0)
	MaxUint256 = ToAmount(Sub(Exp(big.NewInt(2), big.NewInt(256)), big.NewInt(1)))

	ZeroAddress = common.Address{}
)

Functions

func AppendBloom

func AppendBloom(bin *etypes.Bloom, receipts etypes.Receipts)

AppendBloom appends the given Receipts (+Logs) to bloom

func BlockLogsBloom

func BlockLogsBloom(cn *chain.Chain, b *types.Block) (etypes.Bloom, error)

BlockLogsBloom retrurn block's logsBloom

func CreateEventBloom

func CreateEventBloom(provider types.Provider, events []*ctypes.Event) (etypes.Bloom, error)

CreateEventBloom creates a bloom filter from the given go-type contract events

func EventsToFullLogs

func EventsToFullLogs(chain *chain.Chain, header *mtypes.Header, tx *mtypes.Transaction, evs []*ctypes.Event, idx uint16) ([]*types.Log, error)

EventsToLogs converts non-evm type events to ethereum type logs

func Exec

func Exec(ctx *types.Context, user common.Address, contAddr common.Address, methodName string, args []interface{}) ([]interface{}, error)

Exec calls ContractContext.Exec from Context

func Exp

func Exp(a, b *big.Int) *big.Int

Exp : exponential

func FindCallHistoryEvents

func FindCallHistoryEvents(evs []*ctypes.Event, idx uint16) ([]*ctypes.Event, error)

findTransactionsEvents find tx's EventTagCallHistory-type events from given event list

func GetCC

func GetCC(ctx *types.Context, contAddr common.Address, user common.Address) (*types.ContractContext, error)

GetCC gets ContractContext from Contex with given contract address and user address

func NewTestBlockChain

func NewTestBlockChain(path string, deletePath bool, chainID *big.Int, version uint16, genesis *types.Context, admin common.Address, cfg *initContextInfo, classMap map[string]uint64) (*testBlockChain, error)

NewTestBlockChain makes new test blockchain

func RegisterContracts

func RegisterContracts() map[string]uint64

RegisterContracts creates classmap for deploying contracts ususally in genesis

func Sub

func Sub(a, b *big.Int) *big.Int

Sub : sub

func ToAmount

func ToAmount(b *big.Int) *amount.Amount

ToAmount converts big.Int to amount.Amount

func TokenApprove

func TokenApprove(ctx *types.Context, token, owner, spender common.Address) error

TokenApprove call token.Apporve(to,Amount) from Context

func TxLogsBloom

func TxLogsBloom(cn *chain.Chain, b *types.Block, idx uint16, receipt *etypes.Receipt) (etypes.Bloom, []*etypes.Log, error)

TxLogsBloom retrurn transaction's logsBloom ( idx-th tx in block b)

Types

type BloomBitService

type BloomBitService struct {
	// contains filtered or unexported fields
}

func NewBloomBitService

func NewBloomBitService(cn *chain.Chain, path string, size, confirms uint64) (*BloomBitService, error)

NewBloomBitService starts a bloom service that performs bloom bit indexer and returns it

func (*BloomBitService) BloomStatus

func (b *BloomBitService) BloomStatus() (uint64, uint64)

BloomStatus retrives the bloom size and sections

func (*BloomBitService) Close

func (b *BloomBitService) Close() error

Close closes Database

func (*BloomBitService) Name

func (b *BloomBitService) Name() string

Name returns the name of the service

func (*BloomBitService) OnBlockConnected

func (b *BloomBitService) OnBlockConnected(block *types.Block, loader types.Loader)

OnBlockConnected called when a block is connected to the chain

func (*BloomBitService) OnLoadChain

func (b *BloomBitService) OnLoadChain(loader types.Loader) error

OnLoadChain called when the chain loaded

func (*BloomBitService) OnTransactionFail

func (b *BloomBitService) OnTransactionFail(height uint32, txs []*types.Transaction, err []error)

OnTransactionFail called when a transaction in pool is expired

func (*BloomBitService) OnTransactionInPoolExpired

func (b *BloomBitService) OnTransactionInPoolExpired(txs []*types.Transaction)

OnTransactionInPoolExpired called when a transaction in pool is expired

func (*BloomBitService) ServiceFilter

func (b *BloomBitService) ServiceFilter(ctx context.Context, session *bloombits.MatcherSession)

type BloomIndexer

type BloomIndexer struct {
	// contains filtered or unexported fields
}

BloomIndexer implements a core.ChainIndexer, building up a rotated bloom bits index for the Ethereum header bloom filters, permitting blazing fast filtering.

func (*BloomIndexer) Commit

func (b *BloomIndexer) Commit() error

Commit implements core.ChainIndexerBackend, finalizing the bloom section and writing it out into the database.

func (*BloomIndexer) OpenDatabase

func (b *BloomIndexer) OpenDatabase(path string, cache, handles int, namespace string, readonly bool) (ethdb.Database, error)

OpenDatabase opens an existing database with the given name (or creates one if no previous can be found) from within the node's instance directory. If the node is ephemeral, a memory database is returned.

func (*BloomIndexer) Process

func (b *BloomIndexer) Process(ctx context.Context, block *mtypes.Block) error

Process implements core.ChainIndexerBackend, adding a new header's bloom into the index.

func (*BloomIndexer) Reset

func (b *BloomIndexer) Reset(ctx context.Context, section uint64, lastSectionHead common.Hash) error

Reset implements core.ChainIndexerBackend, starting a new bloombits index section.

type ChainIndexer

type ChainIndexer struct {
	// contains filtered or unexported fields
}

ChainIndexer does a post-processing job for equally sized sections of the canonical chain (like BlooomBits and CHT structures). A ChainIndexer is connected to the blockchain through the event system by starting a ChainHeadEventLoop in a goroutine.

Further child ChainIndexers can be added which use the output of the parent section indexer. These child indexers receive new head notifications only after an entire section has been finished or in case of rollbacks that might affect already finished sections.

func NewBloomIndexer

func NewBloomIndexer(cn *chain.Chain, path string, size, confirms uint64) (*ChainIndexer, error)

NewBloomIndexer returns a bloom indexer that generates bloom bits data for the canonical chain for fast logs filtering.

func NewChainIndexer

func NewChainIndexer(cn *chain.Chain, chainDb ethdb.Database, indexDb ethdb.Database, backend ChainIndexerBackend, section, confirm uint64, throttling time.Duration, kind string) *ChainIndexer

NewChainIndexer creates a new chain indexer to do background processing on chain segments of a given size after certain number of confirmations passed. The throttling parameter might be used to prevent database thrashing.

func (*ChainIndexer) AddCheckpoint

func (c *ChainIndexer) AddCheckpoint(section uint64, shead common.Hash)

AddCheckpoint adds a checkpoint. Sections are never processed and the chain is not expected to be available before this point. The indexer assumes that the backend has sufficient information available to process subsequent sections.

Note: knownSections == 0 and storedSections == checkpointSections until syncing reaches the checkpoint

func (*ChainIndexer) Close

func (c *ChainIndexer) Close() error

Close tears down all goroutines belonging to the indexer and returns any error that might have occurred internally.

func (*ChainIndexer) SectionHead

func (c *ChainIndexer) SectionHead(section uint64) common.Hash

SectionHead retrieves the last block hash of a processed section from the index database.

func (*ChainIndexer) Sections

func (c *ChainIndexer) Sections() (uint64, uint64, common.Hash)

Sections returns the number of processed sections maintained by the indexer and also the information about the last header indexed for potential canonical verifications.

type ChainIndexerBackend

type ChainIndexerBackend interface {
	// Reset initiates the processing of a new chain segment, potentially terminating
	// any partially completed operations (in case of a reorg).
	Reset(ctx context.Context, section uint64, prevHead common.Hash) error

	// Process crunches through the next header in the chain segment. The caller
	// will ensure a sequential order of headers.
	Process(ctx context.Context, block *mtypes.Block) error

	// Commit finalizes the section metadata and stores it into the database.
	Commit() error
}

ChainIndexerBackend defines the methods needed to process chain segments in the background and write the segment results into the database. These can be used to create filter blooms or CHTs.

type Filter

type Filter struct {
	// contains filtered or unexported fields
}

Filter can be used to retrieve and filter logs.

func NewBlockFilter

func NewBlockFilter(backend *chain.Chain, ts IBlockHeight, block common.Hash, addresses []common.Address, topics [][]common.Hash) *Filter

NewBlockFilter creates a new filter which directly inspects the contents of a block to figure out whether it is interesting or not.

func NewRangeFilter

func NewRangeFilter(backend *chain.Chain, ts IBlockHeight, bs *BloomBitService, begin, end int64, addresses []common.Address, topics [][]common.Hash) *Filter

NewRangeFilter creates a new filter which uses a bloom filter on blocks to figure out whether a particular block is interesting or not.

func (*Filter) Logs

func (f *Filter) Logs(ctx context.Context) ([]*types.Log, error)

Logs searches the blockchain for matching log entries, returning all from the first block that contains matches, updating the start of the filter accordingly.

type FilterQuery

type FilterQuery struct {
	BlockHash *common.Hash     // used by eth_getLogs, return logs only from block with this hash
	FromBlock *big.Int         // beginning of the queried range, nil means genesis block
	ToBlock   *big.Int         // end of the range, nil means latest block
	Addresses []common.Address // restricts matches to events created by specific contracts

	// The Topic list restricts matches to particular event topics. Each event has a list
	// of topics. Topics matches a prefix of that list. An empty element slice matches any
	// topic. Non-empty elements represent an alternative that matches any of the
	// contained topics.
	//
	// Examples:
	// [] or nil          matches any topic list
	// [A,B]              matches topic (A OR B) in first position
	// [[A]]              matches topic A in first position
	// [[], [B]]          matches any topic in first position AND B in second position
	// [[A], [B]]         matches topic A in first position AND B in second position
	// [[A, B], [C, D]]   matches topic (A OR B) in first position AND (C OR D) in second position
	Topics [][]common.Hash
}

FilterQuery contains options for contract log filtering.

func ToFilter

func ToFilter(arg map[string]interface{}) FilterQuery

ToFilter converts map[string]interface{} to FilterQuery struct

type IBlockHeight

type IBlockHeight interface {
	BlockHeight(bh hash.Hash256) (uint32, error)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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