Accept none value in build raw for to address

This commit is contained in:
nolash
2021-02-24 22:38:56 +01:00
parent 17431dc000
commit 1f19aecd0e
6 changed files with 63 additions and 4 deletions

View File

@@ -6,9 +6,29 @@ from hexathon import (
)
def is_address(address_hex):
try:
address_hex = strip_0x(address_hex)
except ValueError:
return False
return len(address_hex) == 40
def is_checksum_address(address_hex):
hx = None
try:
hx = to_checksum(address_hex)
except ValueError:
return False
print('{} {}'.format(hx, address_hex))
return hx == address_hex
def to_checksum(address_hex):
address_hex = strip_0x(address_hex)
address_hex = uniform(address_hex)
if len(address_hex) != 40:
raise ValueError('Invalid address length')
h = sha3.keccak_256()
h.update(address_hex.encode('utf-8'))
z = h.digest()

View File

@@ -44,6 +44,7 @@ class HTTPConnection:
logg.debug('(HTTP) send {}'.format(data))
res = urlopen(req, data=data.encode('utf-8'))
o = json.load(res)
logg.debug('(HTTP) recv {}'.format(o))
return jsonrpc_result(o, error_parser)

View File

@@ -73,6 +73,7 @@ def main():
tx = None
status = -1
rcpt = None
if tx_src['blockHash'] != None:
o = jsonrpc_template()
o['method'] = 'eth_getBlockByHash'
@@ -88,13 +89,13 @@ def main():
o['method'] = 'eth_getTransactionReceipt'
o['params'].append(tx_hash)
rcpt = conn.do(o)
status = int(strip_0x(rcpt['status']), 16)
#status = int(strip_0x(rcpt['status']), 16)
if tx == None:
tx = Tx(tx_src)
if rcpt != None:
tx.apply_receipt(rcpt)
print(tx)
status_name = Status(status).name
print('status {}'.format(status_name))
if __name__ == '__main__':

View File

@@ -112,6 +112,8 @@ class TxFactory:
def build_raw(self, tx):
if tx['to'] == None or tx['to'] == '':
tx['to'] = '0x'
txe = EIP155Transaction(tx, tx['nonce'], tx['chainId'])
self.signer.signTransaction(txe)
tx_raw = txe.rlp_serialize()