-
Notifications
You must be signed in to change notification settings - Fork 0
/
key-value-pairs.ts
34 lines (31 loc) · 1.25 KB
/
key-value-pairs.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
import { log } from '@graphprotocol/graph-ts';
import { ValueUpdated as ValueUpdatedEvent } from '../generated/KeyValuePairs/KeyValuePairs';
import { loadOrCreateDAO } from './shared';
import { Bytes } from '@graphprotocol/graph-ts';
export function handleValueUpdated(event: ValueUpdatedEvent): void {
if (event.params.key == 'proposalTemplates') {
const dao = loadOrCreateDAO(event.params.theAddress);
dao.proposalTemplatesHash = event.params.value;
dao.save();
} else if (event.params.key == 'snapshotENS') {
const dao = loadOrCreateDAO(event.params.theAddress);
dao.snapshotENS = event.params.value;
dao.save();
} else if (event.params.key == 'daoName') {
const dao = loadOrCreateDAO(event.params.theAddress);
dao.name = event.params.value;
dao.save();
} else if (event.params.key == 'childDao') {
const subDAO = loadOrCreateDAO(Bytes.fromHexString(event.params.value));
if (subDAO.parentAddress !== null) {
return;
}
subDAO.parentAddress = event.params.theAddress;
subDAO.save();
const parentDAO = loadOrCreateDAO(event.params.theAddress);
parentDAO.hierarchy = parentDAO.hierarchy.concat([subDAO.id]);
parentDAO.save();
} else {
log.warning('Unknown key: {}', [event.params.key]);
}
}