-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathextract-abis.js
More file actions
36 lines (31 loc) · 1.12 KB
/
extract-abis.js
File metadata and controls
36 lines (31 loc) · 1.12 KB
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
const fs = require('fs');
const path = require('path');
const contractsDir = path.join(__dirname, 'security-pg-core-contracts/out');
const destDir = path.join(__dirname, 'src/abi');
if (!fs.existsSync(destDir)) {
fs.mkdirSync(destDir, { recursive: true });
}
const contracts = [
'ChallengeRegistry',
'ChallengeValidator',
'ProgressTracker'
];
contracts.forEach(contractName => {
const sourcePath = path.join(contractsDir, `${contractName}.sol`, `${contractName}.json`);
const destPath = path.join(destDir, `${contractName}.json`);
try {
if (fs.existsSync(sourcePath)) {
const data = JSON.parse(fs.readFileSync(sourcePath, 'utf8'));
if (data.abi) {
fs.writeFileSync(destPath, JSON.stringify(data.abi, null, 2));
console.log(`Extracted ABI for ${contractName}`);
} else {
console.error(`No ABI found in ${sourcePath}`);
}
} else {
console.error(`Source file not found: ${sourcePath}`);
}
} catch (err) {
console.error(`Error processing ${contractName}:`, err);
}
});