def setup_ipc_provider(): from web3.providers.ipc import IPCProvider with tempdir() as base_dir: geth = GethProcess('testing', base_dir=base_dir) geth.start() wait_for_ipc_connection(geth.ipc_path) provider = IPCProvider(geth.ipc_path) provider._geth = geth yield provider geth.stop()
def __init__(self, ipc_path: str = DEFAULT_IPC_PATH, timeout: int = TIMEOUT, testnet: bool = False): super().__init__() self.w3 = Web3(provider=IPCProvider(ipc_path=ipc_path, timeout=timeout) ) # TODO: Unify with clients or build error handling self.ipc_path = ipc_path self.testnet = testnet
def disconnected_provider(request): """ Supply a Provider that's not connected to a node. (See also the web3 fixture.) """ if request.param == 'tester': port = get_open_port() provider = TestRPCProvider(port=port) provider.server.stop() provider.server.close() provider.thread.kill() return provider elif request.param == 'rpc': return RPCProvider(port=9999) elif request.param == 'ipc': return IPCProvider(ipc_path='nonexistent') else: raise ValueError(request.param)
def disconnected_provider(request): """ Supply a Provider that's not connected to a node. (See also the web3 fixture.) """ if request.param == 'testrpc': port = get_open_port() provider = TestRPCProvider(port=port) try: provider.server.stop() provider.server.close() provider.thread.kill() except AttributeError: provider.server.shutdown() return provider elif request.param == 'rpc': return RPCProvider(port=get_open_port()) elif request.param == 'keep-alive-rpc': return KeepAliveRPCProvider(port=get_open_port()) elif request.param == 'ipc': return IPCProvider(ipc_path='nonexistent') else: raise ValueError(request.param)
def test_sync_waits_for_full_result(jsonrpc_ipc_pipe_path, serve_empty_result): provider = IPCProvider(pathlib.Path(jsonrpc_ipc_pipe_path), timeout=3) result = provider.make_request("method", []) assert result == {'id': 1, 'result': {}} provider._socket.sock.close()
def test_ipc_no_path(): """ IPCProvider.isConnected() returns False when no path is supplied """ ipc = IPCProvider(None) assert ipc.isConnected() is False
def test_ipc_tilda_in_path(): expectedPath = str(pathlib.Path.home()) + '/foo' assert IPCProvider('~/foo').ipc_path == expectedPath assert IPCProvider(pathlib.Path('~/foo')).ipc_path == expectedPath
from uniswap.uniswap import UniswapV2Utils as utils from rpc import BatchHTTPProvider, BatchIPCProvider import threading import random config = json.load(open('config.json')) network = config['network'] address = config['address'] privkey = config['privkey'] http_addr = config[network]['http'] wss_addr = config[network]['wss'] uni = UniswapV2Client(address, privkey, http_addr) # w3 = Web3(HTTPProvider(http_addr, request_kwargs={'timeout': 6000})) w3 = Web3(IPCProvider('/data/geth/geth.ipc', timeout=6000)) ws = Web3(WebsocketProvider(wss_addr)) batch_provider = BatchHTTPProvider(config[network]['http']) # batch_provider = BatchIPCProvider('/data/geth/geth.ipc', timeout = 6000) pairABI = json.load(open('abi/IUniswapV2Pair.json'))['abi'] erc20abi = json.load(open('./abi/erc20.abi')) def get_symbol(addr): c = w3.eth.contract(address=addr, abi=erc20abi) symbol = c.functions.symbol().call() return symbol '''