Browse Source

EventID - add network

Leszek Wiesner 3 years ago
parent
commit
a96a01279b
2 changed files with 15 additions and 2 deletions
  1. 14 1
      query-node/mappings/common.ts
  2. 1 1
      query-node/schemas/common.graphql

+ 14 - 1
query-node/mappings/common.ts

@@ -14,7 +14,7 @@ export async function createEvent(
 ): Promise<Event> {
   const { blockNumber, index, extrinsic } = substrateEvent
   const event = new Event({
-    id: `${blockNumber}-${index}`,
+    id: `${CURRENT_NETWORK}-${blockNumber}-${index}`,
     inBlock: await getOrCreateBlock(db, substrateEvent),
     inExtrinsic: extrinsic?.hash,
     indexInBlock: index,
@@ -69,3 +69,16 @@ export async function getOrCreateBlock(
 export function bytesToString(b: Bytes): string {
   return Buffer.from(b.toU8a(true)).toString()
 }
+
+export function hasValuesForProperties<
+  T extends Record<string, unknown>,
+  P extends keyof T & string,
+  PA extends readonly P[]
+>(obj: T, props: PA): obj is T & { [K in PA[number]]: NonNullable<K> } {
+  props.forEach((p) => {
+    if (obj[p] === null || obj[p] === undefined) {
+      return false
+    }
+  })
+  return true
+}

+ 1 - 1
query-node/schemas/common.graphql

@@ -61,7 +61,7 @@ type Block @entity {
 }
 
 type Event @entity {
-  "{blockNumber}-{indexInBlock}"
+  "(network}-{blockNumber}-{indexInBlock}"
   id: ID!
 
   "Hash of the extrinsic which caused the event to be emitted"