Exemplo n.º 1
0
def request_middleware(allowable_delay):
    middleware = make_stalecheck_middleware(allowable_delay)
    make_request, web3 = Mock(), Mock()
    initialized = middleware(make_request, web3)
    # for easier mocking, later:
    initialized.web3 = web3
    initialized.make_request = make_request
    return initialized
Exemplo n.º 2
0
def request_middleware(allowable_delay):
    middleware = make_stalecheck_middleware(allowable_delay)
    make_request, web3 = Mock(), Mock()
    initialized = middleware(make_request, web3)
    # for easier mocking, later:
    initialized.web3 = web3
    initialized.make_request = make_request
    return initialized
Exemplo n.º 3
0
def customize_web3(w3):
    from web3.middleware import make_stalecheck_middleware

    w3.middleware_onion.remove('name_to_address')
    w3.middleware_onion.add(
        make_stalecheck_middleware(ACCEPTABLE_STALE_HOURS * 3600),
        name='stalecheck',
    )
    return w3
Exemplo n.º 4
0
def init_web3(providers=None):
    if not providers:
        providers = [IPCProvider(), HTTPProvider('http://localhost:8545')]
    w3 = Web3(providers)
    w3.middleware_stack.add(
        make_stalecheck_middleware(ACCEPTABLE_STALE_HOURS * 3600),
        name='stalecheck'
    )
    w3.eth.setContractFactory(ConciseContract)
    return w3
Exemplo n.º 5
0
def customize_web3(w3):
    from web3.contract import ConciseContract
    from web3.middleware import make_stalecheck_middleware

    w3.middleware_onion.remove('name_to_address')
    w3.middleware_onion.add(
        make_stalecheck_middleware(ACCEPTABLE_STALE_HOURS * 3600),
        name='stalecheck',
    )
    w3.eth.setContractFactory(ConciseContract)
    return w3
Exemplo n.º 6
0
def customize_web3(w3):
    from web3.contract import ConciseContract
    from web3.middleware import make_stalecheck_middleware

    w3.middleware_stack.remove('name_to_address')
    w3.middleware_stack.add(
        make_stalecheck_middleware(ACCEPTABLE_STALE_HOURS * 3600),
        name='stalecheck',
    )
    w3.eth.setContractFactory(ConciseContract)
    return w3
Exemplo n.º 7
0
def customize_web3(w3: '_Web3') -> '_Web3':
    from web3.middleware import make_stalecheck_middleware

    if w3.middleware_onion.get('name_to_address'):
        w3.middleware_onion.remove('name_to_address')

    if not w3.middleware_onion.get('stalecheck'):
        w3.middleware_onion.add(make_stalecheck_middleware(
            ACCEPTABLE_STALE_HOURS * 3600),
                                name='stalecheck')

    return w3
Exemplo n.º 8
0
Arquivo: utils.py Projeto: voBits/web3
def init_web3(providers=None):
    from web3 import HTTPProvider, IPCProvider, Web3
    from web3.contract import ConciseContract
    from web3.middleware import make_stalecheck_middleware

    if not providers:
        providers = [IPCProvider(), HTTPProvider('http://localhost:8545')]
    w3 = Web3(providers, ens=None)
    w3.middleware_stack.remove('name_to_address')
    w3.middleware_stack.add(
        make_stalecheck_middleware(ACCEPTABLE_STALE_HOURS * 3600),
        name='stalecheck',
    )
    w3.eth.setContractFactory(ConciseContract)
    return w3