-
Notifications
You must be signed in to change notification settings - Fork 0
/
have-there-been-updates.mjs
45 lines (39 loc) · 1.96 KB
/
have-there-been-updates.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/**
* (c) Su & William Entriken, released under MIT license
*
* Check if any updates occurred on-chain since loadedTo.json was saved.
*
* SYNOPSIS
* node have-there-been-updates.js
*
* EXIT STATUS
* 0 (success) if no new updates since loadedTo.json file updated
* 1 (success) if new updates since loadedTo.json file updated
*/
import fs from "fs";
import { ethers } from "ethers";
import { suSquares, underlay } from "./libs/contracts.mjs";
const config = JSON.parse(fs.readFileSync("./config.json"));
const loadedTo = JSON.parse(fs.readFileSync("./build/loadedTo.json"));
const provider = new ethers.JsonRpcProvider(config.provider);
// Load events /////////////////////////////////////////////////////////////////
const suSquaresConnected = suSquares.connect(provider);
const underlayConnected = underlay.connect(provider);
const filterSold = suSquaresConnected.filters.Transfer(suSquares.getAddress(), null, null);
const sold = suSquaresConnected.queryFilter(filterSold, loadedTo + 1);
const filterPersonalized = suSquaresConnected.filters.Personalized();
const personalized = suSquaresConnected.queryFilter(filterPersonalized, loadedTo + 1);
const filterUnderlay = underlayConnected.filters.PersonalizedUnderlay();
const personalizedUnderlay = underlayConnected.queryFilter(filterUnderlay, loadedTo + 1);
// Main program ////////////////////////////////////////////////////////////////
await Promise.all([sold, personalized, personalizedUnderlay]).then((values) => {
const [soldEvents, personalizedEvents, personalizedUnderlayEvents] = values;
console.log(`Since block ${loadedTo + 1}, there have been:`);
console.log(` ${soldEvents.length} sold`);
console.log(` ${personalizedEvents.length} personalized`);
console.log(` ${personalizedUnderlayEvents.length} personalized underlay`);
if (soldEvents.length + personalizedEvents.length + personalizedUnderlayEvents.length === 0) {
process.exit(0); // success
}
process.exit(1); // failure
});