From f341b2eec7e296d959c1386ac321952c2db8e11c Mon Sep 17 00:00:00 2001 From: Teo Gebhard Date: Wed, 21 May 2025 21:46:39 +0300 Subject: [PATCH 1/5] idAsString --- packages/network-subgraphs/schema.graphql | 2 ++ packages/network-subgraphs/src/streamRegistry.ts | 1 + 2 files changed, 3 insertions(+) diff --git a/packages/network-subgraphs/schema.graphql b/packages/network-subgraphs/schema.graphql index 6294e92db..666d56719 100644 --- a/packages/network-subgraphs/schema.graphql +++ b/packages/network-subgraphs/schema.graphql @@ -35,6 +35,8 @@ type StreamPermission @entity { type Stream @entity { "stream ID = 'creator address'/'path' where path can be any string" id: ID! + "Contains same value as in the id field. This field allows us do to substring queries for the field id (by using idAsString_contains where clause)" + idAsString: String! @index "Stream metadata JSON" metadata: String! "Permissions that each Ethereum address owns to this stream" diff --git a/packages/network-subgraphs/src/streamRegistry.ts b/packages/network-subgraphs/src/streamRegistry.ts index ee4268bc5..a70f64db1 100644 --- a/packages/network-subgraphs/src/streamRegistry.ts +++ b/packages/network-subgraphs/src/streamRegistry.ts @@ -19,6 +19,7 @@ export function handleStreamCreation(event: StreamCreated): void { log.info('handleStreamCreation: id={} metadata={} blockNumber={}', [event.params.id, event.params.metadata, event.block.number.toString()]) let stream = new Stream(event.params.id) + stream.idAsString = event.params.id, stream.metadata = event.params.metadata stream.createdAt = event.block.timestamp stream.updatedAt = event.block.timestamp From 84d1a829c077183aba8d6dfad5dda149b2d6a307 Mon Sep 17 00:00:00 2001 From: Teo Gebhard Date: Fri, 23 May 2025 16:53:23 +0300 Subject: [PATCH 2/5] wording --- packages/network-subgraphs/schema.graphql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/network-subgraphs/schema.graphql b/packages/network-subgraphs/schema.graphql index 666d56719..3a3a7e215 100644 --- a/packages/network-subgraphs/schema.graphql +++ b/packages/network-subgraphs/schema.graphql @@ -35,7 +35,7 @@ type StreamPermission @entity { type Stream @entity { "stream ID = 'creator address'/'path' where path can be any string" id: ID! - "Contains same value as in the id field. This field allows us do to substring queries for the field id (by using idAsString_contains where clause)" + "This field has the same value as the ID field. It enables us to perform substring queries on the id field using the idAsString_contains where clause" idAsString: String! @index "Stream metadata JSON" metadata: String! From d5dcc2ae709da67476c7a58dc53ced14cd04684c Mon Sep 17 00:00:00 2001 From: Teo Gebhard Date: Mon, 16 Jun 2025 18:29:11 +0300 Subject: [PATCH 3/5] rm unnecessary comma --- packages/network-subgraphs/src/streamRegistry.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/network-subgraphs/src/streamRegistry.ts b/packages/network-subgraphs/src/streamRegistry.ts index 0fa639eb2..bdb6cfb16 100644 --- a/packages/network-subgraphs/src/streamRegistry.ts +++ b/packages/network-subgraphs/src/streamRegistry.ts @@ -20,7 +20,7 @@ export function handleStreamCreation(event: StreamCreated): void { return } let stream = new Stream(event.params.id) - stream.idAsString = event.params.id, + stream.idAsString = event.params.id stream.metadata = event.params.metadata stream.createdAt = event.block.timestamp stream.updatedAt = event.block.timestamp From 3d59dad4136d63dd6b7ba84ed8b23a3adada9ed7 Mon Sep 17 00:00:00 2001 From: Teo Gebhard Date: Mon, 16 Jun 2025 18:56:01 +0300 Subject: [PATCH 4/5] set idAsString in handleStreamUpdate() --- packages/network-subgraphs/src/streamRegistry.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/packages/network-subgraphs/src/streamRegistry.ts b/packages/network-subgraphs/src/streamRegistry.ts index bdb6cfb16..a1828b0f6 100644 --- a/packages/network-subgraphs/src/streamRegistry.ts +++ b/packages/network-subgraphs/src/streamRegistry.ts @@ -38,7 +38,16 @@ export function handleStreamUpdate(event: StreamUpdated): void { [event.params.id, event.params.metadata, event.block.number.toString()]) let stream = Stream.load(event.params.id) if (stream === null) { + // If the stream was initialized using the trustedSetStreamMetadata() method instead of the usual createStream(), + // the Stream entity does not yet exist. This pattern was used at least in the brubeck-migration-script + // (see: https://polygonscan.com/tx/0x8b3f4eee260cab5b7eed2f90f09db14f35d96bf231368df44988b3035b41a543), + // and possibly in ENS stream creation as well (see: https://github.com/streamr-dev/network-contracts/pull/109). + // The trustedSetStreamMetadata() method, which existed in StreamRegistry before version 5, + // only emitted a StreamUpdated event. Since no StreamCreated event was triggered during this process, + // the handleStreamCreation() function was never called, and the Stream entity wasn't created. + // Therefore, we need to create it here manually. stream = new Stream(event.params.id) + stream.idAsString = event.params.id stream.createdAt = event.block.timestamp } stream.metadata = event.params.metadata From b44ace4dba675d74d948ae22db7736bdfb5d085c Mon Sep 17 00:00:00 2001 From: Teo Gebhard Date: Mon, 16 Jun 2025 19:43:32 +0300 Subject: [PATCH 5/5] update comment --- packages/network-subgraphs/src/streamRegistry.ts | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/packages/network-subgraphs/src/streamRegistry.ts b/packages/network-subgraphs/src/streamRegistry.ts index a1828b0f6..fedf9f839 100644 --- a/packages/network-subgraphs/src/streamRegistry.ts +++ b/packages/network-subgraphs/src/streamRegistry.ts @@ -40,12 +40,11 @@ export function handleStreamUpdate(event: StreamUpdated): void { if (stream === null) { // If the stream was initialized using the trustedSetStreamMetadata() method instead of the usual createStream(), // the Stream entity does not yet exist. This pattern was used at least in the brubeck-migration-script - // (see: https://polygonscan.com/tx/0x8b3f4eee260cab5b7eed2f90f09db14f35d96bf231368df44988b3035b41a543), - // and possibly in ENS stream creation as well (see: https://github.com/streamr-dev/network-contracts/pull/109). - // The trustedSetStreamMetadata() method, which existed in StreamRegistry before version 5, - // only emitted a StreamUpdated event. Since no StreamCreated event was triggered during this process, - // the handleStreamCreation() function was never called, and the Stream entity wasn't created. - // Therefore, we need to create it here manually. + // (see https://github.com/streamr-dev/network-contracts/pull/1007), and possibly also in ENS stream creation + // (see https://github.com/streamr-dev/network-contracts/pull/109). + // The trustedSetStreamMetadata() method, which existed in StreamRegistry before version 5, only emitted + // the StreamUpdated event. Since no StreamCreated event was triggered during this process, the handleStreamCreation() + // function was not called, and therefore the Stream entity wasn't created. For this reason we need to create it here. stream = new Stream(event.params.id) stream.idAsString = event.params.id stream.createdAt = event.block.timestamp