base

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2024 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package base contains the base sql implementation

Index

Constants

View Source
const EthTxColumns = "tx_hash,chain_id,block_hash,block_number,raw_tx,gas_fee_cap,gas_tip_cap,confirmed,transaction_index"

EthTxColumns are all of the columns of the EthTx table.

View Source
const LogColumns = "" /* 139-byte string literal not displayed */

LogColumns are all of the columns of the Log table.

View Source
const ReceiptColumns = "" /* 151-byte string literal not displayed */

ReceiptColumns are all of the columns of the Receipt table.

Variables

View Source
var (
	// TxHashFieldName is the field name of the tx hash.
	TxHashFieldName string
	// ChainIDFieldName gets the chain id field name.
	ChainIDFieldName string
	// BlockNumberFieldName is the name of the block number field.
	BlockNumberFieldName string
	// ContractAddressFieldName is the address of the contract.
	ContractAddressFieldName string
	// BlockIndexFieldName is the index field name.
	BlockIndexFieldName string
	// BlockHashFieldName is the block hash field name.
	BlockHashFieldName string
	// ConfirmedFieldName is the confirmed field name.
	ConfirmedFieldName string
	// TransactionIndexFieldName is the name of the transaction block  field.
	TransactionIndexFieldName string
)
View Source
var PageSize = 100

PageSize is the amount of entries per page of logs.

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 BlockTime added in v0.0.27

type BlockTime struct {
	// ChainID is the chain id of the contract
	ChainID uint32 `gorm:"column:chain_id;primaryKey;index:idx_block_time_chain,priority:1"`
	// BlockNumber is the block number
	BlockNumber uint64 `gorm:"column:block_number;primaryKey"`
	// Timestamp is the timestamp of the block
	Timestamp uint64 `gorm:"column:timestamp"`
}

BlockTime contains the timestamp of a block.

type EthTx

type EthTx struct {
	// TxHash is the hash of the transaction
	TxHash string `gorm:"column:tx_hash;primaryKey"`
	// ChainID is the chain id of the transaction
	ChainID uint32 `gorm:"column:chain_id;primaryKey"`
	// BlockHash is the hash of the block in which the transaction was included
	BlockHash string `gorm:"column:block_hash;index:idx_tx_block_hash,priority:1,sort:desc"`
	// BlockNumber is the block in which the transaction was included
	BlockNumber uint64 `gorm:"column:block_number;index:idx_block_number_tx,priority:1,sort:desc"`
	// RawTx is the raw serialized transaction
	RawTx []byte `gorm:"column:raw_tx"`
	// GasFeeCap contains the gas fee cap stored in wei
	GasFeeCap uint64
	// GasTipCap contains the gas tip cap stored in wei
	GasTipCap uint64
	// Confirmed is true if this log has been confirmed by the chain
	Confirmed bool `gorm:"column:confirmed"`
	// TransactionIndex is the index of the transaction in the block
	TransactionIndex uint64 `gorm:"column:transaction_index;index:idx_block_number_tx,priority:2,sort:desc"`
}

EthTx contains a processed ethereum transaction.

type EthTxAtHead added in v0.0.207

type EthTxAtHead struct {
	// TxHash is the hash of the transaction
	TxHash string `gorm:"column:tx_hash;primaryKey"`
	// ChainID is the chain id of the transaction
	ChainID uint32 `gorm:"column:chain_id;primaryKey"`
	// BlockHash is the hash of the block in which the transaction was included
	BlockHash string `gorm:"column:block_hash;index:idx_head_tx_block_hash,priority:1,sort:desc"`
	// BlockNumber is the block in which the transaction was included
	BlockNumber uint64 `gorm:"column:block_number;index:idx_head_block_number_tx,priority:1,sort:desc"`
	// RawTx is the raw serialized transaction
	RawTx []byte `gorm:"column:raw_tx"`
	// GasFeeCap contains the gas fee cap stored in wei
	GasFeeCap uint64
	// GasTipCap contains the gas tip cap stored in wei
	GasTipCap uint64
	// Confirmed is true if this log has been confirmed by the chain
	Confirmed bool `gorm:"column:confirmed"`
	// TransactionIndex is the index of the transaction in the block
	TransactionIndex uint64 `gorm:"column:transaction_index;index:idx_head_block_number_tx,priority:2,sort:desc"`
	// InsertTime is the time at which this tx was inserted
	InsertTime uint64 `gorm:"column:insert_time"`
}

EthTxAtHead contains a processed ethereum transaction at the tip of the chain.

type LastBlockTime added in v0.0.27

type LastBlockTime struct {
	gorm.Model
	// ChainID is the chain id of the contract
	ChainID uint32 `gorm:"column:chain_id;primaryKey"`
	// BlockNumber is the block number
	BlockNumber uint64 `gorm:"column:block_number"`
}

LastBlockTime contains the last block that had its timestamp stored.

type LastConfirmedBlockInfo added in v0.0.16

type LastConfirmedBlockInfo struct {
	gorm.Model
	// ChainID is the chain id of the contract
	ChainID uint32 `gorm:"column:chain_id"`
	// BlockNumber is the last block number indexed
	BlockNumber uint64 `gorm:"column:block_number"`
}

LastConfirmedBlockInfo contains information on when a chain last had a block pass the required confirmation threshold and was validated.

type LastIndexedInfo

type LastIndexedInfo struct {
	gorm.Model
	// ContractAddress is the contract address
	ContractAddress string `gorm:"column:contract_address;index:idx_last_indexed,priority:1;uniqueIndex:idx_contract_chain"`
	// BlockNumber is the last block number indexed
	BlockNumber uint64 `gorm:"column:block_number;index:idx_last_indexed,priority:2"`
	// ChainID is the chain id of the contract
	ChainID uint32 `gorm:"column:chain_id;index:idx_last_indexed;uniqueIndex:idx_contract_chain"`
}

LastIndexedInfo contains information on when a contract was last indexed.

type Log

type Log struct {
	// ContractAddress is the address of the contract that generated the event
	ContractAddress string `gorm:"column:contract_address;primaryKey;index:idx_address,priority:1,sort:desc"`
	// ChainID is the chain id of the contract that generated the event
	ChainID uint32 `gorm:"column:chain_id;primaryKey;index:idx_address,priority:2,sort:desc"`
	// PrimaryTopic is the primary topic of the event. Topics[0]
	PrimaryTopic sql.NullString `gorm:"primary_topic"`
	// TopicA is the first topic. Topics[1]
	TopicA sql.NullString `gorm:"topic_a"`
	// TopicB is the second topic. Topics[2]
	TopicB sql.NullString `gorm:"topic_b"`
	// TopicC is the third topic. Topics[3]
	TopicC sql.NullString `gorm:"topic_c"`
	// Data is the data provided by the contract
	Data []byte `gorm:"data"`
	// BlockNumber is the block in which the transaction was included
	BlockNumber uint64 `gorm:"column:block_number;index:idx_block_number,priority:1,sort:desc"`
	// TxHash is the hash of the transaction
	TxHash string `gorm:"column:tx_hash;primaryKey;index:idx_tx_hash,priority:1,sort:desc"`
	// TxIndex is the index of the transaction in the block
	TxIndex uint64 `gorm:"tx_index"`
	// BlockHash is the hash of the block in which the transaction was included
	BlockHash string `gorm:"column:block_hash;index:idx_block_hash,priority:1,sort:desc"`
	// Index is the index of the log in the block
	BlockIndex uint64 `gorm:"column:block_index;primaryKey;index:idx_block_number,priority:2,sort:desc"`
	// Removed is true if this log was reverted due to a chain re-organization
	Removed bool `gorm:"removed"`
	// Confirmed is true if this log has been confirmed by the chain
	Confirmed bool `gorm:"confirmed"`
}

Log stores the log of an event.

type LogAtHead added in v0.0.207

type LogAtHead struct {
	// ContractAddress is the address of the contract that generated the event
	ContractAddress string `gorm:"column:contract_address;primaryKey;index:idx_head_address,priority:1,sort:desc"`
	// ChainID is the chain id of the contract that generated the event
	ChainID uint32 `gorm:"column:chain_id;primaryKey;index:idx_head_address,priority:2,sort:desc"`
	// PrimaryTopic is the primary topic of the event. Topics[0]
	PrimaryTopic sql.NullString `gorm:"primary_topic"`
	// TopicA is the first topic. Topics[1]
	TopicA sql.NullString `gorm:"topic_a"`
	// TopicB is the second topic. Topics[2]
	TopicB sql.NullString `gorm:"topic_b"`
	// TopicC is the third topic. Topics[3]
	TopicC sql.NullString `gorm:"topic_c"`
	// Data is the data provided by the contract
	Data []byte `gorm:"data"`
	// BlockNumber is the block in which the transaction was included
	BlockNumber uint64 `gorm:"column:block_number;index:idx_head_block_number,priority:1,sort:desc"`
	// TxHash is the hash of the transaction
	TxHash string `gorm:"column:tx_hash;primaryKey;index:idx_head_tx_hash,priority:1,sort:desc"`
	// TxIndex is the index of the transaction in the block
	TxIndex uint64 `gorm:"tx_index"`
	// BlockHash is the hash of the block in which the transaction was included
	BlockHash string `gorm:"column:block_hash;index:idx_head_block_hash,priority:1,sort:desc"`
	// Index is the index of the log in the block
	BlockIndex uint64 `gorm:"column:block_index;primaryKey;index:idx_head_block_number,priority:2,sort:desc"`
	// Removed is true if this log was reverted due to a chain re-organization
	Removed bool `gorm:"removed"`
	// Confirmed is true if this log has been confirmed by the chain
	Confirmed bool `gorm:"confirmed"`
	// InsertTime is the time at which this log was inserted
	InsertTime uint64 `gorm:"column:insert_time"`
}

LogAtHead stores the log of an event that occurred near the tip of the chain.

type Receipt

type Receipt struct {
	// ChainID is the chain id of the receipt
	ChainID uint32 `gorm:"column:chain_id;primaryKey"`
	// Type is the type
	Type uint8 `gorm:"column:receipt_type"`
	// PostState is the post state
	PostState []byte `gorm:"column:post_state"`
	// Status is the status of the transaction
	Status uint64 `gorm:"column:status"`
	// CumulativeGasUsed is the total amount of gas used when this transaction was executed in the block
	CumulativeGasUsed uint64 `gorm:"column:cumulative_gas_used"`
	// Bloom is the bloom filter
	Bloom []byte `gorm:"column:bloom"`
	// TxHash is the hash of the transaction
	TxHash string `gorm:"column:tx_hash;primaryKey"`
	// ContractAddress is the address of the contract
	ContractAddress string `gorm:"column:contract_address"`
	// GasUsed is the amount of gas used by this transaction alone
	GasUsed uint64 `gorm:"column:gas_used"`
	// BlockHash is the hash of the block in which this transaction was included
	BlockHash string `gorm:"column:block_hash"`
	// BlockNumber is the block in which this transaction was included
	BlockNumber uint64 `gorm:"column:block_number;index:idx_block_number_receipt,priority:1,sort:desc"`
	// TransactionIndex is the index of the transaction in the block
	TransactionIndex uint64 `gorm:"column:transaction_index;index:idx_block_number_receipt,priority:2,sort:desc"`
	// Confirmed is true if this log has been confirmed by the chain
	Confirmed bool `gorm:"column:confirmed"`
}

Receipt stores the receipt of a transaction.

type ReceiptAtHead added in v0.0.207

type ReceiptAtHead struct {
	// ChainID is the chain id of the receipt
	ChainID uint32 `gorm:"column:chain_id;primaryKey"`
	// Type is the type
	Type uint8 `gorm:"column:receipt_type"`
	// PostState is the post state
	PostState []byte `gorm:"column:post_state"`
	// Status is the status of the transaction
	Status uint64 `gorm:"column:status"`
	// CumulativeGasUsed is the total amount of gas used when this transaction was executed in the block
	CumulativeGasUsed uint64 `gorm:"column:cumulative_gas_used"`
	// Bloom is the bloom filter
	Bloom []byte `gorm:"column:bloom"`
	// TxHash is the hash of the transaction
	TxHash string `gorm:"column:tx_hash;primaryKey"`
	// ContractAddress is the address of the contract
	ContractAddress string `gorm:"column:contract_address"`
	// GasUsed is the amount of gas used by this transaction alone
	GasUsed uint64 `gorm:"column:gas_used"`
	// BlockHash is the hash of the block in which this transaction was included
	BlockHash string `gorm:"column:block_hash"`
	// BlockNumber is the block in which this transaction was included
	BlockNumber uint64 `gorm:"column:block_number;index:idx_head_block_number_receipt,priority:1,sort:desc"`
	// TransactionIndex is the index of the transaction in the block
	TransactionIndex uint64 `gorm:"column:transaction_index;index:idx_head_block_number_receipt,priority:2,sort:desc"`
	// Confirmed is true if this log has been confirmed by the chain
	Confirmed bool `gorm:"column:confirmed"`
	// InsertTime is the time at which this receipt was inserted
	InsertTime uint64 `gorm:"column:insert_time"`
}

ReceiptAtHead stores the receipt of a transaction at the tip.

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 NewStore

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

NewStore creates a new store.

func (Store) ConfirmEthTxsForBlockHash added in v0.0.16

func (s Store) ConfirmEthTxsForBlockHash(ctx context.Context, blockHash common.Hash, chainID uint32) error

ConfirmEthTxsForBlockHash confirms eth txs for a given block hash.

func (Store) ConfirmLogsForBlockHash added in v0.0.16

func (s Store) ConfirmLogsForBlockHash(ctx context.Context, chainID uint32, blockHash common.Hash) error

ConfirmLogsForBlockHash confirms logs for a given block hash.

func (Store) ConfirmReceiptsForBlockHash added in v0.0.16

func (s Store) ConfirmReceiptsForBlockHash(ctx context.Context, chainID uint32, blockHash common.Hash) error

ConfirmReceiptsForBlockHash confirms receipts for a given block hash.

func (Store) DB

func (s Store) DB() *gorm.DB

DB gets the database.

func (Store) DeleteEthTxsForBlockHash added in v0.0.16

func (s Store) DeleteEthTxsForBlockHash(ctx context.Context, blockHash common.Hash, chainID uint32) error

DeleteEthTxsForBlockHash deletes eth txs with a given block hash.

func (Store) DeleteLogsForBlockHash added in v0.0.16

func (s Store) DeleteLogsForBlockHash(ctx context.Context, blockHash common.Hash, chainID uint32) error

DeleteLogsForBlockHash deletes logs with a given block hash.

func (Store) DeleteReceiptsForBlockHash added in v0.0.16

func (s Store) DeleteReceiptsForBlockHash(ctx context.Context, chainID uint32, blockHash common.Hash) error

DeleteReceiptsForBlockHash deletes receipts with a given block hash.

func (Store) FlushFromHeadTables added in v0.0.207

func (s Store) FlushFromHeadTables(ctx context.Context, time int64) error

FlushFromHeadTables deletes all logs, receipts, and txs from the head table that are older than the given time.

func (Store) RetrieveBlockTime added in v0.0.27

func (s Store) RetrieveBlockTime(ctx context.Context, chainID uint32, blockNumber uint64) (uint64, error)

RetrieveBlockTime retrieves a block time for a chain and block number.

func (Store) RetrieveBlockTimesCountForChain added in v0.0.42

func (s Store) RetrieveBlockTimesCountForChain(ctx context.Context, chainID uint32) (int64, error)

RetrieveBlockTimesCountForChain retrieves the number of block times stored for a chain.

func (Store) RetrieveEthTxsInRange added in v0.0.9

func (s Store) RetrieveEthTxsInRange(ctx context.Context, ethTxFilter db.EthTxFilter, startBlock, endBlock uint64, page int) ([]db.TxWithBlockNumber, error)

RetrieveEthTxsInRange retrieves eth transactions that match an inputted filter and are within a range given a page.

func (Store) RetrieveEthTxsWithFilter added in v0.0.9

func (s Store) RetrieveEthTxsWithFilter(ctx context.Context, ethTxFilter db.EthTxFilter, page int) ([]db.TxWithBlockNumber, error)

RetrieveEthTxsWithFilter retrieves eth transactions with a filter given a page.

func (Store) RetrieveFirstBlockStored added in v0.0.35

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

RetrieveFirstBlockStored retrieves the first block number that has a stored block time.

func (Store) RetrieveLastBlockStored added in v0.0.35

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

RetrieveLastBlockStored retrieves the last block number that has a stored block time.

func (Store) RetrieveLastConfirmedBlock added in v0.0.16

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

RetrieveLastConfirmedBlock retrieves the last block number that has been confirmed.

func (Store) RetrieveLastIndexed

func (s Store) RetrieveLastIndexed(ctx context.Context, contractAddress common.Address, chainID uint32, livefill bool) (uint64, error)

RetrieveLastIndexed retrieves the last indexed block number for a contract.

func (Store) RetrieveLastIndexedMultiple added in v0.0.207

func (s Store) RetrieveLastIndexedMultiple(ctx context.Context, contractAddresses []common.Address, chainID uint32) (map[common.Address]uint64, error)

RetrieveLastIndexedMultiple retrieves the last indexed block numbers for numerous contracts.

func (Store) RetrieveLogCountForContract added in v0.0.40

func (s Store) RetrieveLogCountForContract(ctx context.Context, contractAddress common.Address, chainID uint32) (int64, error)

RetrieveLogCountForContract retrieves the count of logs per contract.

func (Store) RetrieveLogsFromHeadRangeQuery added in v0.0.207

func (s Store) RetrieveLogsFromHeadRangeQuery(ctx context.Context, logFilter db.LogFilter, startBlock uint64, endBlock uint64, page int) ([]*types.Log, error)

RetrieveLogsFromHeadRangeQuery retrieves all logs (including unconfirmed) for a given contract address, chain ID, and range.

func (Store) RetrieveLogsInRange added in v0.0.9

func (s Store) RetrieveLogsInRange(ctx context.Context, logFilter db.LogFilter, startBlock, endBlock uint64, page int) (logs []*types.Log, err error)

RetrieveLogsInRange retrieves all logs that match an inputted filter and are within a range given a page.

func (Store) RetrieveLogsInRangeAsc added in v0.0.61

func (s Store) RetrieveLogsInRangeAsc(ctx context.Context, logFilter db.LogFilter, startBlock, endBlock uint64, page int) (logs []*types.Log, err error)

RetrieveLogsInRangeAsc retrieves all logs that match an inputted filter and are within a range given a page - in ascending order.

func (Store) RetrieveLogsWithFilter added in v0.0.9

func (s Store) RetrieveLogsWithFilter(ctx context.Context, logFilter db.LogFilter, page int) (logs []*types.Log, err error)

RetrieveLogsWithFilter retrieves all logs that match a filter given a page.

func (Store) RetrieveReceiptCountForChain added in v0.0.93

func (s Store) RetrieveReceiptCountForChain(ctx context.Context, chainID uint32) (int64, error)

RetrieveReceiptCountForChain retrieves the count of receipts per chain.

func (Store) RetrieveReceiptsFromHeadRangeQuery added in v0.0.207

func (s Store) RetrieveReceiptsFromHeadRangeQuery(ctx context.Context, receiptFilter db.ReceiptFilter, startBlock uint64, endBlock uint64, page int) ([]types.Receipt, error)

RetrieveReceiptsFromHeadRangeQuery retrieves all receipts (including unconfirmed) for a given contract address, chain ID, and range.

func (Store) RetrieveReceiptsInRange added in v0.0.9

func (s Store) RetrieveReceiptsInRange(ctx context.Context, receiptFilter db.ReceiptFilter, startBlock, endBlock uint64, page int) (receipts []types.Receipt, err error)

RetrieveReceiptsInRange retrieves receipts that match an inputted filter and are within a range given a page.

func (Store) RetrieveReceiptsWithFilter added in v0.0.9

func (s Store) RetrieveReceiptsWithFilter(ctx context.Context, receiptFilter db.ReceiptFilter, page int) (receipts []types.Receipt, err error)

RetrieveReceiptsWithFilter retrieves receipts with a filter given a page.

func (Store) RetrieveReceiptsWithStaleBlockHash added in v0.0.194

func (s Store) RetrieveReceiptsWithStaleBlockHash(ctx context.Context, chainID uint32, blockHashes []string, startBlock uint64, endBlock uint64) ([]types.Receipt, error)

RetrieveReceiptsWithStaleBlockHash gets receipts that are from a reorged/stale block.

func (Store) RetrieveUnconfirmedEthTxsFromHeadRangeQuery added in v0.0.207

func (s Store) RetrieveUnconfirmedEthTxsFromHeadRangeQuery(ctx context.Context, ethTxFilter db.EthTxFilter, startBlock uint64, endBlock uint64, lastIndexed uint64, page int) ([]db.TxWithBlockNumber, error)

RetrieveUnconfirmedEthTxsFromHeadRangeQuery retrieves all unconfirmed ethTx for a given chain ID and range. lastIndexed is passed because the ethtx table does not have contract addresses, thus the last indexed for that contract cannot be determined for the join. Pass last indexed for the log that you are trying to mature with data.

func (Store) StoreBlockTime added in v0.0.27

func (s Store) StoreBlockTime(ctx context.Context, chainID uint32, blockNumber, timestamp uint64) error

StoreBlockTime stores a block time for a chain.

func (Store) StoreEthTx

func (s Store) StoreEthTx(ctx context.Context, tx *types.Transaction, chainID uint32, blockHash common.Hash, blockNumber uint64, transactionIndex uint64) error

StoreEthTx stores a processed tx.

func (Store) StoreEthTxAtHead added in v0.0.207

func (s Store) StoreEthTxAtHead(ctx context.Context, tx *types.Transaction, chainID uint32, blockHash common.Hash, blockNumber uint64, transactionIndex uint64) error

StoreEthTxAtHead stores a processed text at Head.

func (Store) StoreLastConfirmedBlock added in v0.0.16

func (s Store) StoreLastConfirmedBlock(ctx context.Context, chainID uint32, blockNumber uint64) error

StoreLastConfirmedBlock stores the last block number that has been confirmed. It updates the value if there is a previous last block confirmed value, and creates a new entry if there is no previous value.

func (Store) StoreLastIndexed

func (s Store) StoreLastIndexed(parentCtx context.Context, contractAddress common.Address, chainID uint32, blockNumber uint64, livefillAtHead bool) (err error)

StoreLastIndexed stores the last indexed block number for a contract. It updates the value if there is a previous last indexed value, and creates a new entry if there's no previous value.

func (Store) StoreLastIndexedMultiple added in v0.0.207

func (s Store) StoreLastIndexedMultiple(parentCtx context.Context, contractAddresses []common.Address, chainID uint32, blockNumber uint64) error

StoreLastIndexedMultiple stores the last indexed block numbers for numerous contracts.

func (Store) StoreLogs added in v0.0.102

func (s Store) StoreLogs(ctx context.Context, chainID uint32, logs ...types.Log) error

StoreLogs stores a log.

func (Store) StoreLogsAtHead added in v0.0.207

func (s Store) StoreLogsAtHead(ctx context.Context, chainID uint32, logs ...types.Log) error

StoreLogsAtHead stores a log at the Head of the chain.

func (Store) StoreReceipt

func (s Store) StoreReceipt(ctx context.Context, chainID uint32, receipt types.Receipt) error

StoreReceipt stores a receipt.

func (Store) StoreReceiptAtHead added in v0.0.207

func (s Store) StoreReceiptAtHead(ctx context.Context, chainID uint32, receipt types.Receipt) error

StoreReceiptAtHead stores a receipt.

Jump to

Keyboard shortcuts

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