2020-10-17 15:03:56 +02:00
|
|
|
import logging
|
2020-08-07 11:37:20 +02:00
|
|
|
import re
|
|
|
|
|
|
|
|
from web3 import Web3 as Web3super
|
|
|
|
from web3 import WebsocketProvider, HTTPProvider
|
2020-08-08 11:33:15 +02:00
|
|
|
from .middleware import PlatformMiddleware
|
2020-08-07 11:37:20 +02:00
|
|
|
|
|
|
|
re_websocket = re.compile('^wss?://')
|
|
|
|
re_http = re.compile('^https?://')
|
|
|
|
|
2020-10-17 15:03:56 +02:00
|
|
|
logg = logging.getLogger(__file__)
|
|
|
|
|
2020-08-07 11:37:20 +02:00
|
|
|
|
2020-10-17 12:25:34 +02:00
|
|
|
def create_middleware(ipcpath):
|
|
|
|
PlatformMiddleware.ipcaddr = ipcpath
|
2020-08-07 11:37:20 +02:00
|
|
|
return PlatformMiddleware
|
|
|
|
|
|
|
|
|
|
|
|
# overrides the original Web3 constructor
|
2020-10-26 09:02:29 +01:00
|
|
|
#def Web3(blockchain_provider='ws://localhost:8546', ipcpath=None):
|
|
|
|
def Web3(provider, ipcpath=None):
|
2020-08-07 11:37:20 +02:00
|
|
|
w3 = Web3super(provider)
|
|
|
|
|
2020-10-17 14:47:01 +02:00
|
|
|
if ipcpath != None:
|
2020-10-17 15:03:56 +02:00
|
|
|
logg.info('using signer middleware with ipc {}'.format(ipcpath))
|
2020-10-17 14:47:01 +02:00
|
|
|
w3.middleware_onion.add(create_middleware(ipcpath))
|
|
|
|
|
2020-08-07 11:37:20 +02:00
|
|
|
w3.eth.personal = w3.geth.personal
|
|
|
|
return w3
|