Пример #1
0
def map_dict(
    key_func: typing.Callable,
    value_func: typing.Callable,
    dict: typing.Dict,
) -> typing.Dict[str, typing.Any]:
    return {
        key_func(k): value_func(v)
        for k, v in dict.items()
    }
Пример #2
0
def geth_to_cmd(
    node: typing.Dict,
    datadir: str,
    chain_id: int,
    verbosity: int,
) -> typing.List[str]:
    """
    Transform a node configuration into a cmd-args list for `subprocess.Popen`.

    Args:
        node: a node configuration
        datadir: the node's datadir
        verbosity: geth structlog verbosity, 0 - nothing, 5 - max

    Return:
        cmd-args list
    """
    node_config = [
        'nodekeyhex',
        'port',
        'rpcport',
        'bootnodes',
        'minerthreads',
        'unlock',
        'password',
    ]

    cmd = ['geth']

    for config in node_config:
        if config in node:
            value = node[config]
            cmd.extend([f'--{config}', str(value)])

    # dont use the '--dev' flag
    cmd.extend([
        '--nodiscover',
        '--rpc',
        '--rpcapi',
        'eth,net,web3,personal,txpool',
        '--rpcaddr',
        '0.0.0.0',
        '--networkid',
        str(chain_id),
        '--verbosity',
        str(verbosity),
        '--datadir',
        datadir,
    ])

    if node.get('mine', False):
        cmd.append('--mine')

    log.debug('geth command', command=cmd)

    return cmd
Пример #3
0
def geth_to_cmd(
        node: typing.Dict,
        datadir: str,
        chain_id: int,
        verbosity: int,
) -> typing.List[str]:
    """
    Transform a node configuration into a cmd-args list for `subprocess.Popen`.

    Args:
        node: a node configuration
        datadir: the node's datadir
        verbosity: geth structlog verbosity, 0 - nothing, 5 - max

    Return:
        cmd-args list
    """
    node_config = [
        'nodekeyhex',
        'port',
        'rpcport',
        'bootnodes',
        'minerthreads',
        'unlock',
        'password',
    ]

    cmd = ['geth']

    for config in node_config:
        if config in node:
            value = node[config]
            cmd.extend([f'--{config}', str(value)])

    # dont use the '--dev' flag
    cmd.extend([
        '--nodiscover',
        '--rpc',
        '--rpcapi', 'eth,net,web3',
        '--rpcaddr', '0.0.0.0',
        '--networkid', str(chain_id),
        '--verbosity', str(verbosity),
        '--datadir', datadir,
    ])

    if node.get('mine', False):
        cmd.append('--mine')

    log.debug('geth command: {}'.format(cmd))

    return cmd
Пример #4
0
def _dict_to_kwargs(properties_dict: typing.Dict) -> typing.Dict:
    return {
        key: _create_or_echo(value)
        for key, value in properties_dict.items()
    }
Пример #5
0
def _dict_to_kwargs(properties_dict: typing.Dict) -> typing.Dict:
    return {key: _create_or_echo(value) for key, value in properties_dict.items()}
Пример #6
0
def deserialize_queueid_to_queue(data: typing.Dict):
    return {queue_id: queue for queue_id, queue in data.values()}
Пример #7
0
def serialize_queueid_to_queue(data: typing.Dict):
    # QueueId cannot be the key in a JSON dict, so make it a str
    return {
        str(queue_id): (queue_id, queue)
        for queue_id, queue in data.items()
    }