-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathindex.ts
More file actions
44 lines (41 loc) · 1.46 KB
/
index.ts
File metadata and controls
44 lines (41 loc) · 1.46 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
38
39
40
41
42
43
44
import {
decodeDGApplicationData,
decodeDVMDApplicationData,
decodeDVMDExtendedApplicationData,
} from "@grants-stack-indexer/processors";
import { AnyIndexerFetchedEvent, ILogger } from "@grants-stack-indexer/shared";
/**
* Extracts unique metadata ids from the events batch.
* @param events - Array of indexer fetched events to process
* @returns Array of unique metadata ids found in the events
*/
export const getMetadataCidsFromEvents = (
events: AnyIndexerFetchedEvent[],
logger: ILogger,
): string[] => {
const ids = new Set<string>();
for (const event of events) {
if ("metadata" in event.params) {
ids.add(event.params.metadata[1]);
} else if ("data" in event.params) {
try {
const decoded = decodeDGApplicationData(event.params.data);
ids.add(decoded.metadata.pointer);
} catch (error) {}
try {
const decoded = decodeDVMDApplicationData(event.params.data);
ids.add(decoded.metadata.pointer);
} catch (error) {}
try {
const decoded = decodeDVMDExtendedApplicationData(event.params.data);
ids.add(decoded.metadata.pointer);
} catch (error) {
logger.warn("Failed to decode DVMD extended application data", {
error,
event,
});
}
}
}
return Array.from(ids);
};