mirror of
https://github.com/aljazceru/python-teos.git
synced 2025-12-17 14:14:22 +01:00
Added Logger class; refactored logging accordingly
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
import binascii
|
||||
from hashlib import sha256
|
||||
|
||||
from pisa import logging, bitcoin_cli, M
|
||||
from pisa import bitcoin_cli, Logger
|
||||
from pisa.utils.auth_proxy import JSONRPCException
|
||||
|
||||
logger = Logger("BlockProcessor")
|
||||
|
||||
|
||||
class BlockProcessor:
|
||||
@staticmethod
|
||||
@@ -14,7 +16,7 @@ class BlockProcessor:
|
||||
|
||||
except JSONRPCException as e:
|
||||
block = None
|
||||
logging.error(M("[BlockProcessor] couldn't get block from bitcoind.", error_code=e))
|
||||
logger.error("couldn't get block from bitcoind.", error_code=e)
|
||||
|
||||
return block
|
||||
|
||||
@@ -26,7 +28,7 @@ class BlockProcessor:
|
||||
|
||||
except JSONRPCException as e:
|
||||
block_hash = None
|
||||
logging.error(M("[BlockProcessor] couldn't get block hash.", error_code=e))
|
||||
logger.error("couldn't get block hash.", error_code=e)
|
||||
|
||||
return block_hash
|
||||
|
||||
@@ -38,7 +40,7 @@ class BlockProcessor:
|
||||
|
||||
except JSONRPCException as e:
|
||||
block_count = None
|
||||
logging.error("[BlockProcessor] couldn't get block block count. Error code {}".format(e))
|
||||
logger.error("couldn't get block block count", error_code=e)
|
||||
|
||||
return block_count
|
||||
|
||||
@@ -54,10 +56,10 @@ class BlockProcessor:
|
||||
potential_matches = {locator: potential_locators[locator] for locator in intersection}
|
||||
|
||||
if len(potential_matches) > 0:
|
||||
logging.info(M("[BlockProcessor] list of potential matches", potential_matches=potential_matches))
|
||||
logger.info("list of potential matches", potential_matches=potential_matches)
|
||||
|
||||
else:
|
||||
logging.info(M("[BlockProcessor] no potential matches found"))
|
||||
logger.info("no potential matches found")
|
||||
|
||||
return potential_matches
|
||||
|
||||
@@ -75,13 +77,12 @@ class BlockProcessor:
|
||||
justice_txid = bitcoin_cli.decoderawtransaction(justice_rawtx).get('txid')
|
||||
matches.append((locator, uuid, dispute_txid, justice_txid, justice_rawtx))
|
||||
|
||||
logging.info(M("[BlockProcessor] match found for locator.",
|
||||
locator=locator, uuid=uuid, justice_txid=justice_txid))
|
||||
logger.info("match found for locator.", locator=locator, uuid=uuid, justice_txid=justice_txid)
|
||||
|
||||
except JSONRPCException as e:
|
||||
# Tx decode failed returns error code -22, maybe we should be more strict here. Leaving it simple
|
||||
# for the POC
|
||||
logging.error(M("[BlockProcessor] can't build transaction from decoded data.", error_code=e))
|
||||
logger.error("can't build transaction from decoded data.", error_code=e)
|
||||
|
||||
return matches
|
||||
|
||||
@@ -93,7 +94,7 @@ class BlockProcessor:
|
||||
if tx in tx_job_map and tx in unconfirmed_txs:
|
||||
unconfirmed_txs.remove(tx)
|
||||
|
||||
logging.info(M("[Responder] confirmation received for transaction", tx=tx))
|
||||
logger.info("confirmation received for transaction", tx=tx)
|
||||
|
||||
elif tx in unconfirmed_txs:
|
||||
if tx in missed_confirmations:
|
||||
@@ -102,8 +103,6 @@ class BlockProcessor:
|
||||
else:
|
||||
missed_confirmations[tx] = 1
|
||||
|
||||
logging.info(M("[Responder] transaction missed a confirmation",
|
||||
tx=tx, missed_confirmations=missed_confirmations[tx]))
|
||||
logger.info("transaction missed a confirmation", tx=tx, missed_confirmations=missed_confirmations[tx])
|
||||
|
||||
return unconfirmed_txs, missed_confirmations
|
||||
|
||||
|
||||
Reference in New Issue
Block a user