Handle hex inputs for tx create

This commit is contained in:
nolash
2020-10-26 09:02:29 +01:00
parent d46d0620fa
commit b7a35ea181
9 changed files with 131 additions and 27 deletions

View File

@@ -27,11 +27,35 @@ class EIP155Transaction:
to = binascii.unhexlify(strip_hex_prefix(tx['to']))
data = binascii.unhexlify(strip_hex_prefix(tx['data']))
gas_price = None
start_gas = None
value = None
try:
gas_price = int(tx['gasPrice'])
except ValueError:
gas_price = int(tx['gasPrice'], 16)
try:
start_gas = int(tx['gas'])
except ValueError:
start_gas = int(tx['gas'], 16)
try:
value = int(tx['value'])
except ValueError:
value = int(tx['value'], 16)
try:
nonce = int(nonce)
except ValueError:
nonce = int(nonce, 16)
self.nonce = nonce
self.gas_price = int(tx['gasPrice'])
self.start_gas = int(tx['gas'])
self.gas_price = gas_price
self.start_gas = start_gas
self.to = to
self.value = int(tx['value'])
self.value = value
self.data = data
self.v = chainId
self.r = b''

View File

@@ -17,13 +17,8 @@ def create_middleware(ipcpath):
# overrides the original Web3 constructor
def Web3(blockchain_provider='ws://localhost:8546', ipcpath=None):
provider = None
if re.match(re_websocket, blockchain_provider) != None:
provider = WebsocketProvider(blockchain_provider)
elif re.match(re_http, blockchain_provider) != None:
provider = HTTPProvider(blockchain_provider)
#def Web3(blockchain_provider='ws://localhost:8546', ipcpath=None):
def Web3(provider, ipcpath=None):
w3 = Web3super(provider)
if ipcpath != None:

View File

@@ -38,11 +38,11 @@ class PlatformMiddleware:
# dict input comes as [{}] and fails if not passed on as an array
@staticmethod
def _translate_params(params):
if params.__class__.__name__ == 'tuple':
r = []
for p in params:
r.append(p)
return r
#if params.__class__.__name__ == 'tuple':
# r = []
# for p in params:
# r.append(p)
# return r
if params.__class__.__name__ == 'list' and len(params) > 0:
return params[0]
@@ -64,7 +64,7 @@ class PlatformMiddleware:
ipc_provider_workaround = s.connect(self.ipcaddr)
logg.info('redirecting method {} params {} original params {}'.format(method, params, suspect_params))
o = jsonrpc_request(method, params)
o = jsonrpc_request(method, params[0])
j = json.dumps(o)
logg.debug('send {}'.format(j))
s.send(j.encode('utf-8'))
@@ -81,8 +81,8 @@ class PlatformMiddleware:
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)
logg.info('redirecting methodd {} params {} original params {}'.format(method, params, suspect_params))
o = jsonrpc_request(method, params[0])
j = json.dumps(o)
logg.debug('send {}'.format(j))
s.send(j.encode('utf-8'))

View File

@@ -75,6 +75,7 @@ class ReferenceKeystore(Keystore):
},
)
self.db_session.commit()
logg.info('added private key for address {}'.format(address_hex_clean))
return address_hex

View File

@@ -97,6 +97,7 @@ def personal_new_account(p):
def personal_sign_transaction(p):
logg.debug('got {} to sign'.format(p[0]))
t = EIP155Transaction(p[0], p[0]['nonce'], 8995)
z = signer.signTransaction(t, p[1])
raw_signed_tx = t.rlp_serialize()
@@ -212,7 +213,6 @@ def init():
signer = ReferenceSigner(db)
#if __name__ == '__main__':
def main():
init()
arg = None
@@ -226,3 +226,7 @@ def main():
(rpc_id, response) = process_input(arg)
r = jsonrpc_ok(rpc_id, response)
sys.stdout.write(json.dumps(r))
if __name__ == '__main__':
main()