import { Address } from '@graphprotocol/graph-ts' ; import { DeployAPM as DeployAPMEvent } from '../../generated/ApmRegistryFactory/APMRegistryFactory' ; import { RegistryFactory as RegistryFactoryEntity } from '../../generated/schema' ; import { Registry as RegistryTemplate } from '../../generated/templates' ; import { loadOrCreateRegistry } from './registry' ; export function handleDeployAPM ( event ) { const factory = loadOrCreateApmFactory ( event . address ) ; const registryAddress = event . params . apm ; const registry = loadOrCreateRegistry ( registryAddress , event . params . node ) ; const currentRegistries = factory . registries ; currentRegistries . push ( registry . id ) ; factory . registries = currentRegistries ; factory . registryCount = factory . registryCount + 1 ; factory . save ( ) ; registry . save ( ) ; RegistryTemplate . create ( registryAddress ) ; } function loadOrCreateApmFactory ( factoryAddress ) { let factory = RegistryFactoryEntity . load ( '1' ) ; if ( factory === null ) { factory = new RegistryFactoryEntity ( '1' ) ; factory . address = factoryAddress ; factory . registryCount = 0 ; factory . registries = [ ] ; } return factory ! ; }