Skip to content

Commit

Permalink
chore: migrate-to-file-data-source
Browse files Browse the repository at this point in the history
  • Loading branch information
Harman-singh-waraich committed May 2, 2024
1 parent 6494aa9 commit b61d70b
Show file tree
Hide file tree
Showing 10 changed files with 475 additions and 385 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
"@assemblyscript/loader": "^0.14.11",
"@assemblyscript/node": "github:AssemblyScript/node",
"@gnosis.pm/truffle-nice-tools": "^1.3.1",
"@graphprotocol/graph-cli": "^0.54.0",
"@graphprotocol/graph-ts": "^0.31.0",
"@graphprotocol/graph-cli": "^0.71.0",
"@graphprotocol/graph-ts": "^0.35.1",
"@kleros/erc-792": "3.0.0",
"@kleros/gtcr-encoder": "^1.1.3",
"@kleros/tcr": "^2.0.0",
Expand All @@ -62,7 +62,7 @@
"wait-on": "^5.2.0"
},
"volta": {
"node": "16.20.0",
"node": "20.11.0",
"yarn": "1.22.19"
}
}
45 changes: 29 additions & 16 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ type Evidence @entity {
timestamp: BigInt!
"Tx hash of the evidence submission"
txHash: Bytes!
metadata: EvidenceMetadata
}

type EvidenceMetadata @entity {
id: ID!
"Name of the evidence"
name: String
"Title of the evidence"
Expand Down Expand Up @@ -127,20 +132,6 @@ type LItem @entity {
itemID: Bytes!
"The data describing the item."
data: String!
"The parsed data describing the item."
props: [ItemProp!]! @derivedFrom(field: "item")
"First indexable value of the json file."
key0: String
"Second indexable value of the json file."
key1: String
"Third indexable value of the json file."
key2: String
"Fourth indexable value of the json file."
key3: String
"Fifth indexable value of the json file."
key4: String
"The item identifiers combined as a single string."
keywords: String
"The current status of the item."
status: Status!
"List of status change requests made for the item in the form requests[requestID]."
Expand All @@ -161,14 +152,36 @@ type LItem @entity {
latestRequester: Bytes!
"The account that challenged the latest request, if any."
latestChallenger: Bytes!
metadata: LItemMetadata
}

type LItemMetadata @entity {
"ipfs cid"
id: ID!
"The parsed data describing the item."
props: [ItemProp!]! @derivedFrom(field: "item")
"First indexable value of the json file."
key0: String
"Second indexable value of the json file."
key1: String
"Third indexable value of the json file."
key2: String
"Fourth indexable value of the json file."
key3: String
"Fifth indexable value of the json file."
key4: String
"The item identifiers combined as a single string."
keywords: String
"The item this metadata belongs to"
item: LItem! @derivedFrom(field: "metadata")

}
type _Schema_
@fulltext(
name: "itemSearch"
language: en
algorithm: rank
include: [{ entity: "LItem", fields: [{ name: "keywords" }] }]
include: [{ entity: "LItemMetadata", fields: [{ name: "keywords" }] }]
)

type ItemProp @entity {
Expand All @@ -178,7 +191,7 @@ type ItemProp @entity {
description: String!
isIdentifier: Boolean!
value: String
item: LItem!
item: LItemMetadata!
}

type LRequest @entity {
Expand Down
88 changes: 6 additions & 82 deletions src/GeneralizedTCRMapping.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
/* eslint-disable prefer-const */
import {
Bytes,
BigInt,
Address,
ipfs,
json,
log,
} from '@graphprotocol/graph-ts';
import { Bytes, BigInt, Address, log } from '@graphprotocol/graph-ts';
import {
Item,
Request,
Expand Down Expand Up @@ -36,6 +29,8 @@ import {
Ruling,
ConnectedTCRSet as ConnectedTCRSetEvent,
} from '../generated/templates/GeneralizedTCR/GeneralizedTCR';
import { GTCREvidenceMetadata as EvidenceMetadataTemplate } from '../generated/templates';
import { extractPath } from './utils';

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

// Try to parse and store evidence fields.
let jsonStr = ipfs.cat(event.params._evidence);
if (!jsonStr) {
log.warning('Failed to fetch evidence {}', [event.params._evidence]);
evidenceGroup.save();
evidence.save();
return;
}

let jsonObjValueAndSuccess = json.try_fromBytes(jsonStr as Bytes);
if (!jsonObjValueAndSuccess.isOk) {
log.warning(`Error getting json object value for evidence {}`, [
event.params._evidence,
]);
evidenceGroup.save();
evidence.save();
return;
}

let jsonObj = jsonObjValueAndSuccess.value.toObject();
if (!jsonObj) {
log.warning(`Error converting object for evidence {}`, [
event.params._evidence,
]);
evidenceGroup.save();
evidence.save();
return;
}

let nameValue = jsonObj.get('name');
if (!nameValue) {
log.warning(`Error getting name value for evidence {}`, [
event.params._evidence,
]);
} else {
evidence.name = nameValue.toString();
}

// Somehow Curate uses "title"?? so fetch in case
let titleValue = jsonObj.get('title');
if (!titleValue) {
log.warning(`Error getting title value for evidence {}`, [
event.params._evidence,
]);
} else {
evidence.title = titleValue.toString();
}

let descriptionValue = jsonObj.get('description');
if (!descriptionValue) {
log.warning(`Error getting description value for evidence {}`, [
event.params._evidence,
]);
} else {
evidence.description = descriptionValue.toString();
}

let fileURIValue = jsonObj.get('fileURI');
if (!fileURIValue) {
log.warning(`Error getting fileURI value for evidence {}`, [
event.params._evidence,
]);
} else {
evidence.fileURI = fileURIValue.toString();
}

let fileTypeExtensionValue = jsonObj.get('fileTypeExtension');
if (!fileTypeExtensionValue) {
log.warning(`Error getting fileTypeExtension value for evidence {}`, [
event.params._evidence,
]);
} else {
evidence.fileTypeExtension = fileTypeExtensionValue.toString();
}
const ipfsHash = extractPath(event.params._evidence);
evidence.metadata = ipfsHash;
EvidenceMetadataTemplate.create(ipfsHash);

evidenceGroup.save();
evidence.save();
Expand Down
Loading

0 comments on commit b61d70b

Please sign in to comment.