Avoid empty nonce string from tx
This commit is contained in:
parent
d07fc6c767
commit
468dd65462
@ -2,6 +2,7 @@
|
|||||||
- Implement DictKeystore
|
- Implement DictKeystore
|
||||||
- Remove unused insert_key method in keystore interface
|
- Remove unused insert_key method in keystore interface
|
||||||
- Add transaction executor helper, with adapter helper for eth
|
- Add transaction executor helper, with adapter helper for eth
|
||||||
|
- Fix bitlength of integers in all tx fields before rlp encoding
|
||||||
* 0.4.12
|
* 0.4.12
|
||||||
- Enforce hex strings in signer backend for sign message
|
- Enforce hex strings in signer backend for sign message
|
||||||
* 0.4.11
|
* 0.4.11
|
||||||
|
@ -34,7 +34,10 @@ class ReferenceSigner(Signer):
|
|||||||
g = h.digest()
|
g = h.digest()
|
||||||
k = keys.PrivateKey(self.keyGetter.get(tx.sender, password))
|
k = keys.PrivateKey(self.keyGetter.get(tx.sender, password))
|
||||||
z = keys.ecdsa_sign(message_hash=g, private_key=k)
|
z = keys.ecdsa_sign(message_hash=g, private_key=k)
|
||||||
tx.v = (tx.v * 2) + 35 + z[64]
|
vnum = int.from_bytes(tx.v, 'big')
|
||||||
|
v = (vnum * 2) + 35 + z[64]
|
||||||
|
byts = ((v.bit_length()-1)/8)+1
|
||||||
|
tx.v = v.to_bytes(int(byts), 'big')
|
||||||
tx.r = z[:32]
|
tx.r = z[:32]
|
||||||
tx.s = z[32:64]
|
tx.s = z[32:64]
|
||||||
return z
|
return z
|
||||||
|
@ -35,21 +35,36 @@ class EIP155Transaction:
|
|||||||
gas_price = int(tx['gasPrice'])
|
gas_price = int(tx['gasPrice'])
|
||||||
except ValueError:
|
except ValueError:
|
||||||
gas_price = int(tx['gasPrice'], 16)
|
gas_price = int(tx['gasPrice'], 16)
|
||||||
|
byts = ((gas_price.bit_length()-1)/8)+1
|
||||||
|
gas_price = gas_price.to_bytes(int(byts), 'big')
|
||||||
|
|
||||||
try:
|
try:
|
||||||
start_gas = int(tx['gas'])
|
start_gas = int(tx['gas'])
|
||||||
except ValueError:
|
except ValueError:
|
||||||
start_gas = int(tx['gas'], 16)
|
start_gas = int(tx['gas'], 16)
|
||||||
|
byts = ((start_gas.bit_length()-1)/8)+1
|
||||||
|
start_gas = start_gas.to_bytes(int(byts), 'big')
|
||||||
|
|
||||||
try:
|
try:
|
||||||
value = int(tx['value'])
|
value = int(tx['value'])
|
||||||
except ValueError:
|
except ValueError:
|
||||||
value = int(tx['value'], 16)
|
value = int(tx['value'], 16)
|
||||||
|
byts = ((value.bit_length()-1)/8)+1
|
||||||
|
value = value.to_bytes(int(byts), 'big')
|
||||||
|
|
||||||
try:
|
try:
|
||||||
nonce = int(nonce)
|
nonce = int(nonce)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
nonce = int(nonce, 16)
|
nonce = int(nonce, 16)
|
||||||
|
byts = ((nonce.bit_length()-1)/8)+1
|
||||||
|
nonce = nonce.to_bytes(int(byts), 'big')
|
||||||
|
|
||||||
|
try:
|
||||||
|
chainId = int(chainId)
|
||||||
|
except ValueError:
|
||||||
|
chainId = int(chainId, 16)
|
||||||
|
byts = ((chainId.bit_length()-1)/8)+1
|
||||||
|
chainId = chainId.to_bytes(int(byts), 'big')
|
||||||
|
|
||||||
self.nonce = nonce
|
self.nonce = nonce
|
||||||
self.gas_price = gas_price
|
self.gas_price = gas_price
|
||||||
@ -64,7 +79,6 @@ class EIP155Transaction:
|
|||||||
|
|
||||||
|
|
||||||
def rlp_serialize(self):
|
def rlp_serialize(self):
|
||||||
b = self.nonce.to_bytes(8, byteorder='little')
|
|
||||||
s = [
|
s = [
|
||||||
self.nonce,
|
self.nonce,
|
||||||
self.gas_price,
|
self.gas_price,
|
||||||
@ -79,14 +93,24 @@ class EIP155Transaction:
|
|||||||
return rlp_encode(s)
|
return rlp_encode(s)
|
||||||
|
|
||||||
def serialize(self):
|
def serialize(self):
|
||||||
return {
|
tx = {
|
||||||
'nonce': add_hex_prefix(hex(self.nonce)),
|
'nonce': add_hex_prefix(self.nonce.hex()),
|
||||||
'gasPrice': add_hex_prefix(hex(self.gas_price)),
|
'gasPrice': add_hex_prefix(self.gas_price.hex()),
|
||||||
'gas': add_hex_prefix(hex(self.start_gas)),
|
'gas': add_hex_prefix(self.start_gas.hex()),
|
||||||
'to': add_hex_prefix(self.to.hex()),
|
'to': add_hex_prefix(self.to.hex()),
|
||||||
'value': add_hex_prefix(hex(self.value)),
|
'value': add_hex_prefix(self.value.hex()),
|
||||||
'data': add_hex_prefix(self.data.hex()),
|
'data': add_hex_prefix(self.data.hex()),
|
||||||
'v': add_hex_prefix(hex(self.v)),
|
'v': add_hex_prefix(self.v.hex()),
|
||||||
'r': add_hex_prefix(self.r.hex()),
|
'r': add_hex_prefix(self.r.hex()),
|
||||||
's': add_hex_prefix(self.s.hex()),
|
's': add_hex_prefix(self.s.hex()),
|
||||||
}
|
}
|
||||||
|
if tx['data'] == '':
|
||||||
|
tx['data'] = '0x'
|
||||||
|
|
||||||
|
if tx['value'] == '':
|
||||||
|
tx['value'] = '0x00'
|
||||||
|
|
||||||
|
if tx['nonce'] == '':
|
||||||
|
tx['nonce'] = '0x00'
|
||||||
|
|
||||||
|
return tx
|
||||||
|
2
setup.py
2
setup.py
@ -24,7 +24,7 @@ f.close()
|
|||||||
|
|
||||||
setup(
|
setup(
|
||||||
name="crypto-dev-signer",
|
name="crypto-dev-signer",
|
||||||
version="0.4.13b4",
|
version="0.4.13b8",
|
||||||
description="A signer and keystore daemon and library for cryptocurrency software development",
|
description="A signer and keystore daemon and library for cryptocurrency software development",
|
||||||
author="Louis Holbrook",
|
author="Louis Holbrook",
|
||||||
author_email="dev@holbrook.no",
|
author_email="dev@holbrook.no",
|
||||||
|
@ -68,14 +68,14 @@ class TestSign(unittest.TestCase):
|
|||||||
t = EIP155Transaction(tx_ints, 0)
|
t = EIP155Transaction(tx_ints, 0)
|
||||||
self.assertRegex(t.__class__.__name__, "Transaction")
|
self.assertRegex(t.__class__.__name__, "Transaction")
|
||||||
s = t.serialize()
|
s = t.serialize()
|
||||||
self.assertEqual('{}'.format(s), "{'nonce': '0x0', 'gasPrice': '0x4a817c800', 'gas': '0x5208', 'to': '0x3535353535353535353535353535353535353535', 'value': '0x3e8', 'data': '0xdeadbeef', 'v': '0x1', 'r': '', 's': ''}")
|
self.assertEqual('{}'.format(s), "{'nonce': '', 'gasPrice': '0x04a817c800', 'gas': '0x5208', 'to': '0x3535353535353535353535353535353535353535', 'value': '0x03e8', 'data': '0xdeadbeef', 'v': '0x01', 'r': '', 's': ''}")
|
||||||
r = t.rlp_serialize()
|
r = t.rlp_serialize()
|
||||||
self.assertEqual(r.hex(), 'ea808504a817c8008252089435353535353535353535353535353535353535358203e884deadbeef018080')
|
self.assertEqual(r.hex(), 'ea808504a817c8008252089435353535353535353535353535353535353535358203e884deadbeef018080')
|
||||||
|
|
||||||
t = EIP155Transaction(tx_hexs, 0)
|
t = EIP155Transaction(tx_hexs, 0)
|
||||||
self.assertRegex(t.__class__.__name__, "Transaction")
|
self.assertRegex(t.__class__.__name__, "Transaction")
|
||||||
s = t.serialize()
|
s = t.serialize()
|
||||||
self.assertEqual('{}'.format(s), "{'nonce': '0x0', 'gasPrice': '0x4a817c800', 'gas': '0x5208', 'to': '0x3535353535353535353535353535353535353535', 'value': '0x3e8', 'data': '0xdeadbeef', 'v': '0x1', 'r': '', 's': ''}")
|
self.assertEqual('{}'.format(s), "{'nonce': '', 'gasPrice': '0x04a817c800', 'gas': '0x5208', 'to': '0x3535353535353535353535353535353535353535', 'value': '0x03e8', 'data': '0xdeadbeef', 'v': '0x01', 'r': '', 's': ''}")
|
||||||
r = t.rlp_serialize()
|
r = t.rlp_serialize()
|
||||||
self.assertEqual(r.hex(), 'ea808504a817c8008252089435353535353535353535353535353535353535358203e884deadbeef018080')
|
self.assertEqual(r.hex(), 'ea808504a817c8008252089435353535353535353535353535353535353535358203e884deadbeef018080')
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user