This commit is contained in:
nolash 2020-08-06 10:05:17 +02:00
parent 1dd1c87165
commit 11be7b26f4
Signed by: lash
GPG Key ID: 93EC1C676274C889

View File

@ -45,25 +45,26 @@ class PlatformMiddleware:
r.append(p) r.append(p)
return r return r
# if params.__class__.__name__ == 'list' and len(params) > 0: if params.__class__.__name__ == 'list' and len(params) > 0:
# return params[0] return params[0]
return params return params
def __call__(self, method, suspect_params): def __call__(self, method, suspect_params):
self.id_seq += 1
params = PlatformMiddleware._translate_params(suspect_params)
logg.debug('method {} params {} original params {}'.format(method, params, suspect_params)) self.id_seq += 1
logg.debug('in middleware method {} params {}'.format(method, suspect_params))
if self.re_personal.match(method) != None: if self.re_personal.match(method) != None:
params = PlatformMiddleware._translate_params(suspect_params)
# multiple providers is broken in web3.py 5.12.0 # multiple providers is broken in web3.py 5.12.0
# https://github.com/ethereum/web3.py/issues/1701 # https://github.com/ethereum/web3.py/issues/1701
# hack workaround # hack workaround
s = socket.socket(family=socket.AF_UNIX, type=socket.SOCK_STREAM, proto=0) s = socket.socket(family=socket.AF_UNIX, type=socket.SOCK_STREAM, proto=0)
ipc_provider_workaround = s.connect(self.ipcaddr) ipc_provider_workaround = s.connect(self.ipcaddr)
logg.debug('redirecting method {}'.format(method)) logg.info('redirecting method {} params {} original params {}'.format(method, params, suspect_params))
o = jsonrpc_request(method, params) o = jsonrpc_request(method, params)
j = json.dumps(o) j = json.dumps(o)
logg.debug('send {}'.format(j)) logg.debug('send {}'.format(j))
@ -76,18 +77,17 @@ class PlatformMiddleware:
#return str(json.dumps(jr)) #return str(json.dumps(jr))
return jr return jr
r = self.make_request(method, params) r = self.make_request(method, suspect_params)
logg.debug('retular response {}'.format(r))
return r return r
w3 = Web3(WebsocketProvider('ws://127.0.0.1:8546')) w3 = Web3(WebsocketProvider('ws://127.0.0.1:8546'))
w3.eth.personal = w3.geth.personal w3.eth.personal = w3.geth.personal
w3.middleware_onion.add(PlatformMiddleware) w3.middleware_onion.add(PlatformMiddleware)
#print(w3.eth.personal.newAccount('foo')) print(w3.eth.personal.newAccount('foo'))
#print(w3.eth.blockNumber) print(w3.eth.blockNumber)
print(w3.eth.sendTransaction({ #print(w3.eth.sendTransaction({'to': '0xd3CdA913deB6f67967B99D67aCDFa1712C293601','from': '0xc305c901078781C232A2a521C2aF7980f8385ee9','value': 1000}))
'to': '0xd3CdA913deB6f67967B99D67aCDFa1712C293601',
'from': '0xc305c901078781C232A2a521C2aF7980f8385ee9',
'value': 1000
}))