-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
2,475 additions
and
130 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export class Report { | ||
name: string; | ||
description: string; | ||
|
||
constructor(name: string, description: string) { | ||
this.name = name; | ||
this.description = description; | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { ClaimsByOwnerQuery, HypercertClient } from "@hypercerts-org/sdk"; | ||
|
||
import { Report } from "../model/report"; | ||
import { GraphService } from "./service/graph-service.server"; | ||
import { IpfsService } from "./service/ipfs-service.server"; | ||
|
||
export class ReportService { | ||
private static instance: ReportService; | ||
reports: Report[]; | ||
|
||
hypercertClient: HypercertClient; | ||
|
||
constructor() { | ||
this.reports = new Array<Report>(); | ||
|
||
this.hypercertClient = new HypercertClient({ | ||
chain: { id: 11155111 }, // Sepolia | ||
}); | ||
} | ||
|
||
static async getInstance(): Promise<ReportService> { | ||
if (!ReportService.instance) { | ||
ReportService.instance = new ReportService(); | ||
await ReportService.instance.init(); | ||
} | ||
|
||
return ReportService.instance; | ||
} | ||
|
||
getReports() { | ||
return this.reports; | ||
} | ||
|
||
private async init() { | ||
const claims = await this.getHyperCertClaims(); | ||
for (const claim of claims) { | ||
const metadata = await this.getHyperCertMetadata(claim.uri as string); | ||
|
||
this.reports.push(new Report(metadata.name, metadata.description)); | ||
} | ||
} | ||
|
||
private async getHyperCertClaims() { | ||
const graphService = await GraphService.getInstance(); | ||
const { claims } = (await graphService.claimsByOwner( | ||
"0x42fbf4d890b4efa0fb0b56a9cc2c5eb0e07c1536", | ||
)) as ClaimsByOwnerQuery; | ||
|
||
return claims; | ||
} | ||
|
||
private async getHyperCertMetadata(claimUri: string) { | ||
const ipfsService = await IpfsService.getInstance(); | ||
const metadata = await ipfsService.getMetadata(claimUri); | ||
|
||
return metadata; | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import type { HypercertClient } from "@hypercerts-org/sdk"; | ||
|
||
import { ReportService } from "../bootstrap.server"; | ||
|
||
// graphql schema of hypercert v1.4.1: https://github.com/hypercerts-org/hypercerts/blob/89009f1fcd072aaedd06ede8ba264623277244e9/graph/schema.graphql | ||
export class GraphService { | ||
private static instance: GraphService; | ||
private hypercertClient: HypercertClient; | ||
|
||
constructor(hypercertClient: HypercertClient) { | ||
this.hypercertClient = hypercertClient; | ||
} | ||
|
||
static async getInstance(): Promise<GraphService> { | ||
if (!GraphService.instance) { | ||
GraphService.instance = new GraphService( | ||
(await ReportService.getInstance()).hypercertClient, | ||
); | ||
} | ||
return GraphService.instance; | ||
} | ||
|
||
// see graphql query: https://github.com/hypercerts-org/hypercerts/blob/main/sdk/src/indexer/queries/claims.graphql#L1-L11 | ||
async claimsByOwner(owner: string) { | ||
return await this.hypercertClient.indexer.claimsByOwner(owner); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import type { HypercertClient } from "@hypercerts-org/sdk"; | ||
|
||
import { ReportService } from "../bootstrap.server"; | ||
|
||
export class IpfsService { | ||
private static instance: IpfsService; | ||
private hypercertClient: HypercertClient; | ||
|
||
constructor(hypercertClient: HypercertClient) { | ||
this.hypercertClient = hypercertClient; | ||
} | ||
|
||
static async getInstance(): Promise<IpfsService> { | ||
if (!IpfsService.instance) { | ||
IpfsService.instance = new IpfsService( | ||
(await ReportService.getInstance()).hypercertClient, | ||
); | ||
} | ||
return IpfsService.instance; | ||
} | ||
|
||
// get metadata of hypercert claim | ||
// see Hypercert metadata format v1.4.1: https://github.com/hypercerts-org/hypercerts/blob/89009f1fcd072aaedd06ede8ba264623277244e9/sdk/src/types/metadata.d.ts#L11-L46 | ||
async getMetadata(claimUri: string) { | ||
return await this.hypercertClient.storage.getMetadata(claimUri); | ||
} | ||
} |
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
Oops, something went wrong.