solitude.common module

class solitude.common.FileMessage

Bases: tuple

message (error, warning) related to a text file


column number, optional


line number, optional


the message string


a string indicating the message type


source unit name or file name

solitude.common.file_message_format(m: solitude.common.structures.FileMessage)[source]

Format a FileMessage object to string

class solitude.common.TransactionInfo

Bases: tuple

Transaction information


contract instance address


contract name


function arguments as tuple


function name


full web3 receipt


transaction arguments as dictionary (‘gas’, ‘gasprice’, ‘value’)


Alias for field number 6


source unit name

solitude.common.hex_repr(b: bytes, pad: Optional[int] = None, prefix=True)[source]

Get hex string representation of a byte array

  • b – byte array
  • pad – pad to fixed number of characters
  • prefix – prefix with ‘0x’
solitude.common.get_resource_path(resource_name: str)[source]

Get location of a solitude resource file in the filesystem

Parameters:resource_name – name of the resource
Returns:resource file path

Get the solitude global configuration, containing global settings of the solitude framework.

Returns:the solitude global config
solitude.common.update_global_config(config: dict)[source]

Update the solitude global configuration from a dictionary

Parameters:config – dictionary containing the values to replace
solitude.common.copy_from_url(url: str, destination, decode=False)[source]

Copy file from URL to file-like

  • url – source URL (see open_url())
  • destination – destination writable file-like
  • decode – interpret the stream as utf-8 text and convert it to string
solitude.common.read_from_url(url: str, decode=False)[source]

Read file from URL to a byte array or string

  • url – source URL (see open_url())
  • decode – interpret the stream as utf-8 text and convert it to string

a byte array (bytes) if decode is False, otherwise a string (str)

solitude.common.open_url(url: str, decode=False)[source]

Open URL and return readable file-like

The URL can have one of the following schemas

  • https://{hostname}/{path} - HTTPS url
  • http://{hostname}/{path} - HTTP url
  • resource://{name} - solitude resource, by name
  • file://{path} file on the filesystem, by path
  • url – source URL
  • decode – interpret the stream as utf-8 text and convert it to string

a file-like object, binary if decode is False, otherwise text

solitude.common.read_config_file(url: str) → dict[source]

Read a solitude configuration from YAML or JSON.

Parameters:url – URL or path of configuration; if url ends with ‘.yaml’, the configuration file is interpreted as YAML, otherwise it is assumed to be JSON.
Returns:configuration dictionary
solitude.common.read_yaml_or_json(url: str) → dict[source]

Read a YAML or JSON document.

Parameters:url – URL or path; if url ends with ‘.yaml’, the document is interpreted as YAML, otherwise it is assumed to be JSON.
Returns:a dictionary with the document contents.
solitude.common.make_default_config() → dict[source]

Create a default solitude configuration.

Returns:a configuration dictionary
class solitude.common.ContractObjectList[source]

Bases: object

A collection of compiled contracts


Create an empty collection of compiled contracts

add_contract(unitname: str, contractname: str, contract: dict)[source]

Add a contract, uniquely identified by (unitname, contractname).

  • unitname – source unit containing the contract
  • contractname – name of the contract
  • contract – contract data dictionary, as produced by the compiler module
add_directory(path: str) → None[source]

Add all contracts from a directory.

Parameters:path – path of the directory containing the contracts data.

All contracts, as a dictionary of (unitname, contractname) -> data

find(suffix: Optional[str], contractname: str) → List[Tuple[str, str]][source]

Find contracts by unitname suffix and full contractname.

Example: (“erc20/ERC20.sol”, “ERC20”) matches (“/home/user/contracts/erc20/ERC20.sol”, “ERC20”).

  • suffix – suffix to match the contract source unit name, or None; if it is None, any unit name is matched.
  • contractname – full name of the contract
save_directory(path: str) → None[source]

Save all contracts to a directory.

Parameters:path – path of destination directory; the directory must exist.
select(selector: str) → dict[source]

Find a single contract matching the contract selector string.

The selector string is a string in either of the following forms:

  • “{suffix}:{contractname}”: source unit name suffix and contract name,
    separated by ‘:’. Example: “erc20/ERC20.sol:ERC20” matches contract named “ERC20” in source unit “/home/user/contracts/erc20/ERC20.sol”.
  • “{contractname}”: only the contract name. Example: “ERC20” matches
    contract named “ERC20”.

If the selector matches multiple contract, this function will raise an exception of type ValueError.

Parameters:selector – contract selector
update(other: solitude.common.contract_objectlist.ContractObjectList) → None[source]

Add all contracts from other ContractObjectList.

Parameters:other – other ContractObjectList with contracts to add
class solitude.common.ContractSourceList[source]

Bases: object

A collection of contract sources


Create an empty collection of contract sources

add_directory(path: str, ext_filter: Optional[List[str]] = ['.sol']) → None[source]

Add all sources from a directory.

  • path – directory path
  • ext_filter – list of allowed extensions for the source file names, including the ‘.’ character (e.g. [“.sol”]), or None for any extension
add_file(path: str) → None[source]

Add file to the list of sources.

Parameters:path – file path
add_files(sources: List[str]) → None[source]

Add list of files to the list of sources.

Parameters:sources – list of file paths
add_string(unitname: str, source: str) → None[source]

Add a source string to the list of sources

  • unitname – a name for the provided source unit
  • source – source code text

All added file sources as list of paths


All added source strings as dictionary of unitname -> source.

solitude.common.path_to_unitname(path: str) → str[source]

Create a source unit name from a path

Parameters:path – source file path
Returns:the corresponding normalized source unit name
class solitude.common.Dump(filename: str = None, fileobj=None, prefix: str = None)[source]

Bases: object

FLUSH = 1000
__init__(filename: str = None, fileobj=None, prefix: str = None)[source]

Initialize self. See help(type(self)) for accurate signature.

raw(msg, *args)[source]
write(msg, *args)[source]
class solitude.common.RPCClient(endpoint: str)[source]

Bases: object

Communicate with a JSON-RPC server

Any method can be called by RPCClient.rpcFunctionName(arguments…)

__init__(endpoint: str)[source]
Parameters:endpoint – JSON-RPC server URL
batch_call(functions: List[Tuple[str, list]])[source]

Perform a batch call

Parameters:function – list of the requests to perform in batch, as tuples of (method name, list of arguments)
Returns:the list of responses from the server