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
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
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
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
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
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
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
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