示例#1
0
def get_w3(ipc_path: pathlib.Path = None) -> Web3:
    if ipc_path is None:
        ipc_path = get_xdg_alexandria_root() / 'jsonrpc.ipc'

    provider = IPCProvider(str(ipc_path))
    w3 = Web3(provider=provider, modules={'alexandria': (AlexandriaModule,)})
    return w3
示例#2
0
def load_provider_from_uri(
        uri_string: URI,
        headers: Optional[Dict[str, Tuple[str, str]]] = None) -> BaseProvider:
    uri = urlparse(uri_string)
    if uri.scheme == 'file':
        return IPCProvider(uri.path)
    elif uri.scheme in HTTP_SCHEMES:
        return HTTPProvider(uri_string, headers)
    elif uri.scheme in WS_SCHEMES:
        return WebsocketProvider(uri_string)
    else:
        raise NotImplementedError(
            f'Web3 does not know how to connect to scheme {uri.scheme!r} in {uri_string!r}'
        )
示例#3
0
def load_provider_from_uri(uri_string, headers=None):
    uri = urlparse(uri_string)
    if uri.scheme == 'file':
        return IPCProvider(uri.path)
    elif uri.scheme in HTTP_SCHEMES:
        return HTTPProvider(uri_string, headers)
    elif uri.scheme in WS_SCHEMES:
        return WebsocketProvider(uri_string)
    else:
        raise NotImplementedError(
            'Web3 does not know how to connect to scheme %r in %r' % (
                uri.scheme,
                uri_string,
            ))
示例#4
0
 def _spawn_geth_process(self):
     ipcpath = tempfile.mkstemp(suffix='.ipc')[1]
     proc = subprocess.Popen(
         ['geth', '--dev', '-ipcpath={}'.format(ipcpath)],
         stdout=subprocess.PIPE,
         stdin=subprocess.PIPE,
         stderr=subprocess.PIPE,
     )
     atexit.register(lambda: proc.kill())
     self.proc = proc
     self.web3 = Web3(IPCProvider(ipcpath))
     self.web3.middleware_stack.inject(geth_poa_middleware, layer=0)
     while not self.web3.isConnected():
         time.sleep(0.1)
示例#5
0
def load_provider_from_environment():
    uri_string = os.environ.get('WEB3_PROVIDER_URI', '')
    if not uri_string:
        return None

    uri = urlparse(uri_string)
    if uri.scheme == 'file':
        return IPCProvider(uri.path)
    elif uri.scheme == 'http':
        return HTTPProvider(uri_string)
    else:
        raise NotImplementedError(
            'Web3 does not know how to connect to scheme %r in %r' % (
                uri.scheme,
                uri_string,
            ))
示例#6
0
def test_is_strictly_default_http_middleware():
    web3 = HTTPProvider()
    assert 'http_retry_request' in web3.middlewares

    web3 = IPCProvider()
    assert 'http_retry_request' not in web3.middlewares