forked from AztecProtocol/aztec-packages
-
Notifications
You must be signed in to change notification settings - Fork 0
/
extractFunctionAsNoirArtifact.js
52 lines (44 loc) · 1.54 KB
/
extractFunctionAsNoirArtifact.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
52
const path = require("path");
const fs = require("fs").promises;
// Simple script to extract a contract function as a separate Noir artifact.
// We need to use this since the transpiling that we do on public functions make the contract artifacts
// unreadable by noir tooling, since they are no longer following the noir artifact format.
async function main() {
let [contractArtifactPath, functionName] = process.argv.slice(2);
if (!contractArtifactPath || !functionName) {
console.log(
"Usage: node extractFunctionAsNoirArtifact.js <contractArtifactPath> <functionName>"
);
return;
}
const contractArtifact = JSON.parse(
await fs.readFile(contractArtifactPath, "utf8")
);
const func = contractArtifact.functions.find((f) => f.name === functionName);
if (!func) {
console.error(
`Function ${functionName} not found in ${contractArtifactPath}`
);
return;
}
const artifact = {
noir_version: contractArtifact.noir_version,
hash: 0,
abi: func.abi,
bytecode: func.bytecode,
debug_symbols: func.debug_symbols,
file_map: contractArtifact.file_map,
names: ["main"],
brillig_names: func.brillig_names,
};
const outputDir = path.dirname(contractArtifactPath);
const outputName =
path.basename(contractArtifactPath, ".json") + `-${functionName}.json`;
const outPath = path.join(outputDir, outputName);
console.log(`Writing to ${outPath}`);
await fs.writeFile(outPath, JSON.stringify(artifact, null, 2));
}
main().catch((err) => {
console.error(err);
process.exit(1);
});