-
Notifications
You must be signed in to change notification settings - Fork 1
/
process-idl.js
51 lines (45 loc) · 1.06 KB
/
process-idl.js
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
51
const fs = require("fs");
const path = require("path");
const idlFile = path.join(
__dirname,
"package",
"idl",
"stake_deposit_interceptor.json"
);
const replaceInFields = (obj) => {
if (!obj.fields) return;
obj.fields.forEach((field) => {
if (typeof field.type === "object") {
if (field.type.defined === "PodU64") {
field.type = "u64";
}
if (field.type.defined === "PodU32") {
field.type = "u32";
}
}
});
};
const overwriteTypes = (idl) => {
if (idl.types) {
idl.types.forEach((type) => {
replaceInFields(type);
});
}
if (idl.accounts) {
idl.accounts.forEach((account) => {
replaceInFields(account.type);
});
}
if (idl.instructions) {
idl.instructions.forEach((instruction) => {
instruction.accounts?.forEach(replaceInFields);
instruction.args?.forEach(replaceInFields);
});
}
};
const main = () => {
let idl = JSON.parse(fs.readFileSync(idlFile, "utf-8"));
overwriteTypes(idl);
fs.writeFileSync(idlFile, JSON.stringify(idl, null, 2));
};
main();