From 63208addb527ff1eb208e435c83b9a82040add7d Mon Sep 17 00:00:00 2001 From: Peter Jung Date: Mon, 1 Jul 2024 12:13:09 +0200 Subject: [PATCH] Add changer --- graphs/omen-thumbnailmapping/schema.graphql | 1 + graphs/omen-thumbnailmapping/src/contract.ts | 1 + graphs/omen-thumbnailmapping/src/schema.ts | 21 ++++++++++++++++++- .../tests/contract.test.ts | 12 +++++++++++ 4 files changed, 34 insertions(+), 1 deletion(-) diff --git a/graphs/omen-thumbnailmapping/schema.graphql b/graphs/omen-thumbnailmapping/schema.graphql index baa90f2..5b1d44e 100644 --- a/graphs/omen-thumbnailmapping/schema.graphql +++ b/graphs/omen-thumbnailmapping/schema.graphql @@ -2,4 +2,5 @@ type OmenThumbnailMapping @entity { id: Bytes! # same as marketAddress marketAddress: Bytes! # address image_hash: Bytes! # bytes32 + changer: Bytes! # address } diff --git a/graphs/omen-thumbnailmapping/src/contract.ts b/graphs/omen-thumbnailmapping/src/contract.ts index 0a84ef9..a81b7a1 100644 --- a/graphs/omen-thumbnailmapping/src/contract.ts +++ b/graphs/omen-thumbnailmapping/src/contract.ts @@ -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() } diff --git a/graphs/omen-thumbnailmapping/src/schema.ts b/graphs/omen-thumbnailmapping/src/schema.ts index 71ce75b..0b0ed9c 100644 --- a/graphs/omen-thumbnailmapping/src/schema.ts +++ b/graphs/omen-thumbnailmapping/src/schema.ts @@ -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()}`, @@ -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); } } @@ -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)); + } } diff --git a/graphs/omen-thumbnailmapping/tests/contract.test.ts b/graphs/omen-thumbnailmapping/tests/contract.test.ts index da49bb3..7e6dead 100644 --- a/graphs/omen-thumbnailmapping/tests/contract.test.ts +++ b/graphs/omen-thumbnailmapping/tests/contract.test.ts @@ -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", @@ -45,5 +51,11 @@ describe("Test OmenThumbnailMapping", () => { "image_hash", "0xd2029649" ) + assert.fieldEquals( + "OmenThumbnailMapping", + "0x0000000000000000000000000000000000000001", + "changer", + "0x0000000000000000000000000000000000000002" + ) }) })