Documentation ¶
Overview ¶
Package db provides the database layer for the chain listener.
Index ¶
Constants ¶
This section is empty.
Variables ¶
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 upserts 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) // SetListenerName sets the listener name. SetListenerName(name string) }
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;index:idx_chain_name,unique"` // BlockHeight is the highest height we've seen on the chain BlockNumber int `gorm:"block_number"` // ListenerName is the name of the listener that is tracking this chain ListenerName string `gorm:"column:listener_name;index:idx_chain_name,unique"` }
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 ¶
NewChainListenerStore creates a new transaction store.
func (*Store) LatestBlockForChain ¶
LatestBlockForChain gets the latest block for a chain.
func (*Store) PutLatestBlock ¶
PutLatestBlock upserts the latest block into the database.
func (*Store) SetListenerName ¶ added in v1.3.0
SetListenerName sets the listener name.