Module utils

Source
Expand description

Utility functions

Enums§

RuntimeOrHandleNon-WebAssembly

Statics§

RE_SOL_IMPORT
A regex that matches the import path and identifier of a solidity import statement with the named groups “path”, “id”.
RE_SOL_IMPORT_ALIAS
A regex that matches an alias within an import statement
RE_SOL_PRAGMA_VERSION
A regex that matches the version part of a solidity pragma as follows: pragma solidity ^0.5.2; => ^0.5.2 statement with the named group “version”.
RE_SOL_SDPX_LICENSE_IDENTIFIER
A regex that matches the SDPX license identifier statement with the named group “license”.
RE_THREE_OR_MORE_NEWLINES
A regex used to remove extra lines in flatenned files

Functions§

canonicalize
Canonicalize the path, platform-agnostic
canonicalized
Returns the same path config but with canonicalized paths.
common_ancestor
Finds the common ancestor of both paths
common_ancestor_all
Find the common ancestor, if any, between the given paths
create_contract_or_lib_name_regex
Create a regex that matches any library or contract name inside a file
create_parent_dir_all
Creates the parent directory of the file and all its ancestors if it does not exist See std::fs::create_dir_all()
find_import_paths
Returns all path parts from any solidity import statement in a string, import "./contracts/Contract.sol"; -> "./contracts/Contract.sol".
find_version_pragma
Returns the solidity version pragma from the given input: pragma solidity ^0.5.2; => ^0.5.2
installed_versions
Reads the list of Solc versions that have been installed in the machine. The version list is sorted in ascending order. Checks for installed solc versions under the given path as <root>/<major.minor.path>, (e.g.: ~/.svm/0.8.10) and returns them sorted in ascending order
is_local_source_name
Attempts to determine if the given source is a local, relative import
library_fully_qualified_placeholder
Returns the 36 char (deprecated) fully qualified name placeholder
library_hash
Returns the library placeholder for the given name The placeholder is a 34 character prefix of the hex encoding of the keccak256 hash of the fully qualified library name.
library_hash_placeholder
Returns the library hash placeholder as $hex(library_hash(name))$
range_by_offset
Move a range by a specified offset
read_json_file
Reads the json file and deserialize it into the provided type
resolve_absolute_library
Tries to find an absolute import like src/interfaces/IConfig.sol in cwd, moving up the path until the root is reached.
resolve_library
Returns the path to the library if the source path is in fact determined to be a library path, and it exists. Note: this does not handle relative imports or remappings.
solidity_dirs
Returns a list of unique paths to all folders under root that contain at least one solidity file (*.sol).
source_files
Returns a list of absolute paths to all the solidity files under the root, or the file itself, if the path is a solidity file.
source_files_iter
Returns an iterator that yields all solidity/yul files funder under the given root path or the root itself, if it is a sol/yul file
source_name
Returns the source name for the given source path, the ancestors of the root path /Users/project/sources/contract.sol -> sources/contracts.sol