Beispiel #1
0
def run_ligo_container(
    tag: str = '0.13.0',
    command: str = '',
    files_to_add: List[str] = [],
):
    try:
        client = get_docker_client()
        container = client.containers.create(
            image=f'ligolang/ligo:{tag}',
            command=command,
            detach=True,
        )
        buffer = io.BytesIO()
        with tarfile.open(fileobj=buffer, mode='w:gz') as archive:
            for filename in files_to_add:
                with open(filename, 'rb') as current_file:
                    current_file_data = current_file.read()
                    current_file_buffer = io.BytesIO(
                        initial_bytes=current_file_data)
                    _, short_filename = split(filename)
                    archive.add(filename, arcname=short_filename)
        buffer.seek(0)
        container.put_archive(
            '/root/',
            buffer,
        )
        container.start()
        return container
    except docker.errors.ImageNotFound:
        logger.error('Ligo compiler not found. Please run update-ligo first.')
Beispiel #2
0
def run_smartpy_container(
    tag: str = 'latest',
    command: str = '',
    files_to_add: List[str] = [],
    mounts: List[docker.types.Mount] = [],
):
    try:
        client = get_docker_client()
        container = client.containers.create(
            image=f'{SMARTPY_CLI_IMAGE}:{tag}',
            command=command,
            detach=True,
            mounts=mounts,
        )
        buffer = io.BytesIO()
        with tarfile.open(fileobj=buffer, mode='w:gz') as archive:
            for filename in files_to_add:
                with open(filename, 'rb') as current_file:
                    current_file_data = current_file.read()
                    current_file_buffer = io.BytesIO(
                        initial_bytes=current_file_data)
                    _, short_filename = split(filename)
                    archive.add(filename, arcname=short_filename)
        buffer.seek(0)
        container.put_archive(
            '/root/smartpy-cli/',
            buffer,
        )
        container.start()
        return container
    except docker.errors.ImageNotFound:
        logger.error(
            'SmartPy compiler not found. Please run update-smartpy first.')
Beispiel #3
0
def smartpy_compile(
    _ctx,
    script: str,
    output_directory: str,
    detach: bool,
    protocol: str,
    tag: str,
):
    client = get_docker_client()
    path = get_local_contract_path(script, extension='py')
    if path:
        _, script_name = split(path)
        container = run_smartpy_container(
            tag=tag,
            command=
            f'compile /root/smartpy-cli/{script_name} /root/output --protocol {protocol}',
            files_to_add=[
                path,
            ],
            mounts=[
                docker.types.Mount(target='/root/output',
                                   source=output_directory,
                                   type='bind')
            ])
        if container is None:
            raise Exception(
                'Could not create container. Try running update-smartpy.')
        if not detach:
            for line in container.logs(stream=True):
                print(line.decode('utf-8').rstrip())
    else:
        logger.error(
            'No local script found. Please ensure a valid script is present or specify path.'
        )
Beispiel #4
0
def ligo_invoke_contract(
    _ctx,
    tag: str,
    path: str,
    entry_point: str,
    expression: str,
    detach: bool,
):
    path = get_local_contract_path(path, extension='ligo')
    if path:
        container = run_ligo_container(
            tag=tag,
            command=f'compile-parameter {path} "{entry_point}" "{expression}"',
            files_to_add=[path,],
        )
        if not detach:
            for line in container.logs(stream=True):
                print(line.decode('utf-8').rstrip())
    else:
        logger.error('No local contract found. Please ensure a valid contract is present or specify path.')