Add workflow for copying compiled artifacts to 0x/contract-artifacts (#1842)
The contract artifacts should remain as standard compiler output during development. Fields should only be removed/added prior to being published in `@0x/contract-artifacts`. This PR adds the `yarn transform` script to `@0x/contract-artifacts` to facilitate this. Going forward, `abi-gen-templates` will have to support both standard artifacts and modified artifacts if they diverge, since the templates are used for `contract-artifacts`/`abi-gen-wrappers` (modified artifact) *and* development in all the `contracts/*` packages (standard artifact). This PR makes the following changes to `contract-artifacts`: - remove `evm.bytecode.linkReferences` from all artifacts - remove `evm.deployedBytecode` and `sourceTreeHashHex` from Coordinator artifact - prettify all artifacts (whitespace only changes)
This commit is contained in:
50
packages/contract-artifacts/src/transform.ts
Normal file
50
packages/contract-artifacts/src/transform.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
import { deleteNestedProperty, logUtils } from '@0x/utils';
|
||||
import * as fs from 'fs';
|
||||
|
||||
export const REQUIRED_PROPERTIES: string[] = [
|
||||
'schemaVersion',
|
||||
'contractName',
|
||||
'compilerOutput.evm.bytecode.object',
|
||||
'compilerOutput.abi',
|
||||
];
|
||||
|
||||
export const FORBIDDEN_PROPERTIES: string[] = [
|
||||
'compilerOutput.evm.bytecode.sourceMap',
|
||||
'compilerOutput.evm.bytecode.opcodes',
|
||||
'compilerOutput.evm.bytecode.linkReferences',
|
||||
'compilerOutput.evm.deployedBytecode',
|
||||
'compilerOutput.evm.assembly',
|
||||
'compilerOutput.evm.legacyAssembly',
|
||||
'compilerOutput.evm.gasEstimates',
|
||||
'compilerOutput.evm.methodIdentifiers',
|
||||
'compilerOutput.metadata',
|
||||
'compilerOutput.userdoc',
|
||||
'sourceCodes',
|
||||
'sources',
|
||||
'sourceTreeHashHex',
|
||||
];
|
||||
|
||||
function removeForbiddenProperties(inputDir: string, outputDir: string): void {
|
||||
const filePaths = fs
|
||||
.readdirSync(inputDir)
|
||||
.filter(filename => filename.indexOf('.json') !== -1)
|
||||
.map(filename => `./${inputDir}/${filename}`);
|
||||
|
||||
for (const filePath of filePaths) {
|
||||
const artifact = JSON.parse(fs.readFileSync(filePath).toString()) as { [name: string]: any };
|
||||
for (const property of FORBIDDEN_PROPERTIES) {
|
||||
deleteNestedProperty(artifact, property);
|
||||
}
|
||||
fs.writeFileSync(filePath.replace(inputDir, outputDir), JSON.stringify(artifact));
|
||||
}
|
||||
}
|
||||
|
||||
if (require.main === module) {
|
||||
const inputDir = process.argv[2];
|
||||
const outputDir = process.argv[3] !== undefined ? process.argv[3] : inputDir;
|
||||
logUtils.log(`Deleting forbidden properties from artifacts in ${inputDir}. Output to ${outputDir}`);
|
||||
if (!fs.existsSync(`./${outputDir}`)) {
|
||||
fs.mkdirSync(`./${outputDir}`);
|
||||
}
|
||||
removeForbiddenProperties(inputDir, outputDir);
|
||||
}
|
Reference in New Issue
Block a user