Files
eth-json-rpc-filters/tx-filter.js
Mark Stacey 45e4300d39 Replace lodash.flatmap (#36)
`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.
2021-02-04 21:44:51 -03:30

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