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,8 +184,10 @@ class TxHistory(): ...@@ -184,8 +184,10 @@ 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:
try:
block = yield from community.bma_access.future_request(bma.blockchain.Block, 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'],
...@@ -193,11 +195,15 @@ class TxHistory(): ...@@ -193,11 +195,15 @@ class TxHistory():
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:
if '404' in str(e):
block = None
tries += 1
if block_doc:
for (txid, tx) in enumerate(block_doc.transactions): for (txid, tx) in enumerate(block_doc.transactions):
transfer = yield from self._parse_transaction(community, tx, block_number, transfer = yield from self._parse_transaction(community, tx, block_number,
block_doc.mediantime, received_list, block_doc.mediantime, received_list,
...@@ -207,6 +213,8 @@ class TxHistory(): ...@@ -207,6 +213,8 @@ class TxHistory():
transfers.append(transfer) transfers.append(transfer)
else: else:
logging.debug("None transfer") 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.
Please register or to comment