From 5fada67811f6ee21e477525dd6ff2c3cc3310025 Mon Sep 17 00:00:00 2001 From: yuetloo Date: Tue, 1 Mar 2022 14:42:24 -0500 Subject: [PATCH] subgraph mapping for universal recipient registry --- subgraph/schema.graphql | 1 + .../src/UniversalRecipientRegistryMapping.ts | 53 +++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 subgraph/src/UniversalRecipientRegistryMapping.ts diff --git a/subgraph/schema.graphql b/subgraph/schema.graphql index c87363f76..faaee113a 100644 --- a/subgraph/schema.graphql +++ b/subgraph/schema.graphql @@ -108,6 +108,7 @@ type Recipient @entity { deposit: BigInt recipientAddress: Bytes recipientMetadata: String + recipientMetadataId: String rejected: Boolean verified: Boolean voteOptionIndex: BigInt diff --git a/subgraph/src/UniversalRecipientRegistryMapping.ts b/subgraph/src/UniversalRecipientRegistryMapping.ts new file mode 100644 index 000000000..e7a202f4b --- /dev/null +++ b/subgraph/src/UniversalRecipientRegistryMapping.ts @@ -0,0 +1,53 @@ +import { BigInt, log } from '@graphprotocol/graph-ts' +import { + OwnershipTransferred, + RequestResolved, + RequestSubmitted, +} from '../generated/UniversalRecipientRegistry/UniversalRecipientRegistry' + +import { Recipient } from '../generated/schema' + +export function handleOwnershipTransferred(event: OwnershipTransferred): void { + log.info('handleOwnershipTransferred - universal recipient registry', []) +} + +export function handleRequestResolved(event: RequestResolved): void { + let recipientRegistryId = event.address.toHexString() + + log.info('handleRequestResolved', []) + let recipientId = event.params._recipientId.toHexString() + let recipient = new Recipient(recipientId) + + recipient.requestType = BigInt.fromI32(event.params._type).toString() + recipient.requester = event.transaction.from.toHexString() + recipient.submissionTime = event.params._timestamp.toString() + recipient.rejected = event.params._rejected + recipient.verified = !event.params._rejected + recipient.recipientRegistry = recipientRegistryId + recipient.recipientIndex = event.params._recipientIndex + recipient.requestResolvedHash = event.transaction.hash + + recipient.save() +} + +export function handleRequestSubmitted(event: RequestSubmitted): void { + log.info('handleRequestSubmitted', []) + let recipientRegistryId = event.address.toHexString() + + //TODO: create RecipientRegistry entity here if it does not exist. + + let recipientId = event.params._recipientId.toHexString() + let recipient = new Recipient(recipientId) + + recipient.recipientRegistry = recipientRegistryId + recipient.recipientAddress = event.params._recipient + recipient.recipientMetadataId = event.params._metadataId + recipient.requestType = BigInt.fromI32(event.params._type).toString() + recipient.requester = event.transaction.from.toHexString() + recipient.submissionTime = event.params._timestamp.toString() + recipient.deposit = event.transaction.value + recipient.verified = false + recipient.requestSubmittedHash = event.transaction.hash + + recipient.save() +}