Ejemplo n.º 1
0
filter_params_formatter = apply_formatters_to_dict(FILTER_PARAMS_FORMATTERS)


filter_result_formatter = apply_one_of_formatters((
    (apply_formatter_to_array(log_entry_formatter), is_array_of_dicts),
    (apply_formatter_to_array(to_hexbytes(32)), is_array_of_strings),
))

TRANSACTION_PARAM_FORMATTERS = {
    'chainId': apply_formatter_if(is_integer, str),
}


transaction_param_formatter = compose(
    remove_key_if('to', lambda txn: txn['to'] in {'', b'', None}),
    apply_formatters_to_dict(TRANSACTION_PARAM_FORMATTERS),
)


pythonic_middleware = construct_formatting_middleware(
    request_formatters={
        # Platon
        'platon_getBalance': apply_formatter_at_index(block_number_formatter, 1),
        'platon_getBlockByNumber': apply_formatter_at_index(block_number_formatter, 0),
        'platon_getBlockTransactionCountByNumber': apply_formatter_at_index(
            block_number_formatter,
            0,
        ),
        'platon_getCode': apply_formatter_at_index(block_number_formatter, 1),
        'platon_getStorageAt': apply_formatter_at_index(block_number_formatter, 2),
Ejemplo n.º 2
0
TRANSACTION_PARAMS_MAPPING = {
    'gasPrice': 'gas_price',
}

transaction_params_remapper = apply_key_map(TRANSACTION_PARAMS_MAPPING)

TRANSACTION_PARAMS_FORMATTERS = {
    'gas': to_integer_if_hex,
    'gasPrice': to_integer_if_hex,
    'value': to_integer_if_hex,
    # 'nonce': to_integer_if_hex,
}

transaction_params_formatter = compose(
    # remove nonce for now due to issue https://github.com/ethereum/eth-tester/issues/80
    remove_key_if('nonce', lambda _: True),
    apply_formatters_to_dict(TRANSACTION_PARAMS_FORMATTERS),
)

FILTER_PARAMS_MAPPINGS = {
    'fromBlock': 'from_block',
    'toBlock': 'to_block',
}

filter_params_remapper = apply_key_map(FILTER_PARAMS_MAPPINGS)

FILTER_PARAMS_FORMATTERS = {
    'fromBlock': to_integer_if_hex,
    'toBlock': to_integer_if_hex,
}