Skip to content

Commit

Permalink
Merge pull request #30 from kleros/fix/ipfs-migration
Browse files Browse the repository at this point in the history
Fix/ipfs migration
  • Loading branch information
jaybuidl authored May 13, 2024
2 parents bdec640 + 0572dc7 commit 185db46
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 5 deletions.
3 changes: 2 additions & 1 deletion snapshots/.env.example
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
PNK_DROP_JSON_RPC_URL='<string>'
PNK_DROP_JSON_RPC_URL='<string>'
FILEBASE_TOKEN='<BUCKET_TOKEN>'
4 changes: 2 additions & 2 deletions snapshots/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import utc from "dayjs/plugin/utc.js";
import { createSnapshotCreator } from "./src/create-snapshot-from-block-limits.js";
import { formatEther } from "ethers/lib/utils.js";
import fs from "fs";
import fileToIpfs from "@kleros/file-to-ipfs";
import { fileToIpfs } from "./src/fileToIpfs.js";

dotenv.config();

Expand Down Expand Up @@ -177,7 +177,7 @@ const main = async () => {
const path = `.cache/${sinfo.filename}`;
fs.writeFileSync(path, JSON.stringify(sinfo.snapshot));
const ipfsPath = await fileToIpfs(path);
console.log(`https://ipfs.kleros.io${ipfsPath}`);
console.log(`https://cdn.kleros.link/ipfs/${ipfsPath}`);
}

// txs to run sequentially, hardcoded section.
Expand Down
5 changes: 3 additions & 2 deletions snapshots/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"pnk-drop-snapshot": "./cli.js"
},
"dependencies": {
"@kleros/file-to-ipfs": "^0.2.1",
"@filebase/client": "^0.0.5",
"@kleros/merkle-tree": "^0.2.1",
"awaity": "^1.0.0",
"aws-sdk": "^2.841.0",
Expand All @@ -29,6 +29,7 @@
"eslint-plugin-json": "^3.1.0"
},
"volta": {
"node": "14.16.0"
"node": "18.20.2",
"yarn": "1.22.22"
}
}
17 changes: 17 additions & 0 deletions snapshots/src/fileToIpfs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import path from "path";
import fs from "fs";
import dotenv from "dotenv";

import { File, FilebaseClient } from "@filebase/client";
dotenv.config();

// The API-TOKEN defines in which bucket is going to be stored
const filebase = new FilebaseClient({ token: process.env.FILEBASE_TOKEN ?? "" });

export const fileToIpfs = async (filePath) => {
const content = await fs.promises.readFile(filePath);
const mimeType = 'application/json';
const fileName = path.basename(filePath);
const cid = await filebase.storeDirectory([new File([content], `${fileName}`, { type: mimeType })]);
return cid;
};

0 comments on commit 185db46

Please sign in to comment.