-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstart.ts
66 lines (53 loc) · 1.27 KB
/
start.ts
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import { ethers } from "ethers";
import {
attestedEventSignature,
getAndUpdateLatestAttestationRevocations,
getAndUpdateLatestAttestations,
provider,
revokedEventSignature,
updateDbFromRelevantLog,
updatePostMetaData,
} from "./utils";
import { startGraph } from "./graph";
import express from "express";
require("dotenv").config();
const app = express();
app.use("/url_previews/uploads", express.static("uploads/url_previews"));
app.get("/url_previews/updateMeta/:postId", async (req, res) => {
const postId = req.params.postId;
await updatePostMetaData(postId);
res.send("ok");
});
app.listen(6231, () => {
console.log("Listening on port 6231");
});
let running = false;
export async function update() {
if (running) {
return;
}
try {
running = true;
await getAndUpdateLatestAttestations();
await getAndUpdateLatestAttestationRevocations();
} catch (e) {
console.log("Error!", e);
}
running = false;
}
async function go() {
await update();
const filter = {
topics: [
[
ethers.utils.id(attestedEventSignature),
ethers.utils.id(revokedEventSignature),
],
],
};
provider.on(filter, async (log: ethers.providers.Log) => {
await updateDbFromRelevantLog(log);
});
}
go();
startGraph();