-
Notifications
You must be signed in to change notification settings - Fork 1
/
postBatch.ts
50 lines (41 loc) · 1.12 KB
/
postBatch.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env node
import { chdir } from "process";
chdir(__dirname);
import fs from "fs";
import { ethers } from "hardhat";
import { z } from "zod";
import { fieldToHex } from "../utils/mina";
const schema = z.object({
address: z.string(),
id: z.string().transform(fieldToHex),
previousId: z.string().transform(fieldToHex),
commands: z.array(
z.object({
commandType: z.number().int().gte(0).lte(1),
data: z.string().transform((data) => Buffer.from(data, "base64")),
})
),
});
const main = async () => {
const daFactory = await ethers.getContractFactory("DataAvailability");
const { address, id, previousId, commands } = schema.parse(
JSON.parse(fs.readFileSync(0).toString())
);
const contract = daFactory.attach(address);
try {
const tx = await contract.postBatch(id, previousId, commands);
await tx.wait();
} catch (e) {
if (
e instanceof Object &&
e.hasOwnProperty("reason") &&
// @ts-ignore
e.reason.includes("Batch already exists")
) {
process.exit(0);
}
console.error(e);
process.exit(1);
}
};
main().catch(console.error);