Skip to content

Commit e0a137d

Browse files
authored
Merge pull request #568 from ethpandaops/bbusa/filter-blocks
feat: add block filter view
2 parents a6a266e + a601a73 commit e0a137d

11 files changed

Lines changed: 1130 additions & 9 deletions

File tree

cmd/dora-explorer/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ func startFrontend(router *mux.Router) {
199199
router.HandleFunc("/slot/{slotOrHash}/tracoor", handlers.SlotTracoor).Methods("GET")
200200
router.HandleFunc("/slot/{root}/blob/{index}", handlers.SlotBlob).Methods("GET")
201201
router.HandleFunc("/blocks", handlers.Blocks).Methods("GET")
202+
router.HandleFunc("/blocks/filtered", handlers.BlocksFiltered).Methods("GET")
202203
router.HandleFunc("/block/{numberOrHash}", handlers.Block).Methods("GET")
203204
router.HandleFunc("/blobs", handlers.Blobs).Methods("GET")
204205
router.HandleFunc("/address/{address}", handlers.Address).Methods("GET")

db/slots.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,46 @@ func GetFilteredSlots(filter *dbtypes.BlockFilter, firstSlot uint64, offset uint
476476
fmt.Fprintf(&sql, ` AND slots.eth_block_hash = $%v `, argIdx)
477477
args = append(args, filter.EthBlockHash)
478478
}
479+
if filter.MinGasUsed != nil {
480+
argIdx++
481+
fmt.Fprintf(&sql, ` AND slots.eth_gas_used >= $%v `, argIdx)
482+
args = append(args, *filter.MinGasUsed)
483+
}
484+
if filter.MaxGasUsed != nil {
485+
argIdx++
486+
fmt.Fprintf(&sql, ` AND slots.eth_gas_used <= $%v `, argIdx)
487+
args = append(args, *filter.MaxGasUsed)
488+
}
489+
if filter.MinGasLimit != nil {
490+
argIdx++
491+
fmt.Fprintf(&sql, ` AND slots.eth_gas_limit >= $%v `, argIdx)
492+
args = append(args, *filter.MinGasLimit)
493+
}
494+
if filter.MaxGasLimit != nil {
495+
argIdx++
496+
fmt.Fprintf(&sql, ` AND slots.eth_gas_limit <= $%v `, argIdx)
497+
args = append(args, *filter.MaxGasLimit)
498+
}
499+
if filter.MinBlockSize != nil {
500+
argIdx++
501+
fmt.Fprintf(&sql, ` AND slots.block_size >= $%v `, argIdx)
502+
args = append(args, *filter.MinBlockSize)
503+
}
504+
if filter.MaxBlockSize != nil {
505+
argIdx++
506+
fmt.Fprintf(&sql, ` AND slots.block_size <= $%v `, argIdx)
507+
args = append(args, *filter.MaxBlockSize)
508+
}
509+
if filter.MinSlot != nil {
510+
argIdx++
511+
fmt.Fprintf(&sql, ` AND slots.slot >= $%v `, argIdx)
512+
args = append(args, *filter.MinSlot)
513+
}
514+
if filter.MaxSlot != nil {
515+
argIdx++
516+
fmt.Fprintf(&sql, ` AND slots.slot <= $%v `, argIdx)
517+
args = append(args, *filter.MaxSlot)
518+
}
479519

480520
fmt.Fprintf(&sql, ` ORDER BY slots.slot DESC `)
481521
fmt.Fprintf(&sql, ` LIMIT $%v OFFSET $%v `, argIdx+1, argIdx+2)

dbtypes/other.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,17 @@ type BlockFilter struct {
6767
ForkIds []uint64 // Filter by fork IDs
6868
EthBlockNumber *uint64 // Filter by EL block number
6969
EthBlockHash []byte // Filter by EL block hash
70+
MinGasUsed *uint64 // Filter by minimum gas used
71+
MaxGasUsed *uint64 // Filter by maximum gas used
72+
MinGasLimit *uint64 // Filter by minimum gas limit
73+
MaxGasLimit *uint64 // Filter by maximum gas limit
74+
MinBlockSize *uint64 // Filter by minimum block size (bytes)
75+
MaxBlockSize *uint64 // Filter by maximum block size (bytes)
76+
WithMevBlock uint8 // 0=hide mev, 1=show all, 2=mev only
77+
MinEpoch *uint64 // Filter by minimum epoch
78+
MaxEpoch *uint64 // Filter by maximum epoch
79+
MinSlot *uint64 // Filter by minimum slot (derived from MinEpoch)
80+
MaxSlot *uint64 // Filter by maximum slot (derived from MaxEpoch)
7081
}
7182

7283
type MevBlockFilter struct {

0 commit comments

Comments
 (0)