Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…into 999-credit-registry-page-preparation
  • Loading branch information
PiranavanShanmugavadivelu committed Dec 19, 2023
2 parents 5f53015 + 7810f84 commit b971174
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
2 changes: 2 additions & 0 deletions indexer/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ type CreditOffsetCertificate @entity {
retiringEntityName: String!
retiringEntityAdditionalData: String!
wallet: Wallet!
timestamp: Date!
}

type MarketplaceListing @entity {
Expand Down Expand Up @@ -88,6 +89,7 @@ type RetiredCreditsEvent @entity {
creditCollection: CreditCollection!
owner: String!
amount: BigInt!
timestamp: Date!
}

type CreateListingWasmEvent @entity {
Expand Down
9 changes: 6 additions & 3 deletions indexer/src/mappings/mappingHandlers.ts
Original file line number Diff line number Diff line change
@@ -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<void> {
const request = await fetch("https://api.rollbar.com/api/1/item/", {
Expand Down Expand Up @@ -220,6 +220,7 @@ export async function handleTransferCredits(event: CosmosEvent): Promise<void> {
recipient: recipient,
amount: amount,
creditCollectionId: denom,
timestamp: new Date(event.block.header.time.toISOString()),
});
await transferedCreditsEvent.save();

Expand Down Expand Up @@ -274,6 +275,7 @@ export async function handleRetiredCredits(event: CosmosEvent): Promise<void> {
owner: owner,
amount: amount,
creditCollectionId: denom,
timestamp: new Date(event.block.header.time.toISOString()),
});
await retiredCreditsEvent.save();

Expand All @@ -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<void> {
async function handleOffsetCertificate(certificateId: string, owner: string, certificateData: string, timestamp: string): Promise<void> {
certificateData = certificateData.replace(/(?:\\\\)*\\(?!\\)/g, '');
const certificate = JSON.parse(certificateData);
const denom = findCertificateDataValueByKey(certificate, "denom");
Expand All @@ -313,6 +315,7 @@ async function handleOffsetCertificate(certificateId: string, owner: string, cer
retiringEntityName: retiringEntityName,
retiringEntityAdditionalData: retiringEntityAdditionalData,
walletId: owner,
timestamp: timestamp,
});
await offsetCertificate.save();
}
Expand All @@ -336,7 +339,7 @@ export async function handleCreateCertificate(event: CosmosEvent): Promise<void>
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);
Expand Down

0 comments on commit b971174

Please sign in to comment.