diff --git a/indexer/schema.graphql b/indexer/schema.graphql index 80e4f3396..849356ba6 100644 --- a/indexer/schema.graphql +++ b/indexer/schema.graphql @@ -61,6 +61,7 @@ type CreditOffsetCertificate @entity { retiringEntityName: String! retiringEntityAdditionalData: String! wallet: Wallet! + timestamp: Date! } type MarketplaceListing @entity { @@ -88,6 +89,7 @@ type RetiredCreditsEvent @entity { creditCollection: CreditCollection! owner: String! amount: BigInt! + timestamp: Date! } type CreateListingWasmEvent @entity { diff --git a/indexer/src/mappings/mappingHandlers.ts b/indexer/src/mappings/mappingHandlers.ts index 845df0229..119d45f1f 100644 --- a/indexer/src/mappings/mappingHandlers.ts +++ b/indexer/src/mappings/mappingHandlers.ts @@ -1,8 +1,8 @@ -import { CreditCollection, EventData, MaterialData, MetadataUri, MediaFile, BinaryFile, ApplicantData, WebReference, CreditData, CreateListingWasmEvent, MarketplaceListing, BuyCreditsWasmEvent, UpdateListingWasmEvent, CancelListingWasmEvent, Country, Organization, Wallet, CreditBalance, TransferedCreditsEvent, RetiredCreditsEvent, Certificate, CreditOffsetCertificate } from "../types"; import { CosmosEvent, } from "@subql/types-cosmos"; import fetch from "node-fetch"; +import { ApplicantData, BinaryFile, BuyCreditsWasmEvent, CancelListingWasmEvent, Certificate, Country, CreateListingWasmEvent, CreditBalance, CreditCollection, CreditData, CreditOffsetCertificate, EventData, MarketplaceListing, MaterialData, MediaFile, MetadataUri, Organization, RetiredCreditsEvent, TransferedCreditsEvent, UpdateListingWasmEvent, Wallet, WebReference } from "../types"; async function logRollbarError(error: Error, txHash: string, blockHeight: number): Promise { const request = await fetch("https://api.rollbar.com/api/1/item/", { @@ -220,6 +220,7 @@ export async function handleTransferCredits(event: CosmosEvent): Promise { recipient: recipient, amount: amount, creditCollectionId: denom, + timestamp: new Date(event.block.header.time.toISOString()), }); await transferedCreditsEvent.save(); @@ -274,6 +275,7 @@ export async function handleRetiredCredits(event: CosmosEvent): Promise { owner: owner, amount: amount, creditCollectionId: denom, + timestamp: new Date(event.block.header.time.toISOString()), }); await retiredCreditsEvent.save(); @@ -296,7 +298,7 @@ function findCertificateDataValueByKey(certificate: any[], key: string): string return certificate.find(data => data.key === key).value; } -async function handleOffsetCertificate(certificateId: string, owner: string, certificateData: string): Promise { +async function handleOffsetCertificate(certificateId: string, owner: string, certificateData: string, timestamp: string): Promise { certificateData = certificateData.replace(/(?:\\\\)*\\(?!\\)/g, ''); const certificate = JSON.parse(certificateData); const denom = findCertificateDataValueByKey(certificate, "denom"); @@ -313,6 +315,7 @@ async function handleOffsetCertificate(certificateId: string, owner: string, cer retiringEntityName: retiringEntityName, retiringEntityAdditionalData: retiringEntityAdditionalData, walletId: owner, + timestamp: timestamp, }); await offsetCertificate.save(); } @@ -336,7 +339,7 @@ export async function handleCreateCertificate(event: CosmosEvent): Promise await certificate.save(); if (certificateType === "CREDIT_RETIREMENT") { - await handleOffsetCertificate(certificateId, owner, additionalData); + await handleOffsetCertificate(certificateId, owner, additionalData, event.block.header.time.toISOString()); } } catch (e) { await logRollbarError(e, event.tx.hash, event.block.header.height);