store

package
v0.0.0-...-52d15e0 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2023 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var StateSyncEventABI = abi.MustNewEvent("event StateSynced(uint256 indexed id, " +
	"address indexed sender, address indexed receiver, bytes data)")

Functions

func CreateTestLogForStateSyncEvent

func CreateTestLogForStateSyncEvent(t *testing.T, blockNumber, logIndex uint64) *ethgo.Log

Types

type BoltDBEventTrackerStore

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

BoltDBEventTrackerStore represents a store for event tracker events

func NewBoltDBEventTrackerStore

func NewBoltDBEventTrackerStore(dbPath string) (*BoltDBEventTrackerStore, error)

NewBoltDBEventTrackerStore is a constructor function that creates a new instance of the BoltDBEventTrackerStore struct.

Example Usage:

t := NewBoltDBEventTrackerStore(/edge/polybft/consensus/deposit.db)

Inputs:

  • dbPath (string): Full path to the event tracker store db.

Outputs:

  • A new instance of the BoltDBEventTrackerStore struct with a connection to the event tracker store db.

func NewTestTrackerStore

func NewTestTrackerStore(tb testing.TB) *BoltDBEventTrackerStore

NewTestTrackerStore creates new instance of state used by tests.

func (*BoltDBEventTrackerStore) GetAllLogs

func (p *BoltDBEventTrackerStore) GetAllLogs() ([]*ethgo.Log, error)

GetAllLogs retrieves all logs from the logs bucket in the BoltDB database and returns them as a slice of ethgo.Log structs.

Example Usage: store := NewBoltDBEventTrackerStore("path/to/db") logs, err := store.GetAllLogs()

if err != nil {
    fmt.Println("Error:", err)
    return
}

for _, log := range logs {
    fmt.Println(log)
}

Outputs: The code snippet returns a slice of ethgo.Log structs (logs) and an error (err). The logs slice contains all the logs stored in the logs bucket in the BoltDB database. The error will be non-nil if there was an issue with the read transaction or unmarshaling the log structs.

func (*BoltDBEventTrackerStore) GetLastProcessedBlock

func (p *BoltDBEventTrackerStore) GetLastProcessedBlock() (uint64, error)

GetLastProcessedBlock retrieves the last processed block number from a BoltDB database.

Example Usage:

store := NewBoltDBEventTrackerStore(db)
blockNumber, err := store.GetLastProcessedBlock()
if err != nil {
  fmt.Println("Error:", err)
} else {
  fmt.Println("Last processed block number:", blockNumber)
}

Outputs:

blockNumber: The last processed block number retrieved from the database.
err: Any error that occurred during the database operation.

func (*BoltDBEventTrackerStore) GetLog

func (p *BoltDBEventTrackerStore) GetLog(blockNumber, logIndex uint64) (*ethgo.Log, error)

GetLog retrieves a log from the BoltDB database based on the given block number and log index.

Example Usage:

	store := &BoltDBEventTrackerStore{db: boltDB}
 	block := uint64(10)
	logIndex := uint64(1)
	log, err := store.GetLog(block, logIndex)
	if err != nil {
	  fmt.Println("Error getting log of index: %d for block: %d. Err: %w", logIndex, block, err)
	}

Inputs:

  • blockNumber (uint64): The block number of the desired log.
  • logIndex (uint64): The index of the desired log within the block.

Outputs:

  • log (*ethgo.Log): The retrieved log from the BoltDB database. If the log does not exist, it will be nil.
  • err (error): Any error that occurred during the database operation. If no error occurred, it will be nil.

func (*BoltDBEventTrackerStore) GetLogsByBlockNumber

func (p *BoltDBEventTrackerStore) GetLogsByBlockNumber(blockNumber uint64) ([]*ethgo.Log, error)

GetLogsByBlockNumber retrieves all logs that happened in given block from a BoltDB database.

Example Usage:

	store := &BoltDBEventTrackerStore{db: boltDB}
 	block := uint64(10)
	logs, err := store.GetLogsByBlockNumber(block)
	if err != nil {
	  fmt.Println("Error getting logs for block: %d. Err: %w", block, err)
	}

Inputs: - blockNumber (uint64): The block number for which the logs need to be retrieved.

Outputs: - logs ([]*ethgo.Log): The logs retrieved from the database for the given block number. - err (error): Any error that occurred during the transaction or unmarshaling process.

func (*BoltDBEventTrackerStore) InsertLastProcessedBlock

func (p *BoltDBEventTrackerStore) InsertLastProcessedBlock(lastProcessedBlockNumber uint64) error

InsertLastProcessedBlock inserts the last processed block number into a BoltDB bucket.

Inputs: - lastProcessedBlockNumber (uint64): The block number to be inserted into the bucket.

Outputs: - error: An error indicating if there was a problem with the transaction or the insertion.

func (*BoltDBEventTrackerStore) InsertLogs

func (p *BoltDBEventTrackerStore) InsertLogs(logs []*ethgo.Log) error

InsertLogs inserts logs into a BoltDB database, where logs are stored by a composite key: - {log.BlockNumber,log.LogIndex}

Example Usage:

store := &BoltDBEventTrackerStore{db: boltDB}
logs := []*ethgo.Log{log1, log2, log3}
err := store.InsertLogs(logs)
if err != nil {
  fmt.Println("Error inserting logs:", err)
}

Inputs:

  • logs: A slice of ethgo.Log structs representing the logs to be inserted into the database.

Outputs:

  • error: If an error occurs during the insertion process, it is returned. Otherwise, nil is returned.

type EventTrackerStore

type EventTrackerStore interface {
	GetLastProcessedBlock() (uint64, error)
	InsertLastProcessedBlock(blockNumber uint64) error
	InsertLogs(logs []*ethgo.Log) error
	GetLogsByBlockNumber(blockNumber uint64) ([]*ethgo.Log, error)
	GetLog(blockNumber, logIndex uint64) (*ethgo.Log, error)
	GetAllLogs() ([]*ethgo.Log, error)
}

EventTrackerStore is an interface that defines the behavior of an event tracker store

Jump to

Keyboard shortcuts

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