aboutsummaryrefslogtreecommitdiffstats
path: root/packages/deployer/src/compiler.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/deployer/src/compiler.ts')
-rw-r--r--packages/deployer/src/compiler.ts37
1 files changed, 28 insertions, 9 deletions
diff --git a/packages/deployer/src/compiler.ts b/packages/deployer/src/compiler.ts
index 149ca5d6d..7c60a099b 100644
--- a/packages/deployer/src/compiler.ts
+++ b/packages/deployer/src/compiler.ts
@@ -1,6 +1,10 @@
+import { promisify } from '@0xproject/utils';
import * as ethUtil from 'ethereumjs-util';
+import * as fs from 'fs';
+import 'isomorphic-fetch';
import * as _ from 'lodash';
import * as path from 'path';
+import * as requireFromString from 'require-from-string';
import solc = require('solc');
import * as Web3 from 'web3';
@@ -15,7 +19,6 @@ import {
ContractSourceData,
ContractSources,
ContractSpecificSourceData,
- ImportContents,
} from './utils/types';
import { utils } from './utils/utils';
@@ -186,9 +189,18 @@ export class Compiler {
}
const fullSolcVersion = binPaths[contractSpecificSourceData.solcVersion];
- const solcBinPath = `./solc/solc_bin/${fullSolcVersion}`;
- const solcBin = require(solcBinPath);
- const solcInstance = solc.setupMethods(solcBin);
+ const compiler_bin_filename = path.join(__dirname, '../../solc_bin', fullSolcVersion);
+ let solcjs: string;
+ if (fs.existsSync(compiler_bin_filename)) {
+ solcjs = fs.readFileSync(compiler_bin_filename).toString();
+ } else {
+ utils.consoleLog(`Downloading ${fullSolcVersion}...`);
+ const url = `https://ethereum.github.io/solc-bin/bin/${fullSolcVersion}`;
+ const response = await fetch(url);
+ solcjs = await response.text();
+ fs.writeFileSync(compiler_bin_filename, solcjs);
+ }
+ const solcInstance = solc.setupMethods(requireFromString(solcjs, compiler_bin_filename));
utils.consoleLog(`Compiling ${fileName}...`);
const source = this._contractSources[fileName];
@@ -210,11 +222,14 @@ export class Compiler {
this._solcErrors.add(normalizedErrMsg);
});
}
-
const contractName = path.basename(fileName, constants.SOLIDITY_FILE_EXTENSION);
const contractIdentifier = `${fileName}:${contractName}`;
const abi: Web3.ContractAbi = JSON.parse(compiled.contracts[contractIdentifier].interface);
- const unlinked_binary = `0x${compiled.contracts[contractIdentifier].bytecode}`;
+ const bytecode = `0x${compiled.contracts[contractIdentifier].bytecode}`;
+ const runtimeBytecode = `0x${compiled.contracts[contractIdentifier].runtimeBytecode}`;
+ const sourceMap = compiled.contracts[contractIdentifier].srcmap;
+ const sourceMapRuntime = compiled.contracts[contractIdentifier].srcmapRuntime;
+ const sources = _.keys(compiled.sources);
const updated_at = Date.now();
const contractNetworkData: ContractNetworkData = {
solc_version: contractSpecificSourceData.solcVersion,
@@ -222,8 +237,12 @@ export class Compiler {
source_tree_hash: sourceTreeHash,
optimizer_enabled: this._optimizerEnabled,
abi,
- unlinked_binary,
+ bytecode,
+ runtime_bytecode: runtimeBytecode,
updated_at,
+ source_map: sourceMap,
+ source_map_runtime: sourceMapRuntime,
+ sources,
};
let newArtifact: ContractArtifact;
@@ -284,13 +303,13 @@ export class Compiler {
* @param importPath Path to an imported dependency.
* @return Import contents object containing source code of dependency.
*/
- private _findImportsIfSourcesExist(importPath: string): ImportContents {
+ private _findImportsIfSourcesExist(importPath: string): solc.ImportContents {
const fileName = path.basename(importPath);
const source = this._contractSources[fileName];
if (_.isUndefined(source)) {
throw new Error(`Contract source not found for ${fileName}`);
}
- const importContents: ImportContents = {
+ const importContents: solc.ImportContents = {
contents: source,
};
return importContents;