mirror of
https://github.com/zkitter/eth-json-rpc-filters.git
synced 2026-01-08 23:08:10 -05:00
`flatmap` is a great utility function, but, it didn't seem necessary here. The operation it was used for was trivial to implement using plain JavaScript. Removing this dependency leaves one less thing for us to update.
28 lines
696 B
JavaScript
28 lines
696 B
JavaScript
const BaseFilter = require('./base-filter')
|
|
const getBlocksForRange = require('./getBlocksForRange')
|
|
const { incrementHexInt } = require('./hexUtils')
|
|
|
|
class TxFilter extends BaseFilter {
|
|
|
|
constructor ({ provider }) {
|
|
super()
|
|
this.type = 'tx'
|
|
this.provider = provider
|
|
}
|
|
|
|
async update ({ oldBlock }) {
|
|
const toBlock = oldBlock
|
|
const fromBlock = incrementHexInt(oldBlock)
|
|
const blocks = await getBlocksForRange({ provider: this.provider, fromBlock, toBlock })
|
|
const blockTxHashes = []
|
|
for (const block of blocks) {
|
|
blockTxHashes.push(...block.transactions)
|
|
}
|
|
// add to results
|
|
this.addResults(blockTxHashes)
|
|
}
|
|
|
|
}
|
|
|
|
module.exports = TxFilter
|