Files
radicle-explorer/src/anchors.ts
T
Alexis Sellier 6f2f8c454f Switch to @radicle/gray-matter fork
Upstream wasn't interested in updating to working js-yaml.

Signed-off-by: Alexis Sellier <self@cloudhead.io>
2022-03-22 18:02:30 +01:00

27 lines
896 B
TypeScript

import { ethers } from "ethers";
import type { Config } from "./config";
import { decodeRadicleId, formatProjectHash, querySubgraph } from "@app/utils";
const GetAllAnchors = `
query GetAllAnchors($project: Bytes!, $org: ID!) {
anchors(orderBy: timestamp, orderDirection: desc, where: { objectId: $project, org: $org }) {
multihash
timestamp
}
}
`;
interface AnchorObject {
timestamp: number;
multihash: string;
}
export async function getProjectAnchors(urn: string, anchorsStorage: string, config: Config): Promise<string[]> {
const unpadded = decodeRadicleId(urn);
const id = ethers.utils.hexZeroPad(unpadded, 32);
const allAnchors = await querySubgraph(config.orgs.subgraph, GetAllAnchors, { project: id, org: anchorsStorage });
return allAnchors.anchors
.map((anchor: AnchorObject) => formatProjectHash(ethers.utils.arrayify(anchor.multihash)));
}