-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: As a User, I want to check the number of Attestation, Modules, …
…Portals and Schemas from the subgraph (#237)
- Loading branch information
Showing
5 changed files
with
84 additions
and
4 deletions.
There are no files selected for viewing
This file contains 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 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 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,14 +1,32 @@ | ||
import { ModuleRegistered as ModuleRegisteredEvent, ModuleRegistry } from "../generated/ModuleRegistry/ModuleRegistry"; | ||
import { Module } from "../generated/schema"; | ||
import { Counter, Module } from "../generated/schema"; | ||
|
||
export function handleModuleRegistered(event: ModuleRegisteredEvent): void { | ||
const contract = ModuleRegistry.bind(event.address); | ||
const moduleData = contract.modules(event.params.moduleAddress); | ||
const module = new Module(event.params.moduleAddress.toHex()); | ||
|
||
incrementModulesCount(); | ||
|
||
module.moduleAddress = moduleData.getModuleAddress(); | ||
module.name = moduleData.getName(); | ||
module.description = moduleData.getDescription(); | ||
|
||
module.save(); | ||
} | ||
|
||
function incrementModulesCount(): void { | ||
let counter = Counter.load("counter"); | ||
|
||
if (!counter) { | ||
counter = new Counter("counter"); | ||
} | ||
|
||
if (!counter.modules) { | ||
counter.modules = 1; | ||
} else { | ||
counter.modules += 1; | ||
} | ||
|
||
counter.save(); | ||
} |
This file contains 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 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,15 +1,33 @@ | ||
import { SchemaCreated as SchemaCreatedEvent, SchemaRegistry } from "../generated/SchemaRegistry/SchemaRegistry"; | ||
import { Schema } from "../generated/schema"; | ||
import { Counter, Schema } from "../generated/schema"; | ||
|
||
export function handleSchemaCreated(event: SchemaCreatedEvent): void { | ||
const contract = SchemaRegistry.bind(event.address); | ||
const schemaData = contract.getSchema(event.params.id); | ||
const schema = new Schema(event.params.id.toHex()); | ||
|
||
incrementSchemasCount(); | ||
|
||
schema.name = schemaData.name; | ||
schema.description = schemaData.description; | ||
schema.context = schemaData.context; | ||
schema.schema = schemaData.schema; | ||
|
||
schema.save(); | ||
} | ||
|
||
function incrementSchemasCount(): void { | ||
let counter = Counter.load("counter"); | ||
|
||
if (!counter) { | ||
counter = new Counter("counter"); | ||
} | ||
|
||
if (!counter.schemas) { | ||
counter.schemas = 1; | ||
} else { | ||
counter.schemas += 1; | ||
} | ||
|
||
counter.save(); | ||
} |