예제 #1
0
def allcontracts(contract_files):
    return {
        "{}:{}".format(c, name_from_file(c)):
        compile_contract(get_contract_path(c),
                         name_from_file(c),
                         optimize=False)
        for c in contract_files
    }
예제 #2
0
파일: abi.py 프로젝트: Fedwallet/raiden
def validate_solc():
    import subprocess

    try:
        _solidity.compile_contract(
            get_contract_path('HumanStandardToken.sol'),
            'HumanStandardToken',
            combined='abi',
            optimize=False,
        )
    except subprocess.CalledProcessError as e:
        msg = (
            'The solidity compiler failed to execute. Please make sure that you\n'
            'are using the binary version of the compiler (solc-js is not compatible)\n'
        )

        if e.output:
            msg += ('\n' 'Output: ' + e.output)

        raise RuntimeError(msg)
예제 #3
0
파일: abi.py 프로젝트: zbww/raiden
def validate_solc():
    if _solidity.get_solidity() is None:
        raise RuntimeError(
            "Couldn't find the solc in the current $PATH.\n"
            "Make sure the solidity compiler is installed and available on your $PATH."
        )

    try:
        _solidity.compile_contract(
            get_contract_path('HumanStandardToken.sol'),
            'HumanStandardToken',
            combined='abi',
            optimize=False,
        )
    except subprocess.CalledProcessError as e:
        msg = (
            'The solidity compiler failed to execute. Please make sure that you\n'
            'are using the binary version of the compiler (solc-js is not compatible)\n'
        )

        if e.output:
            msg += ('\n' 'Output: ' + e.output)

        raise RuntimeError(msg)

    except OSError as e:
        msg = (
            'The solidity compiler failed to execute. Please make sure the\n'
            'binary is compatible with your architecture and you can execute it.'
        )

        child_traceback = getattr(e, 'child_traceback', None)
        if child_traceback:
            msg += ('\n' 'Traceback: ' + child_traceback)

        raise RuntimeError(msg)
예제 #4
0
파일: abi.py 프로젝트: maddee2145/raiden
def get_static_or_compile(
        contract_path,
        contract_name,
        **compiler_flags):
    """Search the path of `contract_path` for a file with the same name and the
    extension `.static-abi.json`. If the file exists, and the recorded checksum
    matches, this will return the precompiled contract, otherwise it will
    compile it.

    Writing compiled contracts to the desired file and path happens only when
    the environment variable `STORE_PRECOMPILED` is set (to whatever value).
    Users are not expected to ever set this value, the functionality is exposed
    through the `setup.py compile_contracts` command.

    Args:
        contract_path (str): the path of the contract file
        contract_name (str): the contract name
        **compiler_flags (dict): flags that will be passed to the compiler
    """
    # this will be set by `setup.py compile_contracts`
    store_updated = os.environ.get('STORE_PRECOMPILED', False)
    precompiled = None
    precompiled_path = '{}.static-abi.json'.format(contract_path)
    try:
        with open(precompiled_path) as f:
            precompiled = json.load(f)
    except IOError:
        pass

    if precompiled or store_updated:
        checksum = contract_checksum(contract_path)
    if precompiled and precompiled['checksum'] == checksum:
        return precompiled
    if _solidity.get_solidity() is None:
        raise RuntimeError('The solidity compiler, `solc`, is not available.')

    compiled = _solidity.compile_contract(
        contract_path,
        contract_name,
        **compiler_flags
    )

    if store_updated:
        compiled['checksum'] = checksum
        with open(precompiled_path, 'w') as f:
            json.dump(compiled, f)
        print("'{}' written".format(precompiled_path))
    return compiled
예제 #5
0
# -*- coding: utf-8 -*-
from ethereum import _solidity

from raiden.utils import (
    host_port_to_endpoint,
    isaddress,
    pex,
    split_endpoint,
    get_contract_path,
)
from raiden.network.rpc.client import DEFAULT_POLL_TIMEOUT

discovery_contract_compiled = _solidity.compile_contract(
    get_contract_path('EndpointRegistry.sol'),
    'EndpointRegistry',
    combined='abi',
)
DISCOVERY_CONTRACT_ABI = discovery_contract_compiled['abi']


class Discovery(object):
    """ Mock mapping address: host, port """

    def __init__(self):
        self.nodeid_hostport = dict()

    def register(self, nodeid, host, port):
        assert isaddress(nodeid)  # fixme, this is H(pubkey)
        self.nodeid_hostport[nodeid] = (host, port)

    def get(self, nodeid):
예제 #6
0
파일: abi.py 프로젝트: hdiedrich/raiden
            return description


def get_eventname_types(event_description):
    if 'name' not in event_description:
        raise ValueError('Not an event description, missing the name.')

    name = normalize_name(event_description['name'])
    encode_types = [element['type'] for element in event_description['inputs']]
    return name, encode_types


# pylint: disable=invalid-name
human_token_compiled = _solidity.compile_contract(
    get_contract_path('HumanStandardToken.sol'),
    'HumanStandardToken',
    combined='abi',
)

channel_manager_compiled = _solidity.compile_contract(
    get_contract_path('ChannelManagerContract.sol'),
    'ChannelManagerContract',
    combined='abi',
)

netting_channel_compiled = _solidity.compile_contract(
    get_contract_path('NettingChannelContract.sol'),
    'NettingChannelContract',
    combined='abi',
)
예제 #7
0
파일: prepare_gnt.py 프로젝트: 4000D/tokens
from __future__ import print_function
import json
import subprocess
from ethereum._solidity import compile_contract
from ethereum.abi import ContractTranslator

GOLEM_FACTORY = '0x7da82C7AB4771ff031b66538D2fB9b0B047f6CF9'
MIGRATION_MASTER = '0x7da82C7AB4771ff031b66538D2fB9b0B047f6CF9'
START_BLOCK = 2607800
END_BLOCK = 2734100

version_info = subprocess.check_output(['solc', '--version'])
print(version_info)

contract = compile_contract('contracts/Token.sol', 'GolemNetworkToken')

init = contract['bin_hex']
abi = contract['abi']

translator = ContractTranslator(abi)
args = translator.encode_constructor_arguments(
    (GOLEM_FACTORY, MIGRATION_MASTER, START_BLOCK, END_BLOCK)
).encode('hex')

print('\nGolem Network Token')
print('- Factory: ' + GOLEM_FACTORY)
print('- Migration Master: ' + MIGRATION_MASTER)
print('- Start: ', START_BLOCK)
print('- End: ', END_BLOCK)
print()
print('Deploy:')
예제 #8
0
파일: deploy.py 프로젝트: VidRoll/raiden
def allcontracts(contract_files):
    return {
        name_from_file(c): compile_contract(get_contract_path(c),
                                            name_from_file(c))
        for c in contract_files
    }
예제 #9
0
def get_eventname_types(event_description):
    if 'name' not in event_description:
        raise ValueError('Not an event description, missing the name.')

    name = normalize_name(event_description['name'])
    encode_types = [
        element['type']
        for element in event_description['inputs']
    ]
    return name, encode_types


# pylint: disable=invalid-name
human_token_compiled = _solidity.compile_contract(
    get_contract_path('HumanStandardToken.sol'),
    'HumanStandardToken',
    combined='abi',
)

channel_manager_compiled = _solidity.compile_contract(
    get_contract_path('ChannelManagerContract.sol'),
    'ChannelManagerContract',
    combined='abi',
)

endpoint_registry_compiled = _solidity.compile_contract(
    get_contract_path('EndpointRegistry.sol'),
    'EndpointRegistry',
    combined='abi',
)
예제 #10
0
def allcontracts(contract_files):
    return {
        name_from_file(c): compile_contract(
            get_contract_path(c),
            name_from_file(c)) for c in contract_files
    }