Skip to content
Snippets Groups Projects
Commit 0062a30b authored by inso's avatar inso
Browse files

Fix crash when doc could not be found or parsed

parent 6c6db2ac
No related branches found
No related tags found
No related merge requests found
...@@ -89,7 +89,7 @@ class TxHistory(): ...@@ -89,7 +89,7 @@ class TxHistory():
""" """
Parse a transaction Parse a transaction
:param cutecoin.core.Community community: The community :param cutecoin.core.Community community: The community
:param dict tx: The tx json data :param ucoinpy.documents.Transaction tx: The tx json data
:param int block_number: The block number were we found the tx :param int block_number: The block number were we found the tx
:param int mediantime: Median time on the network :param int mediantime: Median time on the network
:param list received_list: The list of received transactions :param list received_list: The list of received transactions
...@@ -184,29 +184,37 @@ class TxHistory(): ...@@ -184,29 +184,37 @@ class TxHistory():
:return: The list of transfers sent :return: The list of transfers sent
""" """
block = None block = None
block_doc = None
tries = 0 tries = 0
while block is None and tries < 3: while block is None and tries < 3:
block = yield from community.bma_access.future_request(bma.blockchain.Block, try:
block = yield from community.bma_access.future_request(bma.blockchain.Block,
req_args={'number': block_number}) req_args={'number': block_number})
signed_raw = "{0}{1}\n".format(block['raw'], signed_raw = "{0}{1}\n".format(block['raw'],
block['signature']) block['signature'])
transfers = [] transfers = []
try: try:
block_doc = Block.from_signed_raw(signed_raw) block_doc = Block.from_signed_raw(signed_raw)
except: except TypeError:
logging.debug("Error in {0}".format(block_number)) logging.debug("Error in {0}".format(block_number))
block = None block = None
tries += 1 tries += 1
except ValueError as e:
for (txid, tx) in enumerate(block_doc.transactions): if '404' in str(e):
transfer = yield from self._parse_transaction(community, tx, block_number, block = None
block_doc.mediantime, received_list, tries += 1
current_block, txid+txmax) if block_doc:
if transfer != None: for (txid, tx) in enumerate(block_doc.transactions):
logging.debug("Transfer amount : {0}".format(transfer.metadata['amount'])) transfer = yield from self._parse_transaction(community, tx, block_number,
transfers.append(transfer) block_doc.mediantime, received_list,
else: current_block, txid+txmax)
logging.debug("None transfer") if transfer != None:
logging.debug("Transfer amount : {0}".format(transfer.metadata['amount']))
transfers.append(transfer)
else:
logging.debug("None transfer")
else:
logging.debug("Could not find or parse block {0}".format(block_number))
return transfers return transfers
@asyncio.coroutine @asyncio.coroutine
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment