mirror of
https://github.com/oceanprotocol-archive/squid-js.git
synced 2024-02-02 15:31:51 +01:00
hardened event listening
This commit is contained in:
parent
8ab5f7408b
commit
7b0d34a420
@ -1,6 +1,7 @@
|
|||||||
import GenericContract from "./contracts/GenericContract"
|
import GenericContract from "./contracts/GenericContract"
|
||||||
import EventListener from "./EventListener"
|
import EventListener from "./EventListener"
|
||||||
import Web3Provider from "./Web3Provider"
|
import Web3Provider from "./Web3Provider"
|
||||||
|
// import Logger from "../utils/Logger"
|
||||||
|
|
||||||
export default class Event {
|
export default class Event {
|
||||||
|
|
||||||
@ -39,15 +40,19 @@ export default class Event {
|
|||||||
private async handler(callback: any) {
|
private async handler(callback: any) {
|
||||||
const contract = await GenericContract.getInstance(this.contractName)
|
const contract = await GenericContract.getInstance(this.contractName)
|
||||||
|
|
||||||
const events = await contract.getEventData(this.eventName, {
|
try {
|
||||||
filter: this.filter,
|
const events = await contract.getEventData(this.eventName, {
|
||||||
fromBlock: this.lastBlock,
|
filter: this.filter,
|
||||||
toBlock: "latest",
|
fromBlock: this.lastBlock,
|
||||||
})
|
toBlock: "latest",
|
||||||
|
})
|
||||||
|
|
||||||
if (events.length > 0) {
|
if (events.length > 0) {
|
||||||
this.lastBlock = events[events.length - 1].blockNumber + 1
|
this.lastBlock = events[events.length - 1].blockNumber + 1
|
||||||
callback(events)
|
callback(events)
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
// Logger.log("err")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user