proposal-31-finalize-decent.../scripts/calculateIPFSContenthashes.ts
2023-10-18 08:11:34 -07:00

24 lines
780 B
TypeScript

// @ts-ignore
import contentHash from "content-hash";
import fs from "fs";
import path from "path";
import { DeclCalculator } from "./utils";
import { ipfsCids } from "./constants";
const contentHashToBytesMemory = (hash: string) => `hex"${hash}"`;
const ipfsCidToBytesMemory = (cid: string) => contentHashToBytesMemory(contentHash.fromIpfs(cid));
const solidityDoublePadding = " ".repeat(8);
const { calculateDecl: calculateContenthashDecl } = new DeclCalculator(
"bytes memory",
solidityDoublePadding,
ipfsCidToBytesMemory,
(name: string) => name + "Contenthash"
);
const solidityCode = Object.entries(ipfsCids)
.map((e) => calculateContenthashDecl(e))
.join("");
fs.writeFileSync(path.join("data", "ensDomainsIPFSContenthashes.txt"), solidityCode);