Avoid empty nonce string from tx
This commit is contained in:
@@ -34,7 +34,10 @@ class ReferenceSigner(Signer):
|
||||
g = h.digest()
|
||||
k = keys.PrivateKey(self.keyGetter.get(tx.sender, password))
|
||||
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.s = z[32:64]
|
||||
return z
|
||||
|
||||
@@ -35,21 +35,36 @@ class EIP155Transaction:
|
||||
gas_price = int(tx['gasPrice'])
|
||||
except ValueError:
|
||||
gas_price = int(tx['gasPrice'], 16)
|
||||
byts = ((gas_price.bit_length()-1)/8)+1
|
||||
gas_price = gas_price.to_bytes(int(byts), 'big')
|
||||
|
||||
try:
|
||||
start_gas = int(tx['gas'])
|
||||
except ValueError:
|
||||
start_gas = int(tx['gas'], 16)
|
||||
byts = ((start_gas.bit_length()-1)/8)+1
|
||||
start_gas = start_gas.to_bytes(int(byts), 'big')
|
||||
|
||||
try:
|
||||
value = int(tx['value'])
|
||||
except ValueError:
|
||||
value = int(tx['value'], 16)
|
||||
byts = ((value.bit_length()-1)/8)+1
|
||||
value = value.to_bytes(int(byts), 'big')
|
||||
|
||||
try:
|
||||
nonce = int(nonce)
|
||||
except ValueError:
|
||||
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.gas_price = gas_price
|
||||
@@ -64,7 +79,6 @@ class EIP155Transaction:
|
||||
|
||||
|
||||
def rlp_serialize(self):
|
||||
b = self.nonce.to_bytes(8, byteorder='little')
|
||||
s = [
|
||||
self.nonce,
|
||||
self.gas_price,
|
||||
@@ -79,14 +93,24 @@ class EIP155Transaction:
|
||||
return rlp_encode(s)
|
||||
|
||||
def serialize(self):
|
||||
return {
|
||||
'nonce': add_hex_prefix(hex(self.nonce)),
|
||||
'gasPrice': add_hex_prefix(hex(self.gas_price)),
|
||||
'gas': add_hex_prefix(hex(self.start_gas)),
|
||||
tx = {
|
||||
'nonce': add_hex_prefix(self.nonce.hex()),
|
||||
'gasPrice': add_hex_prefix(self.gas_price.hex()),
|
||||
'gas': add_hex_prefix(self.start_gas.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()),
|
||||
'v': add_hex_prefix(hex(self.v)),
|
||||
'v': add_hex_prefix(self.v.hex()),
|
||||
'r': add_hex_prefix(self.r.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
|
||||
|
||||
Reference in New Issue
Block a user