allow scraping tx via env, skip notifs sent already

pull/2/head
lza_menace 2 years ago
parent 3aafd18791
commit 4cbe824b39

@ -178,7 +178,7 @@ class Scrape extends Collection {
// Handle Opensea/Seaport sales // Handle Opensea/Seaport sales
const logDescription = seaportInterface.parseLog(log) const logDescription = seaportInterface.parseLog(log)
const matchingOffers = logDescription.args.offer.filter( const matchingOffers = logDescription.args.offer.filter(
o => o.token.toLowerCase() == this.contractAddress o => o.token.toLowerCase() == this.contractAddress.toLowerCase()
); );
if (matchingOffers.length === 0) return; if (matchingOffers.length === 0) return;
sale = true; sale = true;
@ -217,7 +217,7 @@ class Scrape extends Collection {
} else if (log.topics[0].toLowerCase() === LOOKSRARE_SALE_TOPIC.toLowerCase()) { } else if (log.topics[0].toLowerCase() === LOOKSRARE_SALE_TOPIC.toLowerCase()) {
// Handle LooksRare sales // Handle LooksRare sales
const logDescription = looksrareInterface.parseLog(log); const logDescription = looksrareInterface.parseLog(log);
if (logDescription.args.collection.toLowerCase() != this.contractAddress) return; if (logDescription.args.collection.toLowerCase() != this.contractAddress.toLowerCase()) return;
sale = true; sale = true;
platform = 'looksrare'; platform = 'looksrare';
fromAddress = logDescription.args.maker.toLowerCase(); fromAddress = logDescription.args.maker.toLowerCase();
@ -258,11 +258,12 @@ class Scrape extends Collection {
writeToDatabase(q) writeToDatabase(q)
.then((res) => this.writeLastBlock(log.blockNumber)) .then((res) => this.writeLastBlock(log.blockNumber))
.catch((err) => console.log(`Error writing to database: ${err}`)); .catch((err) => console.log(`Error writing to database: ${err}`));
if (process.env.DISCORD_ACTIVE == 1 && checkUnsentNotif(txHash, logIndex)) { let notifSent = await checkUnsentNotif(txHash, logIndex);
if (process.env.DISCORD_ACTIVE == 1 && notifSent) {
postDiscord(q) postDiscord(q)
.then(async res => { .then(async res => {
await markSent(txHash, logIndex); await markSent(txHash, logIndex);
console.log(`[ ${timestamp.toISOString()} ][ ${this.contractName} ][ discord ] ${res}`) console.log(`[ ${timestamp.toISOString()} ][ ${this.contractName} ][ discord ] ${res}\n`)
}) })
.catch((err) => console.log(`Error posting to Discord: ${err}`)); .catch((err) => console.log(`Error posting to Discord: ${err}`));
} }
@ -428,6 +429,10 @@ if (process.env.SCRAPE) {
for(const key in ALL_CONTRACTS) { for(const key in ALL_CONTRACTS) {
if (process.env.ONLY && process.env.ONLY != key) continue if (process.env.ONLY && process.env.ONLY != key) continue
const c = new Scrape(key); const c = new Scrape(key);
if (process.env.TX) {
c.getSalesEvents(process.env.TX);
continue;
}
c.scrape(); c.scrape();
} }
} }

Loading…
Cancel
Save