From 6786ccf848bd116488b3261a3b4e0b43b9e42dc1 Mon Sep 17 00:00:00 2001 From: lza_menace Date: Sun, 25 Dec 2022 01:20:41 -0800 Subject: [PATCH] better chain sale logic to avoid missing notifs --- src/scraper.js | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/scraper.js b/src/scraper.js index 9122f76..223769b 100644 --- a/src/scraper.js +++ b/src/scraper.js @@ -295,17 +295,19 @@ class Scrape extends Collection { txDate: timestamp } writeToDatabase(q) - .then((res) => this.writeLastBlock(log.blockNumber)) + .then(async _ => { + let notifSent = await checkUnsentNotif(txHash, logIndex); + if (process.env.DISCORD_ACTIVE == 1 && (notifSent || process.env.FORCE == 1)) { + postDiscord(q) + .then(async res => { + await markSent(txHash, logIndex); + console.log(`[ ${timestamp.toISOString()} ][ ${this.contractName} ][ discord ] ${res}\n`) + }) + .catch((err) => console.log(`Error posting to Discord: ${err}`)); + } + this.writeLastBlock(log.blockNumber); + }) .catch((err) => console.log(`Error writing to database: ${err}`)); - let notifSent = await checkUnsentNotif(txHash, logIndex); - if (process.env.DISCORD_ACTIVE == 1 && (notifSent || process.env.FORCE == 1)) { - postDiscord(q) - .then(async res => { - await markSent(txHash, logIndex); - console.log(`[ ${timestamp.toISOString()} ][ ${this.contractName} ][ discord ] ${res}\n`) - }) - .catch((err) => console.log(`Error posting to Discord: ${err}`)); - } } }); } catch(err) {