mirror of
https://seed.radicle.dev/rad:z4V1sjrXqjvFdnCUbxPFqd5p4DtH5.git
synced 2026-11-20 22:00:43 +08:00
Upstream wasn't interested in updating to working js-yaml. Signed-off-by: Alexis Sellier <self@cloudhead.io>
27 lines
896 B
TypeScript
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)));
|
|
}
|