-
Notifications
You must be signed in to change notification settings - Fork 55
Expand file tree
/
Copy pathindex.ts
More file actions
37 lines (26 loc) · 1.13 KB
/
index.ts
File metadata and controls
37 lines (26 loc) · 1.13 KB
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
import "dotenv/config";
import { uploadToIpfs } from "./utils/uploadToIpfs.ts";
import { fetchDisputeArchiveSnapshot } from "./utils/fetchDisputeArchiveSnapshot.ts";
import { fetchDisputeIds } from "./utils/fetchDisputeIds.ts";
import { isDisputeArchived, registerCid } from "./utils/contract.ts";
async function main() {
console.log("Fetching dispute IDs...");
const disputeIdsUnsorted = await fetchDisputeIds();
console.log(`Fetched ${disputeIdsUnsorted.length} ids`);
const disputeIds = disputeIdsUnsorted.sort((a, b) => Number(a) - Number(b));
// skip Ids already archived
for (const id of disputeIds) {
const isArchived = await isDisputeArchived(id);
if (isArchived) {
console.log(`Skipping dispute ${id}. Already archived.`);
continue;
}
console.log(`Archiving dispute ${id} ...`);
const snapshot = await fetchDisputeArchiveSnapshot(BigInt(id));
const cid = await uploadToIpfs(id, snapshot);
const courtID = snapshot.dispute.court.id;
const hash = await registerCid(id, courtID, cid);
console.log(`Dispute ${id} archived with cid: ${cid}. Transaction hash: ${hash}`);
}
}
main();