def is_testrpc_available(): try: import testrpc # noqa: F401 return True except ImportError: return False to_integer_if_hex = apply_formatter_if(is_string, hex_to_integer) TRANSACTION_FORMATTERS = { 'to': apply_formatter_if( compose(complement(bool), decode_hex), static_return(None), ), } def ethtestrpc_string_middleware(make_request, web3): def middleware(method, params): return force_obj_to_text(make_request(method, params)) return middleware ethtestrpc_middleware = construct_formatting_middleware( request_formatters={ 'eth_uninstallFilter': apply_formatter_at_index(to_integer_if_hex, 0), 'eth_getFilterChanges': apply_formatter_at_index(to_integer_if_hex, 0), 'eth_getFilterLogs': apply_formatter_at_index(to_integer_if_hex, 0),
} filter_params_remapper = apply_key_map(FILTER_PARAMS_MAPPINGS) FILTER_PARAMS_FORMATTERS = { 'fromBlock': to_integer_if_hex, 'toBlock': to_integer_if_hex, } filter_params_formatter = apply_formatters_to_dict(FILTER_PARAMS_FORMATTERS) filter_params_transformer = compose(filter_params_remapper, filter_params_formatter) TRANSACTION_FORMATTERS = { 'to': apply_formatter_if(partial(operator.eq, ''), static_return(None)), } transaction_formatter = apply_formatters_to_dict(TRANSACTION_FORMATTERS) RECEIPT_FORMATTERS = { 'logs': apply_formatter_to_array(log_key_remapper), } receipt_formatter = apply_formatters_to_dict(RECEIPT_FORMATTERS) transaction_params_transformer = compose(transaction_params_remapper, transaction_params_formatter) ethereum_tester_middleware = construct_formatting_middleware( request_formatters={
def is_testrpc_available(): try: import testrpc # noqa: F401 return True except ImportError: return False to_integer_if_hex = apply_formatter_if(is_string, hex_to_integer) TRANSACTION_FORMATTERS = { 'to': apply_formatter_if( compose(complement(bool), decode_hex), static_return(None), ), } def ethtestrpc_string_middleware(make_request, web3): def middleware(method, params): return force_obj_to_text(make_request(method, params)) return middleware ethtestrpc_middleware = construct_formatting_middleware( request_formatters={ 'eth_uninstallFilter': apply_formatter_at_index(to_integer_if_hex, 0), 'eth_getFilterChanges': apply_formatter_at_index(to_integer_if_hex, 0),
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, } transaction_params_formatter = apply_formatters_to_dict(TRANSACTION_PARAMS_FORMATTERS) TRANSACTION_FORMATTERS = { 'to': apply_formatter_if(static_return(None), partial(operator.eq, b'')), } transaction_formatter = apply_formatters_to_dict(TRANSACTION_FORMATTERS) ethereum_tester_middleware = construct_formatting_middleware( request_formatters={ # Eth 'eth_getBlockByNumber': apply_formatters_to_args( apply_formatter_if(to_integer_if_hex, is_not_named_block), ), 'eth_getFilterChanges': apply_formatters_to_args(hex_to_integer), 'eth_getFilterLogs': apply_formatters_to_args(hex_to_integer), 'eth_getBlockTransactionCountByNumber': apply_formatters_to_args(
} filter_params_remapper = apply_key_map(FILTER_PARAMS_MAPPINGS) FILTER_PARAMS_FORMATTERS = { 'fromBlock': to_integer_if_hex, 'toBlock': to_integer_if_hex, } filter_params_formatter = apply_formatters_to_dict(FILTER_PARAMS_FORMATTERS) filter_params_transformer = compose(filter_params_remapper, filter_params_formatter) TRANSACTION_FORMATTERS = { 'to': apply_formatter_if(partial(operator.eq, b''), static_return(None)), } transaction_formatter = apply_formatters_to_dict(TRANSACTION_FORMATTERS) RECEIPT_FORMATTERS = { 'logs': apply_formatter_to_array(log_key_remapper), } receipt_formatter = apply_formatters_to_dict(RECEIPT_FORMATTERS) transaction_params_transformer = compose(transaction_params_remapper, transaction_params_formatter)