aboutsummaryrefslogtreecommitdiffstats
path: root/packages/sol-tracing-utils/src/artifact_adapters/sol_compiler_artifact_adapter.ts
diff options
context:
space:
mode:
authorHsuan Lee <boczeratul@gmail.com>2019-03-06 17:46:50 +0800
committerHsuan Lee <boczeratul@gmail.com>2019-03-06 17:46:50 +0800
commit35703539d0f2b4ddb3b11d0de8c9634af59ab71f (patch)
treeae3731221dbbb3a6fa40060a8d916cfd3f738289 /packages/sol-tracing-utils/src/artifact_adapters/sol_compiler_artifact_adapter.ts
parent92a1fde5b1ecd81b07cdb5bf0c9c1cd3544799db (diff)
downloaddexon-0x-contracts-35703539d0f2b4ddb3b11d0de8c9634af59ab71f.tar
dexon-0x-contracts-35703539d0f2b4ddb3b11d0de8c9634af59ab71f.tar.gz
dexon-0x-contracts-35703539d0f2b4ddb3b11d0de8c9634af59ab71f.tar.bz2
dexon-0x-contracts-35703539d0f2b4ddb3b11d0de8c9634af59ab71f.tar.lz
dexon-0x-contracts-35703539d0f2b4ddb3b11d0de8c9634af59ab71f.tar.xz
dexon-0x-contracts-35703539d0f2b4ddb3b11d0de8c9634af59ab71f.tar.zst
dexon-0x-contracts-35703539d0f2b4ddb3b11d0de8c9634af59ab71f.zip
Deploy @dexon-foundation/0x.jsstable
Diffstat (limited to 'packages/sol-tracing-utils/src/artifact_adapters/sol_compiler_artifact_adapter.ts')
-rw-r--r--packages/sol-tracing-utils/src/artifact_adapters/sol_compiler_artifact_adapter.ts77
1 files changed, 0 insertions, 77 deletions
diff --git a/packages/sol-tracing-utils/src/artifact_adapters/sol_compiler_artifact_adapter.ts b/packages/sol-tracing-utils/src/artifact_adapters/sol_compiler_artifact_adapter.ts
deleted file mode 100644
index bfd3a504a..000000000
--- a/packages/sol-tracing-utils/src/artifact_adapters/sol_compiler_artifact_adapter.ts
+++ /dev/null
@@ -1,77 +0,0 @@
-import { FallthroughResolver, FSResolver, NPMResolver, RelativeFSResolver, URLResolver } from '@0x/sol-resolver';
-import { logUtils } from '@0x/utils';
-import { CompilerOptions, ContractArtifact } from 'ethereum-types';
-import * as fs from 'fs';
-import * as glob from 'glob';
-import * as _ from 'lodash';
-import * as path from 'path';
-
-import { ContractData, SourceCodes, Sources } from '../types';
-
-import { AbstractArtifactAdapter } from './abstract_artifact_adapter';
-
-const CONFIG_FILE = 'compiler.json';
-
-export class SolCompilerArtifactAdapter extends AbstractArtifactAdapter {
- private readonly _artifactsPath: string;
- private readonly _sourcesPath: string;
- private readonly _resolver: FallthroughResolver;
- /**
- * Instantiates a SolCompilerArtifactAdapter
- * @param artifactsPath Path to your artifacts directory
- * @param sourcesPath Path to your contract sources directory
- */
- constructor(artifactsPath?: string, sourcesPath?: string) {
- super();
- const config: CompilerOptions = fs.existsSync(CONFIG_FILE)
- ? JSON.parse(fs.readFileSync(CONFIG_FILE).toString())
- : {};
- if (_.isUndefined(artifactsPath) && _.isUndefined(config.artifactsDir)) {
- throw new Error(`artifactsDir not found in ${CONFIG_FILE}`);
- }
- this._artifactsPath = (artifactsPath || config.artifactsDir) as string;
- if (_.isUndefined(sourcesPath) && _.isUndefined(config.contractsDir)) {
- throw new Error(`contractsDir not found in ${CONFIG_FILE}`);
- }
- this._sourcesPath = (sourcesPath || config.contractsDir) as string;
- this._resolver = new FallthroughResolver();
- this._resolver.appendResolver(new URLResolver());
- const packagePath = path.resolve('');
- this._resolver.appendResolver(new NPMResolver(packagePath));
- this._resolver.appendResolver(new RelativeFSResolver(this._sourcesPath));
- this._resolver.appendResolver(new FSResolver());
- }
- public async collectContractsDataAsync(): Promise<ContractData[]> {
- const artifactsGlob = `${this._artifactsPath}/**/*.json`;
- const artifactFileNames = glob.sync(artifactsGlob, { absolute: true });
- const contractsData: ContractData[] = [];
- for (const artifactFileName of artifactFileNames) {
- const artifact: ContractArtifact = JSON.parse(fs.readFileSync(artifactFileName).toString());
- if (_.isUndefined(artifact.compilerOutput.evm)) {
- logUtils.warn(`${artifactFileName} doesn't contain bytecode. Skipping...`);
- continue;
- }
- const sources: Sources = {};
- const sourceCodes: SourceCodes = {};
- _.map(artifact.sources, (value: { id: number }, relativeFilePath: string) => {
- const source = this._resolver.resolve(relativeFilePath);
- sources[value.id] = source.absolutePath;
- sourceCodes[value.id] = source.source;
- });
- const contractData = {
- sourceCodes,
- sources,
- bytecode: artifact.compilerOutput.evm.bytecode.object,
- sourceMap: artifact.compilerOutput.evm.bytecode.sourceMap,
- runtimeBytecode: artifact.compilerOutput.evm.deployedBytecode.object,
- sourceMapRuntime: artifact.compilerOutput.evm.deployedBytecode.sourceMap,
- };
- const isInterfaceContract = contractData.bytecode === '0x' && contractData.runtimeBytecode === '0x';
- if (isInterfaceContract) {
- continue;
- }
- contractsData.push(contractData);
- }
- return contractsData;
- }
-}