Documentation ¶
Index ¶
- func Connect() *gorm.DB
- func DeleteBlock(dbWTx *gorm.DB, number uint64) error
- func DoesItMatch(event *data.Event, topics map[uint8]string) bool
- func EventTopicsAsString(topics map[uint8]string) string
- func ExtractOutOnlyMatchingEvents(events []*data.Event, topics map[uint8]string) *data.Events
- func GetAllBlockNumbersInRange(db *gorm.DB, from uint64, to uint64) []uint64
- func GetBlockByHash(db *gorm.DB, hash common.Hash) *data.Block
- func GetBlockByNumber(db *gorm.DB, number uint64) *data.Block
- func GetBlockCount(db *gorm.DB) uint64
- func GetBlocksByNumberRange(db *gorm.DB, from uint64, to uint64) *data.Blocks
- func GetBlocksByTimeRange(db *gorm.DB, from uint64, to uint64) *data.Blocks
- func GetContractCreationTransactionsFromAccountByBlockNumberRange(db *gorm.DB, account common.Address, from uint64, to uint64) *data.Transactions
- func GetContractCreationTransactionsFromAccountByBlockTimeRange(db *gorm.DB, account common.Address, from uint64, to uint64) *data.Transactions
- func GetCurrentBlockNumber(db *gorm.DB) uint64
- func GetCurrentOldestBlockNumber(db *gorm.DB) uint64
- func GetEventByBlockHashAndLogIndex(db *gorm.DB, hash common.Hash, index uint) *data.Event
- func GetEventByBlockNumberAndLogIndex(db *gorm.DB, number uint64, index uint) *data.Event
- func GetEventsByBlockHash(db *gorm.DB, blockHash common.Hash) *data.Events
- func GetEventsByTransactionHash(db *gorm.DB, txHash common.Hash) *data.Events
- func GetEventsFromContractByBlockNumberRange(db *gorm.DB, contract common.Address, from uint64, to uint64) *data.Events
- func GetEventsFromContractByBlockTimeRange(db *gorm.DB, contract common.Address, from uint64, to uint64) *data.Events
- func GetEventsFromContractWithTopicsByBlockNumberRange(db *gorm.DB, contract common.Address, from uint64, to uint64, ...) *data.Events
- func GetEventsFromContractWithTopicsByBlockTimeRange(db *gorm.DB, contract common.Address, from uint64, to uint64, ...) *data.Events
- func GetLastXEventsFromContract(db *gorm.DB, contract common.Address, x int) *data.Events
- func GetTransactionByHash(db *gorm.DB, hash common.Hash) *data.Transaction
- func GetTransactionCountBetweenAccountsByBlockNumberRange(db *gorm.DB, fromAccount common.Address, toAccount common.Address, from uint64, ...) int64
- func GetTransactionCountBetweenAccountsByBlockTimeRange(db *gorm.DB, fromAccount common.Address, toAccount common.Address, from uint64, ...) int64
- func GetTransactionCountByBlockHash(db *gorm.DB, hash common.Hash) int64
- func GetTransactionCountByBlockNumber(db *gorm.DB, number uint64) int64
- func GetTransactionCountFromAccountByBlockNumberRange(db *gorm.DB, account common.Address, from uint64, to uint64) int64
- func GetTransactionCountFromAccountByBlockTimeRange(db *gorm.DB, account common.Address, from uint64, to uint64) int64
- func GetTransactionCountToAccountByBlockNumberRange(db *gorm.DB, account common.Address, from uint64, to uint64) int64
- func GetTransactionCountToAccountByBlockTimeRange(db *gorm.DB, account common.Address, from uint64, to uint64) int64
- func GetTransactionFromAccountWithNonce(db *gorm.DB, account common.Address, nonce uint64) *data.Transaction
- func GetTransactionsBetweenAccountsByBlockNumberRange(db *gorm.DB, fromAccount common.Address, toAccount common.Address, from uint64, ...) *data.Transactions
- func GetTransactionsBetweenAccountsByBlockTimeRange(db *gorm.DB, fromAccount common.Address, toAccount common.Address, from uint64, ...) *data.Transactions
- func GetTransactionsByBlockHash(db *gorm.DB, hash common.Hash) *data.Transactions
- func GetTransactionsByBlockNumber(db *gorm.DB, number uint64) *data.Transactions
- func GetTransactionsFromAccountByBlockNumberRange(db *gorm.DB, account common.Address, from uint64, to uint64) *data.Transactions
- func GetTransactionsFromAccountByBlockTimeRange(db *gorm.DB, account common.Address, from uint64, to uint64) *data.Transactions
- func GetTransactionsToAccountByBlockNumberRange(db *gorm.DB, account common.Address, from uint64, to uint64) *data.Transactions
- func GetTransactionsToAccountByBlockTimeRange(db *gorm.DB, account common.Address, from uint64, to uint64) *data.Transactions
- func PutBlock(dbWTx *gorm.DB, block *Blocks) error
- func RemoveEventsByBlockHash(dbWTx *gorm.DB, blockHash string) error
- func RemoveTransactionsByBlockHash(dbWTx *gorm.DB, blockHash string) error
- func StoreBlock(dbWOTx *gorm.DB, block *PackedBlock, status *d.StatusHolder, ...) error
- func UpdateBlock(dbWTx *gorm.DB, block *Blocks) error
- func UpsertEvent(dbWTx *gorm.DB, event *Events) error
- func UpsertTransaction(dbWTx *gorm.DB, tx *Transactions) error
- type Blocks
- type Events
- type PackedBlock
- type PackedTransaction
- type Tabler
- type Transactions
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DeleteBlock ¶
DeleteBlock - Delete block entry, identified by block number, while cascading all dependent entries ( i.e. in transactions/ events table )
func DoesItMatch ¶
DoesItMatch - Given one event emitted by some contract & topic signature against which we're attempting to match the event it'll return boolean depending upon whether it's satisfying all conditions or not
func EventTopicsAsString ¶
EventTopicsAsString - Given event topic signatures as map, returns these topics as string, seperated by `,` i.e. comma to be used for forming DB raw query
func ExtractOutOnlyMatchingEvents ¶
ExtractOutOnlyMatchingEvents - Extract out only those events which are having full match with specified event topic signatures
func GetAllBlockNumbersInRange ¶
GetAllBlockNumbersInRange - Returns all block numbers in given range, both inclusive
func GetBlockByHash ¶
GetBlockByHash - Given blockhash finds out block related information
If not found, returns nil
func GetBlockCount ¶
GetBlockCount - Returns how many blocks currently present in database
Caution : As we're dealing with very large tables ( with row count ~ 10M & increasing 1 row every 2 seconds ) this function needs to be least frequently, otherwise due to full table scan it'll cost us a lot
Currently only using during application start up ¶
All other block count calculation requirements can be fulfilled by using in-memory program state holder
func GetBlocksByNumberRange ¶
GetBlocksByNumberRange - Given block numbers as range, it'll extract out those blocks by number, while returning them in ascendically sorted form in terms of block numbers
Note : Can return at max 10 blocks in a single query
If more blocks are requested, simply to be rejected In that case, consider splitting them such that they satisfy criteria
func GetBlocksByTimeRange ¶
GetBlocksByTimeRange - Given time range ( of 60 sec span at max ), returns blocks mined in that time span
If asked to find out blocks in time span larger than 60 sec, simply drops query request
func GetContractCreationTransactionsFromAccountByBlockNumberRange ¶
func GetContractCreationTransactionsFromAccountByBlockNumberRange(db *gorm.DB, account common.Address, from uint64, to uint64) *data.Transactions
GetContractCreationTransactionsFromAccountByBlockNumberRange - Fetch all contract creation tx(s) from given account with in specific block number range
func GetContractCreationTransactionsFromAccountByBlockTimeRange ¶
func GetContractCreationTransactionsFromAccountByBlockTimeRange(db *gorm.DB, account common.Address, from uint64, to uint64) *data.Transactions
GetContractCreationTransactionsFromAccountByBlockTimeRange - Fetch all contract creation tx(s) from given account with in specific block time span range
func GetCurrentBlockNumber ¶
GetCurrentBlockNumber - Returns highest block number, which got processed by the service
func GetCurrentOldestBlockNumber ¶
GetCurrentOldestBlockNumber - Fetches what's lowest block number present in database, which denotes if it's not 0, from here we can start syncing again, until we reach 0
func GetEventByBlockHashAndLogIndex ¶
GetEventByBlockHashAndLogIndex - Given block hash and log index in block return respective event log, if any exists
func GetEventByBlockNumberAndLogIndex ¶
GetEventByBlockNumberAndLogIndex - Given block number and log index in block return respective event log, if any exists
func GetEventsByBlockHash ¶
GetEventsByBlockHash - Given block hash retrieves all events from all tx present in that block
func GetEventsByTransactionHash ¶
GetEventsByTransactionHash - Given tx hash, returns all events emitted during contract interaction ( i.e. tx execution )
func GetEventsFromContractByBlockNumberRange ¶
func GetEventsFromContractByBlockNumberRange(db *gorm.DB, contract common.Address, from uint64, to uint64) *data.Events
GetEventsFromContractByBlockNumberRange - Given block number range & contract address, extracts out all events emitted by this contract during block span
func GetEventsFromContractByBlockTimeRange ¶
func GetEventsFromContractByBlockTimeRange(db *gorm.DB, contract common.Address, from uint64, to uint64) *data.Events
GetEventsFromContractByBlockTimeRange - Given block time range & contract address, extracts out all events emitted by this contract during time span
func GetEventsFromContractWithTopicsByBlockNumberRange ¶
func GetEventsFromContractWithTopicsByBlockNumberRange(db *gorm.DB, contract common.Address, from uint64, to uint64, topics map[uint8]string) *data.Events
GetEventsFromContractWithTopicsByBlockNumberRange - Given block number range, contract address & topics of event log, extracts out all events emitted by this contract during block span with topic signatures matching
func GetEventsFromContractWithTopicsByBlockTimeRange ¶
func GetEventsFromContractWithTopicsByBlockTimeRange(db *gorm.DB, contract common.Address, from uint64, to uint64, topics map[uint8]string) *data.Events
GetEventsFromContractWithTopicsByBlockTimeRange - Given time range, contract address & topics of event log, extracts out all events emitted by this contract during block span with topic signatures matching
func GetLastXEventsFromContract ¶
GetLastXEventsFromContract - Finds out last `x` events emitted by contract
func GetTransactionByHash ¶
GetTransactionByHash - Given tx hash, extracts out transaction related data
func GetTransactionCountBetweenAccountsByBlockNumberRange ¶
func GetTransactionCountBetweenAccountsByBlockNumberRange(db *gorm.DB, fromAccount common.Address, toAccount common.Address, from uint64, to uint64) int64
GetTransactionCountBetweenAccountsByBlockNumberRange - Given from & to account addresses & block number range, returns #-of transactions where `from` & `to` fields are matching
func GetTransactionCountBetweenAccountsByBlockTimeRange ¶
func GetTransactionCountBetweenAccountsByBlockTimeRange(db *gorm.DB, fromAccount common.Address, toAccount common.Address, from uint64, to uint64) int64
GetTransactionCountBetweenAccountsByBlockTimeRange - Given from & to account addresses & block mining time range, returns #-of transactions where `from` & `to` fields are matching
func GetTransactionCountByBlockHash ¶
GetTransactionCountByBlockHash - Given block hash, finds out how many transactions are packed in that block
func GetTransactionCountByBlockNumber ¶
GetTransactionCountByBlockNumber - Given block number, finds out how many transactions are packed in that block
func GetTransactionCountFromAccountByBlockNumberRange ¶
func GetTransactionCountFromAccountByBlockNumberRange(db *gorm.DB, account common.Address, from uint64, to uint64) int64
GetTransactionCountFromAccountByBlockNumberRange - Given account address & block number range, it can find out how many tx(s) were sent from this account in specified block range
func GetTransactionCountFromAccountByBlockTimeRange ¶
func GetTransactionCountFromAccountByBlockTimeRange(db *gorm.DB, account common.Address, from uint64, to uint64) int64
GetTransactionCountFromAccountByBlockTimeRange - Given account address & block mining time stamp range, it can find out count of all tx(s) performed by this address, with in that time span
func GetTransactionCountToAccountByBlockNumberRange ¶
func GetTransactionCountToAccountByBlockNumberRange(db *gorm.DB, account common.Address, from uint64, to uint64) int64
GetTransactionCountToAccountByBlockNumberRange - Given account address & block number range, returns #-of transactions where `account` was in `to` field
func GetTransactionCountToAccountByBlockTimeRange ¶
func GetTransactionCountToAccountByBlockTimeRange(db *gorm.DB, account common.Address, from uint64, to uint64) int64
GetTransactionCountToAccountByBlockTimeRange - Given account address which is present in `to` field of tx(s) held in blocks mined with in given time range, returns those tx count
func GetTransactionFromAccountWithNonce ¶
func GetTransactionFromAccountWithNonce(db *gorm.DB, account common.Address, nonce uint64) *data.Transaction
GetTransactionFromAccountWithNonce - Given tx sender address & account nonce, finds out tx, satisfying condition
func GetTransactionsBetweenAccountsByBlockNumberRange ¶
func GetTransactionsBetweenAccountsByBlockNumberRange(db *gorm.DB, fromAccount common.Address, toAccount common.Address, from uint64, to uint64) *data.Transactions
GetTransactionsBetweenAccountsByBlockNumberRange - Given from & to account addresses & block number range, returns transactions where `from` & `to` fields are matching
func GetTransactionsBetweenAccountsByBlockTimeRange ¶
func GetTransactionsBetweenAccountsByBlockTimeRange(db *gorm.DB, fromAccount common.Address, toAccount common.Address, from uint64, to uint64) *data.Transactions
GetTransactionsBetweenAccountsByBlockTimeRange - Given from & to account addresses & block mining time range, returns transactions where `from` & `to` fields are matching
func GetTransactionsByBlockHash ¶
GetTransactionsByBlockHash - Given block hash, returns all transactions present in that block
func GetTransactionsByBlockNumber ¶
func GetTransactionsByBlockNumber(db *gorm.DB, number uint64) *data.Transactions
GetTransactionsByBlockNumber - Given block number, returns all transactions present in that block
func GetTransactionsFromAccountByBlockNumberRange ¶
func GetTransactionsFromAccountByBlockNumberRange(db *gorm.DB, account common.Address, from uint64, to uint64) *data.Transactions
GetTransactionsFromAccountByBlockNumberRange - Given account address & block number range, it can find out all transactions which are performed from this account
func GetTransactionsFromAccountByBlockTimeRange ¶
func GetTransactionsFromAccountByBlockTimeRange(db *gorm.DB, account common.Address, from uint64, to uint64) *data.Transactions
GetTransactionsFromAccountByBlockTimeRange - Given account address & block mining time stamp range, it can find out all tx(s) performed from this account, with in that time span
func GetTransactionsToAccountByBlockNumberRange ¶
func GetTransactionsToAccountByBlockNumberRange(db *gorm.DB, account common.Address, from uint64, to uint64) *data.Transactions
GetTransactionsToAccountByBlockNumberRange - Given account address & block number range, returns transactions where `account` was in `to` field
func GetTransactionsToAccountByBlockTimeRange ¶
func GetTransactionsToAccountByBlockTimeRange(db *gorm.DB, account common.Address, from uint64, to uint64) *data.Transactions
GetTransactionsToAccountByBlockTimeRange - Given account address which is present in `to` field of tx(s) held in blocks mined with in given time range
func RemoveEventsByBlockHash ¶
RemoveEventsByBlockHash - All events emitted by tx(s) packed in block, to be removed from DB
func RemoveTransactionsByBlockHash ¶
RemoveTransactionsByBlockHash - Remove all tx(s) packed in this block from DB
func StoreBlock ¶
func StoreBlock(dbWOTx *gorm.DB, block *PackedBlock, status *d.StatusHolder, queue *q.BlockProcessorQueue) error
StoreBlock - Persisting block data in database, if data already not stored
Also checks equality with existing data, if mismatch found, updated with latest data
Tries to wrap db modifications inside database transaction to guarantee consistency, other read only operations being performed without protection of db transaction
👆 gives us performance improvement, also taste of atomic db operation i.e. either whole block data is written or nothing is written
func UpdateBlock ¶
UpdateBlock - Updating already existing block
func UpsertEvent ¶
UpsertEvent - It may be the case previously this block was processed and event log also got persisted into database, which has been updated on chain, due to chain reorganization
Now we want to persist latest entry into database, using upsert operation i.e. if entry doesn't exist yet, it'll be created, but if it does i.e. conflicting primary key found, then, all fields will be updated to latest value
func UpsertTransaction ¶
func UpsertTransaction(dbWTx *gorm.DB, tx *Transactions) error
UpsertTransaction - It may be the case previously this block was processed and transaction also got persisted into database, which has been updated on chain, due to chain reorganization
Now we want to persist latest entry into database, using upsert operation i.e. if entry doesn't exist yet, it'll be created, but if it does i.e. conflicting primary key found, then, all fields will be updated to latest value
Types ¶
type Blocks ¶
type Blocks struct { Hash string `gorm:"column:hash;type:char(66);primaryKey"` Number uint64 `gorm:"column:number;type:bigint;not null;unique;index:,sort:asc"` Time uint64 `gorm:"column:time;type:bigint;not null;index:,sort:asc"` ParentHash string `gorm:"column:parenthash;type:char(66);not null"` Difficulty string `gorm:"column:difficulty;type:varchar;not null"` GasUsed uint64 `gorm:"column:gasused;type:bigint;not null"` GasLimit uint64 `gorm:"column:gaslimit;type:bigint;not null"` Nonce string `gorm:"column:nonce;type:varchar;not null"` Miner string `gorm:"column:miner;type:char(42);not null"` Size float64 `gorm:"column:size;type:float(8);not null"` StateRootHash string `gorm:"column:stateroothash;type:char(66);not null"` UncleHash string `gorm:"column:unclehash;type:char(66);not null"` TransactionRootHash string `gorm:"column:txroothash;type:char(66);not null"` ReceiptRootHash string `gorm:"column:receiptroothash;type:char(66);not null"` ExtraData []byte `gorm:"column:extradata;type:bytea"` Transactions Transactions `gorm:"foreignKey:blockhash;constraint:OnDelete:CASCADE;"` Events Events `gorm:"foreignKey:blockhash;constraint:OnDelete:CASCADE;"` }
Blocks - Mined block info holder table model
type Events ¶
type Events struct { BlockHash string `gorm:"column:blockhash;type:char(66);not null;primaryKey"` Index uint `gorm:"column:index;type:integer;not null;primaryKey"` Origin string `gorm:"column:origin;type:char(42);not null;index"` Topics pq.StringArray `gorm:"column:topics;type:text[];not null;index:,type:gin"` Data []byte `gorm:"column:data;type:bytea"` TransactionHash string `gorm:"column:txhash;type:char(66);not null;index"` }
Events - Events emitted from smart contracts to be held in this table
type PackedBlock ¶
type PackedBlock struct { Block *Blocks Transactions []*PackedTransaction }
PackedBlock - Whole block data to be persisted in a single database transaction to ensure data consistency, if something goes wrong in mid, whole persisting operation will get reverted
type PackedTransaction ¶
type PackedTransaction struct { Tx *Transactions Events []*Events }
PackedTransaction - All data that is stored in a tx, to be passed from tx data fetcher to whole block data persist handler function
type Transactions ¶
type Transactions struct { Hash string `gorm:"column:hash;type:char(66);primaryKey"` From string `gorm:"column:from;type:char(42);not null;index"` To string `gorm:"column:to;type:char(42);index"` Contract string `gorm:"column:contract;type:char(42);index"` Value string `gorm:"column:value;type:varchar"` Data []byte `gorm:"column:data;type:bytea"` Gas uint64 `gorm:"column:gas;type:bigint;not null"` GasPrice string `gorm:"column:gasprice;type:varchar;not null"` Cost string `gorm:"column:cost;type:varchar;not null"` Nonce uint64 `gorm:"column:nonce;type:bigint;not null;index"` State uint64 `gorm:"column:state;type:smallint;not null"` BlockHash string `gorm:"column:blockhash;type:char(66);not null;index"` Events Events `gorm:"foreignKey:txhash;constraint:OnDelete:CASCADE;"` }
Transactions - Blockchain transaction holder table model
func (Transactions) TableName ¶
func (Transactions) TableName() string
TableName - Overriding default table name