db

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2024 License: MIT Imports: 8 Imported by: 7

Documentation

Overview

Package db provides the database layer for the chain listener.

Index

Constants

This section is empty.

Variables

View Source
var ErrNoLatestBlockForChainID = errors.New("no latest block for chainId")

ErrNoLatestBlockForChainID is returned when no block exists for the chain.

Functions

func GetAllModels

func GetAllModels() (allModels []interface{})

GetAllModels gets all models to migrate see: https://medium.com/@SaifAbid/slice-interfaces-8c78f8b6345d for an explanation of why we can't do this at initialization time

Types

type ChainListenerDB

type ChainListenerDB interface {
	// PutLatestBlock upsers the latest block on a given chain id to be new height.
	PutLatestBlock(ctx context.Context, chainID, height uint64) error
	// LatestBlockForChain gets the latest block for a given chain id.
	// will return ErrNoLatestBlockForChainID if no block exists for the chain.
	LatestBlockForChain(ctx context.Context, chainID uint64) (uint64, error)
}

ChainListenerDB is the interface for the chain listener database.

type LastIndexed

type LastIndexed struct {
	// CreatedAt is the creation time
	CreatedAt time.Time
	// UpdatedAt is the update time
	UpdatedAt time.Time
	// DeletedAt time
	DeletedAt gorm.DeletedAt `gorm:"index"`
	// ChainID is the chain id of the chain we're watching blocks on. This is our primary index.
	ChainID uint64 `gorm:"column:chain_id;primaryKey;autoIncrement:false"`
	// BlockHeight is the highest height we've seen on the chain
	BlockNumber int `gorm:"block_number"`
}

LastIndexed is used to make sure we haven't missed any events while offline. since we event source - rather than use a state machine this is needed to make sure we haven't missed any events by allowing us to go back and source any events we may have missed.

this does not inherit from gorm.model to allow us to use ChainID as a primary key.

type Store

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

Store is the sqlite store. It extends the base store for sqlite specific queries.

func NewChainListenerStore

func NewChainListenerStore(db *gorm.DB, metrics metrics.Handler) *Store

NewChainListenerStore creates a new transaction store.

func (Store) LatestBlockForChain

func (s Store) LatestBlockForChain(ctx context.Context, chainID uint64) (uint64, error)

LatestBlockForChain gets the latest block for a chain.

func (Store) PutLatestBlock

func (s Store) PutLatestBlock(ctx context.Context, chainID, height uint64) error

PutLatestBlock upserts the latest block into the database.

Jump to

Keyboard shortcuts

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