Add flag for saving standard input during compilation

This commit is contained in:
Amir Bandeali
2019-10-29 17:29:04 -07:00
parent 48436424db
commit bd9e531257
3 changed files with 14 additions and 1 deletions

View File

@@ -725,6 +725,7 @@ export interface Source {
* isOfflineMode: If set to true - sol-compiler will not fetch the list of solc releases from github. It will use the hardcoded list. Defaults to false.
* solcVersion: If you don't want to compile each contract with the Solidity version specified in-file, you can force all
* contracts to compile with the the version specified here.
* shouldSaveStandardInput: Write the standard JSON input in ${contractsDir}/${contractName}.input.json
*/
export interface CompilerOptions {
contractsDir?: string;
@@ -734,6 +735,7 @@ export interface CompilerOptions {
useDockerisedSolc?: boolean;
isOfflineMode?: boolean;
solcVersion?: string;
shouldSaveStandardInput?: boolean;
}
export interface BlockRange {

View File

@@ -49,6 +49,8 @@ const DEFAULT_CONTRACTS_DIR = path.resolve('contracts');
const DEFAULT_ARTIFACTS_DIR = path.resolve('artifacts');
const DEFAULT_USE_DOCKERISED_SOLC = false;
const DEFAULT_IS_OFFLINE_MODE = false;
const DEFAULT_SHOULD_SAVE_STANDARD_INPUT = false;
// Solc compiler settings cannot be configured from the commandline.
// If you need this configured, please create a `compiler.json` config file
// with your desired configurations.
@@ -95,6 +97,7 @@ export class Compiler {
private readonly _specifiedContracts: string[] | TYPE_ALL_FILES_IDENTIFIER;
private readonly _useDockerisedSolc: boolean;
private readonly _isOfflineMode: boolean;
private readonly _shouldSaveStandardInput: boolean;
/**
* Instantiates a new instance of the Compiler class.
* @param opts Optional compiler options
@@ -123,6 +126,8 @@ export class Compiler {
this._useDockerisedSolc =
passedOpts.useDockerisedSolc || config.useDockerisedSolc || DEFAULT_USE_DOCKERISED_SOLC;
this._isOfflineMode = passedOpts.isOfflineMode || config.isOfflineMode || DEFAULT_IS_OFFLINE_MODE;
this._shouldSaveStandardInput =
passedOpts.shouldSaveStandardInput || config.shouldSaveStandardInput || DEFAULT_SHOULD_SAVE_STANDARD_INPUT;
this._nameResolver = new NameResolver(this._contractsDir);
const resolver = new FallthroughResolver();
resolver.appendResolver(new URLResolver());
@@ -327,7 +332,12 @@ export class Compiler {
`Contract ${contractName} not found in ${contractPath}. Please make sure your contract has the same name as it's file name`,
);
}
if (this._shouldSaveStandardInput) {
await fsWrapper.writeFileAsync(
`${this._contractsDir}/${contractName}.input.json`,
utils.stringifyWithFormatting(input.standardInput),
);
}
addHexPrefixToContractBytecode(compiledContract);
if (shouldPersist) {

View File

@@ -21,6 +21,7 @@ export const compilerOptionsSchema = {
},
useDockerisedSolc: { type: 'boolean' },
isOfflineMode: { type: 'boolean' },
shouldSaveStandardInput: { type: 'boolean' },
},
type: 'object',
required: [],