Skip to content

Commit 93c8141

Browse files
authored
Merge pull request #27 from kleros/chore/migrate-to-file-data-source
chore: migrate-to-file-data-source
2 parents 6494aa9 + b61d70b commit 93c8141

File tree

10 files changed

+475
-385
lines changed

10 files changed

+475
-385
lines changed

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@
3636
"@assemblyscript/loader": "^0.14.11",
3737
"@assemblyscript/node": "github:AssemblyScript/node",
3838
"@gnosis.pm/truffle-nice-tools": "^1.3.1",
39-
"@graphprotocol/graph-cli": "^0.54.0",
40-
"@graphprotocol/graph-ts": "^0.31.0",
39+
"@graphprotocol/graph-cli": "^0.71.0",
40+
"@graphprotocol/graph-ts": "^0.35.1",
4141
"@kleros/erc-792": "3.0.0",
4242
"@kleros/gtcr-encoder": "^1.1.3",
4343
"@kleros/tcr": "^2.0.0",
@@ -62,7 +62,7 @@
6262
"wait-on": "^5.2.0"
6363
},
6464
"volta": {
65-
"node": "16.20.0",
65+
"node": "20.11.0",
6666
"yarn": "1.22.19"
6767
}
6868
}

schema.graphql

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ type Evidence @entity {
5454
timestamp: BigInt!
5555
"Tx hash of the evidence submission"
5656
txHash: Bytes!
57+
metadata: EvidenceMetadata
58+
}
59+
60+
type EvidenceMetadata @entity {
61+
id: ID!
5762
"Name of the evidence"
5863
name: String
5964
"Title of the evidence"
@@ -127,20 +132,6 @@ type LItem @entity {
127132
itemID: Bytes!
128133
"The data describing the item."
129134
data: String!
130-
"The parsed data describing the item."
131-
props: [ItemProp!]! @derivedFrom(field: "item")
132-
"First indexable value of the json file."
133-
key0: String
134-
"Second indexable value of the json file."
135-
key1: String
136-
"Third indexable value of the json file."
137-
key2: String
138-
"Fourth indexable value of the json file."
139-
key3: String
140-
"Fifth indexable value of the json file."
141-
key4: String
142-
"The item identifiers combined as a single string."
143-
keywords: String
144135
"The current status of the item."
145136
status: Status!
146137
"List of status change requests made for the item in the form requests[requestID]."
@@ -161,14 +152,36 @@ type LItem @entity {
161152
latestRequester: Bytes!
162153
"The account that challenged the latest request, if any."
163154
latestChallenger: Bytes!
155+
metadata: LItemMetadata
164156
}
165157

158+
type LItemMetadata @entity {
159+
"ipfs cid"
160+
id: ID!
161+
"The parsed data describing the item."
162+
props: [ItemProp!]! @derivedFrom(field: "item")
163+
"First indexable value of the json file."
164+
key0: String
165+
"Second indexable value of the json file."
166+
key1: String
167+
"Third indexable value of the json file."
168+
key2: String
169+
"Fourth indexable value of the json file."
170+
key3: String
171+
"Fifth indexable value of the json file."
172+
key4: String
173+
"The item identifiers combined as a single string."
174+
keywords: String
175+
"The item this metadata belongs to"
176+
item: LItem! @derivedFrom(field: "metadata")
177+
178+
}
166179
type _Schema_
167180
@fulltext(
168181
name: "itemSearch"
169182
language: en
170183
algorithm: rank
171-
include: [{ entity: "LItem", fields: [{ name: "keywords" }] }]
184+
include: [{ entity: "LItemMetadata", fields: [{ name: "keywords" }] }]
172185
)
173186

174187
type ItemProp @entity {
@@ -178,7 +191,7 @@ type ItemProp @entity {
178191
description: String!
179192
isIdentifier: Boolean!
180193
value: String
181-
item: LItem!
194+
item: LItemMetadata!
182195
}
183196

184197
type LRequest @entity {

src/GeneralizedTCRMapping.ts

Lines changed: 6 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,5 @@
11
/* eslint-disable prefer-const */
2-
import {
3-
Bytes,
4-
BigInt,
5-
Address,
6-
ipfs,
7-
json,
8-
log,
9-
} from '@graphprotocol/graph-ts';
2+
import { Bytes, BigInt, Address, log } from '@graphprotocol/graph-ts';
103
import {
114
Item,
125
Request,
@@ -36,6 +29,8 @@ import {
3629
Ruling,
3730
ConnectedTCRSet as ConnectedTCRSetEvent,
3831
} from '../generated/templates/GeneralizedTCR/GeneralizedTCR';
32+
import { GTCREvidenceMetadata as EvidenceMetadataTemplate } from '../generated/templates';
33+
import { extractPath } from './utils';
3934

4035
// Items on a TCR can be in 1 of 4 states:
4136
// - (0) Absent: The item is not registered on the TCR and there are no pending requests.
@@ -616,80 +611,9 @@ export function handleEvidence(event: EvidenceEvent): void {
616611
BigInt.fromI32(1),
617612
);
618613

619-
// Try to parse and store evidence fields.
620-
let jsonStr = ipfs.cat(event.params._evidence);
621-
if (!jsonStr) {
622-
log.warning('Failed to fetch evidence {}', [event.params._evidence]);
623-
evidenceGroup.save();
624-
evidence.save();
625-
return;
626-
}
627-
628-
let jsonObjValueAndSuccess = json.try_fromBytes(jsonStr as Bytes);
629-
if (!jsonObjValueAndSuccess.isOk) {
630-
log.warning(`Error getting json object value for evidence {}`, [
631-
event.params._evidence,
632-
]);
633-
evidenceGroup.save();
634-
evidence.save();
635-
return;
636-
}
637-
638-
let jsonObj = jsonObjValueAndSuccess.value.toObject();
639-
if (!jsonObj) {
640-
log.warning(`Error converting object for evidence {}`, [
641-
event.params._evidence,
642-
]);
643-
evidenceGroup.save();
644-
evidence.save();
645-
return;
646-
}
647-
648-
let nameValue = jsonObj.get('name');
649-
if (!nameValue) {
650-
log.warning(`Error getting name value for evidence {}`, [
651-
event.params._evidence,
652-
]);
653-
} else {
654-
evidence.name = nameValue.toString();
655-
}
656-
657-
// Somehow Curate uses "title"?? so fetch in case
658-
let titleValue = jsonObj.get('title');
659-
if (!titleValue) {
660-
log.warning(`Error getting title value for evidence {}`, [
661-
event.params._evidence,
662-
]);
663-
} else {
664-
evidence.title = titleValue.toString();
665-
}
666-
667-
let descriptionValue = jsonObj.get('description');
668-
if (!descriptionValue) {
669-
log.warning(`Error getting description value for evidence {}`, [
670-
event.params._evidence,
671-
]);
672-
} else {
673-
evidence.description = descriptionValue.toString();
674-
}
675-
676-
let fileURIValue = jsonObj.get('fileURI');
677-
if (!fileURIValue) {
678-
log.warning(`Error getting fileURI value for evidence {}`, [
679-
event.params._evidence,
680-
]);
681-
} else {
682-
evidence.fileURI = fileURIValue.toString();
683-
}
684-
685-
let fileTypeExtensionValue = jsonObj.get('fileTypeExtension');
686-
if (!fileTypeExtensionValue) {
687-
log.warning(`Error getting fileTypeExtension value for evidence {}`, [
688-
event.params._evidence,
689-
]);
690-
} else {
691-
evidence.fileTypeExtension = fileTypeExtensionValue.toString();
692-
}
614+
const ipfsHash = extractPath(event.params._evidence);
615+
evidence.metadata = ipfsHash;
616+
EvidenceMetadataTemplate.create(ipfsHash);
693617

694618
evidenceGroup.save();
695619
evidence.save();

0 commit comments

Comments
 (0)