-
Notifications
You must be signed in to change notification settings - Fork 49
Refactor/evidence refactors #1634
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 4 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
5f1bbe0
feat(subgraph): add-additional-fields-in-evidence-entity
tractorss 4822433
refactor(contracts): update-evidence-module-natspecs
tractorss 7cf0b1e
refactor(web): support-new-evidence-refactors
tractorss 2d23ed7
feat(subgraph): evidence-fulltext-search
tractorss 8637c5e
feat(web): evidence-search
tractorss 653f505
Merge branch 'dev' into refactor/evidence-refactors
alcercu 78a063f
Merge branch 'refactor/evidence-refactors' into feat/evidence-search
alcercu d1b6fe2
Merge pull request #1640 from kleros/feat/evidence-search
alcercu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,61 @@ | ||
import { json, JSONValueKind, log } from "@graphprotocol/graph-ts"; | ||
import { Evidence as EvidenceEvent } from "../generated/EvidenceModule/EvidenceModule"; | ||
import { ClassicEvidence } from "../generated/schema"; | ||
import { ensureClassicEvidenceGroup } from "./entities/ClassicEvidenceGroup"; | ||
import { ensureUser } from "./entities/User"; | ||
import { ONE } from "./utils"; | ||
import { JSONValueToMaybeString } from "../../utils"; | ||
|
||
export function handleEvidenceEvent(event: EvidenceEvent): void { | ||
const evidenceGroupID = event.params._externalDisputeID.toString(); | ||
const evidenceGroup = ensureClassicEvidenceGroup(evidenceGroupID); | ||
const evidenceIndex = evidenceGroup.nextEvidenceIndex; | ||
evidenceGroup.nextEvidenceIndex = evidenceGroup.nextEvidenceIndex.plus(ONE); | ||
evidenceGroup.save(); | ||
const evidence = new ClassicEvidence(`${evidenceGroupID}-${evidenceIndex.toString()}`); | ||
const evidenceId = `${evidenceGroupID}-${evidenceIndex.toString()}`; | ||
const evidence = new ClassicEvidence(evidenceId); | ||
const userId = event.params._party.toHexString(); | ||
evidence.timestamp = event.block.timestamp; | ||
evidence.evidence = event.params._evidence; | ||
evidence.evidenceGroup = evidenceGroupID.toString(); | ||
evidence.sender = userId; | ||
ensureUser(userId); | ||
|
||
let jsonObjValueAndSuccess = json.try_fromString(event.params._evidence); | ||
if (!jsonObjValueAndSuccess.isOk || jsonObjValueAndSuccess.isError) { | ||
log.error(`Error getting json object for evidenceId {}`, [evidenceId]); | ||
evidence.save(); | ||
return; | ||
} | ||
|
||
if (jsonObjValueAndSuccess.value.isNull() || jsonObjValueAndSuccess.value.kind !== JSONValueKind.OBJECT) { | ||
log.error(`Encountered invalid parsed value for evidenceId {}`, [evidenceId]); | ||
evidence.save(); | ||
return; | ||
} | ||
|
||
let jsonObj = jsonObjValueAndSuccess.value.toObject(); | ||
if (!jsonObj) { | ||
log.error(`Error converting json object for evidenceId {}`, [evidenceId]); | ||
evidence.save(); | ||
return; | ||
} | ||
|
||
let name = jsonObj.get("name"); | ||
let description = jsonObj.get("description"); | ||
let fileURI = jsonObj.get("fileURI"); | ||
let fileTypeExtension = jsonObj.get("fileTypeExtension"); | ||
|
||
evidence.name = JSONValueToMaybeString(name); | ||
evidence.description = JSONValueToMaybeString(description); | ||
|
||
if (fileURI) { | ||
evidence.fileURI = JSONValueToMaybeString(fileURI); | ||
} | ||
|
||
if (fileTypeExtension) { | ||
evidence.fileTypeExtension = JSONValueToMaybeString(fileTypeExtension); | ||
} | ||
|
||
evidence.save(); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { JSONValue, JSONValueKind } from "@graphprotocol/graph-ts"; | ||
|
||
export function JSONValueToMaybeString(value: JSONValue | null, _default: string = "-"): string { | ||
// Subgraph considers an empty string to be null and | ||
// the handler crashes when attempting to save the entity. | ||
// This is a security vulnerability because an adversary | ||
// could manually craft an item with missing columns | ||
// and the item would not show up in the UI, passing | ||
// the challenge period unoticed. | ||
// | ||
// We fix this by setting the field manually to a hifen. | ||
if (value == null || value.isNull()) { | ||
return "-"; | ||
} | ||
|
||
switch (value.kind) { | ||
case JSONValueKind.BOOL: | ||
return value.toBool() == true ? "true" : "false"; | ||
case JSONValueKind.STRING: | ||
return value.toString(); | ||
case JSONValueKind.NUMBER: | ||
return value.toBigInt().toHexString(); | ||
default: | ||
return _default; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.