blob: 53449e5e1355da6ac56dffab27925daa02a0b380 (
plain) (
blame)
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
|
import { Compiler, CompilerOptions } from '@0xproject/sol-compiler';
import * as rimraf from 'rimraf';
import { ContractData } from '../types';
import { AbstractArtifactAdapter } from './abstract_artifact_adapter';
import { SolCompilerArtifactAdapter } from './sol_compiler_artifact_adapter';
export class TruffleArtifactAdapter extends AbstractArtifactAdapter {
private _solcVersion: string;
private _sourcesPath: string;
constructor(sourcesPath: string, solcVersion: string) {
super();
this._solcVersion = solcVersion;
this._sourcesPath = sourcesPath;
}
public async collectContractsDataAsync(): Promise<ContractData[]> {
const artifactsDir = '.0x-artifacts';
const compilerOptions: CompilerOptions = {
contractsDir: this._sourcesPath,
artifactsDir,
compilerSettings: {
outputSelection: {
['*']: {
['*']: ['abi', 'evm.bytecode.object', 'evm.deployedBytecode.object'],
},
},
},
contracts: '*',
solcVersion: this._solcVersion,
};
const compiler = new Compiler(compilerOptions);
await compiler.compileAsync();
const solCompilerArtifactAdapter = new SolCompilerArtifactAdapter(artifactsDir, this._sourcesPath);
const contractsDataFrom0xArtifacts = await solCompilerArtifactAdapter.collectContractsDataAsync();
rimraf.sync(artifactsDir);
return contractsDataFrom0xArtifacts;
}
}
|