Skip to content

Commit

Permalink
Add changer
Browse files Browse the repository at this point in the history
  • Loading branch information
kongzii committed Jul 1, 2024
1 parent 04a6f26 commit 63208ad
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 1 deletion.
1 change: 1 addition & 0 deletions graphs/omen-thumbnailmapping/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ type OmenThumbnailMapping @entity {
id: Bytes! # same as marketAddress
marketAddress: Bytes! # address
image_hash: Bytes! # bytes32
changer: Bytes! # address
}
1 change: 1 addition & 0 deletions graphs/omen-thumbnailmapping/src/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export function handleImageUpdated(event: ImageUpdated): void {

mapping.marketAddress = event.params.marketAddress
mapping.image_hash = event.params.image_hash
mapping.changer = event.params.changer

mapping.save()
}
21 changes: 20 additions & 1 deletion graphs/omen-thumbnailmapping/src/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ export class OmenThumbnailMapping extends Entity {
save(): void {
let marketAddress = this.get("marketAddress");
let image_hash = this.get("image_hash");
let changer = this.get("changer");
assert(marketAddress != null, "Cannot save OmenThumbnailMapping entity without an marketAddress");
assert(image_hash != null, "Cannot save OmenThumbnailMapping entity without an image_hash");
if (marketAddress && image_hash) {
assert(changer != null, "Cannot save OmenThumbnailMapping entity without an changer");
if (marketAddress && image_hash && changer) {
assert(
marketAddress.kind == ValueKind.BYTES,
`Entities of type OmenThumbnailMapping must have an marketAddress of type Bytes but the marketAddress '${marketAddress.displayData()}' is of type ${marketAddress.displayKind()}`,
Expand All @@ -26,6 +28,10 @@ export class OmenThumbnailMapping extends Entity {
image_hash.kind == ValueKind.BYTES,
`Entities of type OmenThumbnailMapping must have an image_hash of type Bytes but the image_hash '${image_hash.displayData()}' is of type ${image_hash.displayKind()}`,
);
assert(
changer.kind == ValueKind.BYTES,
`Entities of type OmenThumbnailMapping must have an changer of type Bytes but the changer '${changer.displayData()}' is of type ${changer.displayKind()}`,
);
store.set("OmenThumbnailMapping", marketAddress.toBytes().toHexString(), this);
}
}
Expand Down Expand Up @@ -78,4 +84,17 @@ export class OmenThumbnailMapping extends Entity {
set image_hash(value: Bytes) {
this.set("image_hash", Value.fromBytes(value));
}

get changer(): Bytes {
let value = this.get("changer");
if (!value || value.kind == ValueKind.NULL) {
throw new Error("Cannot return null for a required field.");
} else {
return value.toBytes();
}
}

set changer(value: Bytes) {
this.set("changer", Value.fromBytes(value));
}
}
12 changes: 12 additions & 0 deletions graphs/omen-thumbnailmapping/tests/contract.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ describe("Test OmenThumbnailMapping", () => {
test("OmenThumbnailMapping created and stored", () => {
assert.entityCount("OmenThumbnailMapping", 1)

assert.fieldEquals(
"OmenThumbnailMapping",
"0x0000000000000000000000000000000000000001",
"id",
"0x0000000000000000000000000000000000000001"
)
assert.fieldEquals(
"OmenThumbnailMapping",
"0x0000000000000000000000000000000000000001",
Expand All @@ -45,5 +51,11 @@ describe("Test OmenThumbnailMapping", () => {
"image_hash",
"0xd2029649"
)
assert.fieldEquals(
"OmenThumbnailMapping",
"0x0000000000000000000000000000000000000001",
"changer",
"0x0000000000000000000000000000000000000002"
)
})
})

0 comments on commit 63208ad

Please sign in to comment.