Beispiel #1
0
def find_project_contracts(project_dir):
    contracts_dir = get_contracts_dir(project_dir)
    # TODO: support non-solidity based contract compilation.
    solidity_glob = os.path.join(contracts_dir, "*.sol")
    serpent_glob = os.path.join(contracts_dir, "*.se")
    lll_glob = os.path.join(contracts_dir, "*.lll")
    mutan_glob = os.path.join(contracts_dir, "*.mutan")

    return tuple(
        itertools.chain(glob.glob(solidity_glob), glob.glob(serpent_glob), glob.glob(lll_glob), glob.glob(mutan_glob))
    )
Beispiel #2
0
def find_project_contracts(project_dir):
    contracts_dir = get_contracts_dir(project_dir)
    # TODO: support non-solidity based contract compilation.
    solidity_glob = os.path.join(contracts_dir, "*.sol")
    serpent_glob = os.path.join(contracts_dir, "*.se")
    lll_glob = os.path.join(contracts_dir, "*.lll")
    mutan_glob = os.path.join(contracts_dir, "*.mutan")

    return tuple(itertools.chain(
        glob.glob(solidity_glob),
        glob.glob(serpent_glob),
        glob.glob(lll_glob),
        glob.glob(mutan_glob),
    ))
Beispiel #3
0
def compile_contracts(watch, contracts):
    """
    Compile project contracts, storing their output in `./build/contracts.json`

    Call bare to compile all contracts or specify contract names or file paths
    to restrict to only compiling those contracts.

    Pass in a file path and a contract name separated by a colon(":") to
    specify only named contracts in the specified file.
    """
    project_dir = os.getcwd()

    click.echo("============ Compiling ==============")
    click.echo("> Loading contracts from: {0}".format(
        get_contracts_dir(project_dir)))

    result = compile_and_write_contracts(project_dir, *contracts)
    contract_source_paths, compiled_sources, output_file_path = result

    click.echo("> Found {0} contract source files".format(
        len(contract_source_paths)))
    for path in contract_source_paths:
        click.echo("- {0}".format(os.path.basename(path)))
    click.echo("")
    click.echo("> Compiled {0} contracts".format(len(compiled_sources)))
    for contract_name in sorted(compiled_sources.keys()):
        click.echo("- {0}".format(contract_name))
    click.echo("")
    click.echo("> Outfile: {0}".format(output_file_path))

    if watch:
        # The path to watch
        watch_path = utils.get_contracts_dir(project_dir)

        click.echo("============ Watching ==============")

        event_handler = ContractChangedEventHandler(
            project_dir=project_dir,
            contract_filters=contracts,
        )
        observer = PollingObserver()
        observer.schedule(event_handler, watch_path, recursive=True)
        observer.start()
        try:
            while observer.is_alive():
                time.sleep(1)
        except KeyboardInterrupt:
            observer.stop()
        observer.join()
Beispiel #4
0
def get_contracts_observer(project_dir, contract_filters=None, compiler_kwargs=None):
    if contract_filters is None:
        contract_filters = []
    if compiler_kwargs is None:
        compiler_kwargs = {}
    contracts_dir = utils.get_contracts_dir(project_dir)
    libraries_dir = get_project_libraries_dir(project_dir)

    event_handler = ContractSourceChangedEventHandler(
        project_dir=project_dir, contract_filters=contract_filters, compiler_kwargs=compiler_kwargs
    )
    observer = PollingObserver()
    observer.schedule(event_handler, contracts_dir, recursive=True)
    observer.schedule(event_handler, libraries_dir, recursive=True)
    return observer
Beispiel #5
0
def get_contracts_observer(project_dir,
                           contract_filters=None,
                           compiler_kwargs=None):
    if contract_filters is None:
        contract_filters = []
    if compiler_kwargs is None:
        compiler_kwargs = {}
    contracts_dir = utils.get_contracts_dir(project_dir)
    libraries_dir = get_project_libraries_dir(project_dir)

    event_handler = ContractSourceChangedEventHandler(
        project_dir=project_dir,
        contract_filters=contract_filters,
        compiler_kwargs=compiler_kwargs,
    )
    observer = PollingObserver()
    observer.schedule(event_handler, contracts_dir, recursive=True)
    if os.path.exists(libraries_dir):
        observer.schedule(event_handler, libraries_dir, recursive=True)
    return observer