SolcUtil

SolcUtil

Utility class to hold solc-related operations.

Constructor

new SolcUtil(logSetting)

Source:

Initialize a SolcUtil instance.

Parameters:
Name Type Description
logSetting Logger.state.ENUM

Log setting, as represented by the Logger state enum.

Methods

findExtInDir(root, ext) → {Array.<string>}

Source:

Recursively looks for files within a given root filepath passed of a particular extension (e.g. .sol).

Parameters:
Name Type Description
root string

Root filepath to search within

ext string

File extension

Returns:

results - String array of all filenames which satisfied the constraints, as absolute filepaths.

Type
Array.<string>

findFilesInDir(root, condition) → {Array.<string>}

Source:

Recursively looks for files within a given root filepath passed, using the "condition" function passed in to determine whether to include it in the results.

Parameters:
Name Type Description
root string

Root filepath to search within

condition function

A function whose return value dictates whether or not a file is included in the results. The general format of the input function is:

function(filename){ return isValid; } or (filename) => return isValid;

Returns:

results - String array of all filenames which satisfied the constraints, as absolute filepaths.

Type
Array.<string>

findSolInDir(root) → {Array.<string>}

Source:

Recursively looks for files with the .sol extension within the root filepath passed.

Parameters:
Name Type Description
root string

Root filepath to search within

Returns:

results - String array of all filenames ending in ".sol", as absolute filepaths.

Type
Array.<string>

generateSolcInput(base, src) → {JSON}

Source:

Generate input object, assuming Solidity as language, a raw contract source file (singular contract) as a string.

Parameters:
Name Type Description
base string

"base" is the "solc filename" we use in generating the solcInput; needs a better name, essentially think of it as the output of toSolcFilename() (function above).

src string

Raw Solidity source code.

Returns:

input - solc input generated.

Type
JSON

generateSolcInputDirectory(root) → {JSON}

Source:

Generate input object, assuming Solidity as language, from root filepath of sources. This function will search for all .sol files in the root directory, and attach them to the solc input as specified in the solc documentation.

Parameters:
Name Type Description
root string

Root filepath to search within

Returns:

input - solc input including all .sol files found.

Type
JSON

generateSolcInputFile(filepath, root) → {JSON}

Source:

Generate input object, assuming Solidity as language, a singular .sol file.

Parameters:
Name Type Description
filepath string

.sol filepath

root string

String of the root to utilize in conversion of the solc filename. For more information, see the function "toSolcFilename".

Returns:

input - solc input generated.

Type
JSON

toSolcFilename(filepath, root) → {string}

Source:

Converts an absolute regular .sol filepath into one to be input to the compiler. Essentially returns a kind of "relative filepath" removing the root from the .sol filepath passed.

Parameters:
Name Type Description
filepath string

String of the filepath to convert to a solc filename. (e.g. "/home/luiserebii/github/solidity-math/Calculator.sol")

root string

String of the root to utilize in conversion of the solc filename.

Returns:

solcFilename

Type
string