Beispiel #1
0
from eth_utils.curried import (
    apply_formatters_to_dict,
    apply_key_map,
)
from hexbytes import (
    HexBytes, )

from web3._utils.toolz import (
    compose, )
from web3.middleware.formatting import (
    construct_formatting_middleware, )

remap_geth_poa_fields = apply_key_map({
    'extraData': 'proofOfAuthorityData',
})

pythonic_geth_poa = apply_formatters_to_dict({
    'proofOfAuthorityData': HexBytes,
})

geth_poa_cleanup = compose(pythonic_geth_poa, remap_geth_poa_fields)

geth_poa_middleware = construct_formatting_middleware(result_formatters={
    'eth_getBlockByHash':
    geth_poa_cleanup,
    'eth_getBlockByNumber':
    geth_poa_cleanup,
}, )
Beispiel #2
0
from web3._utils.normalizers import (
    abi_address_to_hex,
    abi_bytes_to_hex,
    abi_int_to_hex,
    abi_string_to_hex,
)
from web3._utils.rpc_abi import (
    abi_request_formatters, )

from helios_web3.utils.rpc_abi import RPC_ABIS

from web3.middleware.formatting import (
    construct_formatting_middleware, )

STANDARD_NORMALIZERS = [
    abi_bytes_to_hex,
    abi_int_to_hex,
    abi_string_to_hex,
    abi_address_to_hex,
]

RPC_ABIS['personal_importRawKey'] = ['bytes', None]

abi_middleware = construct_formatting_middleware(
    request_formatters=abi_request_formatters(STANDARD_NORMALIZERS, RPC_ABIS))
Beispiel #3
0
from eth_utils.curried import (  # type: ignore
    apply_formatters_to_dict, apply_key_map,
)
from eth_utils.toolz import (
    compose, )
from hexbytes import (
    HexBytes, )

from web3.middleware.formatting import (
    construct_formatting_middleware, )
from web3.types import (
    RPCEndpoint, )

remap_geth_poa_fields = apply_key_map({
    'extraData': 'proofOfAuthorityData',
})

pythonic_geth_poa = apply_formatters_to_dict({
    'proofOfAuthorityData': HexBytes,
})

geth_poa_cleanup = compose(pythonic_geth_poa, remap_geth_poa_fields)

geth_poa_middleware = construct_formatting_middleware(result_formatters={
    RPCEndpoint("eth_getBlockByHash"):
    geth_poa_cleanup,
    RPCEndpoint("eth_getBlockByNumber"):
    geth_poa_cleanup,
}, )
Beispiel #4
0
is_not_null = complement(is_null)

remap_geth_poa_fields = apply_key_map({
    'extraData': 'proofOfAuthorityData',
})

pythonic_geth_poa = apply_formatters_to_dict({
    'proofOfAuthorityData': HexBytes,
})

geth_poa_cleanup = compose(pythonic_geth_poa, remap_geth_poa_fields)


geth_poa_middleware = construct_formatting_middleware(
    result_formatters={
        RPC.eth_getBlockByHash: apply_formatter_if(is_not_null, geth_poa_cleanup),
        RPC.eth_getBlockByNumber: apply_formatter_if(is_not_null, geth_poa_cleanup),
    },
)


async def async_geth_poa_middleware(
    make_request: Callable[[RPCEndpoint, Any], Any], w3: "Web3"
) -> AsyncMiddleware:
    middleware = await async_construct_formatting_middleware(
        result_formatters={
            RPC.eth_getBlockByHash: apply_formatter_if(is_not_null, geth_poa_cleanup),
            RPC.eth_getBlockByNumber: apply_formatter_if(is_not_null, geth_poa_cleanup),
        },
    )
    return await middleware(make_request, w3)
Beispiel #5
0
    apply_formatters_to_dict,
    apply_key_map,
)
from hexbytes import (
    HexBytes,
)

from web3._utils.toolz import (
    compose,
)
from web3.middleware.formatting import (
    construct_formatting_middleware,
)

remap_geth_poa_fields = apply_key_map({
    'extraData': 'proofOfAuthorityData',
})

pythonic_geth_poa = apply_formatters_to_dict({
    'proofOfAuthorityData': HexBytes,
})

geth_poa_cleanup = compose(pythonic_geth_poa, remap_geth_poa_fields)

geth_poa_middleware = construct_formatting_middleware(
    result_formatters={
        'eth_getBlockByHash': geth_poa_cleanup,
        'eth_getBlockByNumber': geth_poa_cleanup,
    },
)
from web3._utils.method_formatters import (
    PYTHONIC_REQUEST_FORMATTERS,
    PYTHONIC_RESULT_FORMATTERS,
)
from web3.middleware.formatting import (
    construct_formatting_middleware, )

pythonic_middleware = construct_formatting_middleware(
    request_formatters=PYTHONIC_REQUEST_FORMATTERS,
    result_formatters=PYTHONIC_RESULT_FORMATTERS,
)
pythonic_middleware = construct_formatting_middleware(
    request_formatters={
        # Hls
        'hls_getBlockCreationParams':
        compose(apply_formatter_at_index(to_hex_if_bytes, 0), ),
        'hls_getBalance':
        apply_formatter_at_index(block_number_formatter, 1),
        'hls_getBlockTransactionCountByNumber':
        apply_formatter_at_index(
            block_number_formatter,
            0,
        ),
        'hls_getReceivableTransactions':
        apply_formatter_at_index(to_hex_if_bytes, 0),
        'hls_getCode':
        apply_formatter_at_index(block_number_formatter, 1),
        'hls_getStorageAt':
        apply_formatter_at_index(block_number_formatter, 2),
        'hls_getTransactionCount':
        apply_formatter_at_index(block_number_formatter, 1),
        'hls_getBlockByNumber':
        compose(
            apply_formatter_at_index(block_number_formatter, 0),
            apply_formatter_at_index(to_hex_if_bytes, 1),
        ),
        'hls_getTransactionReceipt':
        apply_formatter_at_index(to_hex_if_bytes, 0),
        'hls_call':
        compose(
            apply_formatter_at_index(transaction_param_formatter, 0),
            apply_formatter_at_index(block_number_formatter, 1),
        ),
    },
    result_formatters={
        # Hls
        'hls_blockNumber':
        to_integer_if_hex,
        'hls_gasPrice':
        to_integer_if_hex,
        'hls_getGasPrice':
        to_integer_if_hex,
        'hls_getBalance':
        to_integer_if_hex,
        'hls_getBlockTransactionCountByHash':
        to_integer_if_hex,
        'hls_getBlockTransactionCountByNumber':
        to_integer_if_hex,
        'hls_getCode':
        HexBytes,
        'hls_getStorageAt':
        HexBytes,
        'hls_getTransactionByBlockHashAndIndex':
        apply_formatter_if(
            is_not_null,
            transaction_formatter,
        ),
        'hls_getTransactionByBlockNumberAndIndex':
        apply_formatter_if(
            is_not_null,
            transaction_formatter,
        ),
        'hls_getTransactionReceipt':
        apply_formatter_if(
            is_not_null,
            receipt_formatter,
        ),
        'hls_getTransactionCount':
        to_integer_if_hex,
        'hls_protocolVersion':
        compose(
            apply_formatter_if(is_integer, str),
            to_integer_if_hex,
        ),
        'hls_getTransactionByHash':
        apply_formatter_if(is_not_null, transaction_formatter),
        'hls_getReceivableTransactions':
        apply_formatter_to_array(transaction_formatter),
        'hls_filterAddressesWithReceivableTransactions':
        apply_formatter_to_array(HexBytes),
        'hls_getReceiveTransactionOfSendTransaction':
        apply_formatter_if(is_not_null, transaction_formatter),
        'hls_getHistoricalGasPrice':
        apply_formatter_to_array(min_gas_price_formatter),
        'hls_getApproximateHistoricalNetworkTPCCapability':
        apply_formatter_to_array(min_gas_price_formatter),
        'hls_getApproximateHistoricalTPC':
        apply_formatter_to_array(min_gas_price_formatter),
        'hls_getBlockNumber':
        to_integer_if_hex,
        'hls_getBlockCreationParams':
        block_creation_parameters_formatter,
        'hls_getBlockByHash':
        apply_formatter_if(is_not_null, block_formatter),
        'hls_getBlockByNumber':
        apply_formatter_if(is_not_null, block_formatter),
        'hls_getConnectedNodes':
        apply_formatter_to_array(get_connected_nodes_formatter),
        'hls_call':
        HexBytes,
        # Net
        'net_peerCount':
        to_integer_if_hex,
    },
)