Add eth_signTransaction workaround for missing personal_signTransaction

This commit is contained in:
nolash
2020-08-07 23:01:49 +02:00
parent 34440ece7e
commit 472e2f04fc
5 changed files with 48 additions and 14 deletions

View File

@@ -3,3 +3,9 @@ def strip_hex_prefix(hx):
return hx[2:]
return hx
def add_hex_prefix(hx):
if len(hx) < 2:
return hx
if hx[:2] != '0x':
return '0x' + hx
return hx

View File

@@ -3,7 +3,7 @@ import binascii
from rlp import encode as rlp_encode
from common import strip_hex_prefix
from common import strip_hex_prefix, add_hex_prefix
logg = logging.getLogger(__name__)
@@ -52,13 +52,13 @@ class EIP155Transaction:
def serialize(self):
return {
'nonce': '0x' + hex(self.nonce),
'gasPrice': '0x' + hex(self.gas_price),
'gas': '0x' + hex(self.start_gas),
'to': '0x' + self.to.hex(),
'value': '0x' + hex(self.value),
'data': '0x' + self.data.hex(),
'v': '0x' + hex(self.v),
'r': '0x' + self.r.hex(),
's': '0x' + self.s.hex(),
'nonce': add_hex_prefix(hex(self.nonce)),
'gasPrice': add_hex_prefix(hex(self.gas_price)),
'gas': add_hex_prefix(hex(self.start_gas)),
'to': add_hex_prefix(self.to.hex()),
'value': add_hex_prefix(hex(self.value)),
'data': add_hex_prefix(self.data.hex()),
'v': add_hex_prefix(hex(self.v)),
'r': add_hex_prefix(self.r.hex()),
's': add_hex_prefix(self.s.hex()),
}

View File

@@ -19,7 +19,7 @@ def Web3(blockchain_provider='ws://localhost:8546', ipcaddr=None):
provider = None
if re.match(re_websocket, blockchain_provider) != None:
provider = WebsocketProvider(blockchain_provider)
elif re.match(re_http, blockchain_providers[0]) != None:
elif re.match(re_http, blockchain_provider) != None:
provider = HTTPProvider(blockchain_provider)
w3 = Web3super(provider)

View File

@@ -73,5 +73,23 @@ class PlatformMiddleware:
#return str(json.dumps(jr))
return jr
elif method == 'eth_signTransaction':
params = PlatformMiddleware._translate_params(suspect_params)
s = socket.socket(family=socket.AF_UNIX, type=socket.SOCK_STREAM, proto=0)
ipc_provider_workaround = s.connect(self.ipcaddr)
logg.info('redirecting method {} params {} original params {}'.format(method, params, suspect_params))
o = jsonrpc_request(method, params)
j = json.dumps(o)
logg.debug('send {}'.format(j))
s.send(j.encode('utf-8'))
r = s.recv(4096)
s.close()
logg.debug('got recv {}'.format(str(r)))
jr = json.loads(r)
jr['id'] = self.id_seq
#return str(json.dumps(jr))
return jr
r = self.make_request(method, suspect_params)
return r