base

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2022 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package base contains the base sql implementation

Index

Constants

This section is empty.

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
)

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 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;auto_increment:false"`
	// 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
}

EthTx contains a processed ethereum transaction.

type LastIndexedInfo

type LastIndexedInfo struct {
	gorm.Model
	// ContractAddress is the contract address
	ContractAddress string `gorm:"column:contract_address"`
	// 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;auto_increment:false"`
}

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"`
	// ChainID is the chain id of the contract that generated the event
	ChainID uint32 `gorm:"chain_id"`
	// 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:"block_number"`
	// TxHash is the hash of the transaction
	TxHash string `gorm:"column:tx_hash;primaryKey"`
	// 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:"block_hash"`
	// Index is the index of the log in the block
	Index uint64 `gorm:"column:index;primaryKey;auto_increment:false"`
	// Removed is true if this log was reverted due to a chain re-organization
	Removed bool `gorm:"removed"`
}

Log stores the log of an event.

type Receipt

type Receipt struct {
	// ChainID is the chain id of the receipt
	ChainID uint32 `gorm:"column:chain_id;primaryKey;auto_increment:false"`
	// Type is the type
	Type uint8 `gorm:"receipt_type"`
	// PostState is the post state
	PostState []byte `gorm:"post_state"`
	// Status is the status of the transaction
	Status uint64 `gorm:"status"`
	// CumulativeGasUsed is the total amount of gas used when this transaction was executed in the block
	CumulativeGasUsed uint64 `gorm:"cumulative_gas_used"`
	// Bloom is the bloom filter
	Bloom []byte `gorm:"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:"contract_address"`
	// GasUsed is the amount of gas used by this transaction alone
	GasUsed uint64 `gorm:"gas_used"`
	// BlockHash is the hash of the block in which this transaction was included
	BlockHash string `gorm:"block_hash"`
	// BlockNumber is the block in which this transaction was included
	BlockNumber uint64 `gorm:"block_number"`
	// TransactionIndex is the index of the transaction in the block
	TransactionIndex uint64 `gorm:"transaction_index"`
}

Receipt stores the receipt of a transaction.

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) *Store

NewStore creates a new store.

func (Store) DB

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

DB gets the database.

func (Store) RetrieveAllLogs_Test

func (s Store) RetrieveAllLogs_Test(ctx context.Context) (logs []*types.Log, err error)

RetrieveAllLogs_Test retrieves all logs in the database. This is only used for testing.

func (Store) RetrieveAllReceipts_Test

func (s Store) RetrieveAllReceipts_Test(ctx context.Context) (receipts []types.Receipt, err error)

RetrieveAllReceipts_Test retrieves all receipts. Should only be used for testing.

func (Store) RetrieveLastIndexed

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

RetrieveLastIndexed retrieves the last indexed block number for a contract.

func (Store) RetrieveLogs

func (s Store) RetrieveLogs(ctx context.Context, txHash common.Hash, chainID uint32) (logs []*types.Log, err error)

RetrieveLogs retrieves all logs that match a tx hash and chain id.

func (Store) RetrieveReceipt

func (s Store) RetrieveReceipt(ctx context.Context, txHash common.Hash, chainID uint32) (receipt types.Receipt, err error)

RetrieveReceipt retrieves a receipt by tx hash and chain id.

func (Store) StoreEthTx

func (s Store) StoreEthTx(ctx context.Context, tx *types.Transaction, chainID uint32) error

StoreEthTx stores a processed text.

func (Store) StoreLastIndexed

func (s Store) StoreLastIndexed(ctx context.Context, contractAddress common.Address, chainID uint32, blockNumber uint64) 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 is no previous value.

func (Store) StoreLog

func (s Store) StoreLog(ctx context.Context, log types.Log, chainID uint32) error

StoreLog stores a log.

func (Store) StoreReceipt

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

StoreReceipt stores a receipt.

Jump to

Keyboard shortcuts

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