Refactored check_tx_in_chain with new log format

This commit is contained in:
Salvatore Ingala
2019-10-09 08:29:47 +07:00
parent bae9b6b913
commit 4bcc8e20a0
3 changed files with 10 additions and 11 deletions

View File

@@ -20,8 +20,7 @@ if __name__ == '__main__':
start_api()
else:
logger.error("[Pisad] bitcoind is running on a different network, check conf.py and bitcoin.conf. "
"Shutting down")
logger.error("bitcoind is running on a different network, check conf.py and bitcoin.conf. Shutting down")
else:
logging.error("[Pisad] can't connect to bitcoind. Shutting down")
logging.error("can't connect to bitcoind. Shutting down")

View File

@@ -183,11 +183,11 @@ class Responder:
for uuid, job in self.jobs.items():
# First we check if the dispute transaction is still in the blockchain. If not, the justice can not be
# there either, so we'll need to call the reorg manager straight away
dispute_in_chain, _ = check_tx_in_chain(job.dispute_txid, parent='Responder', tx_label='dispute tx')
dispute_in_chain, _ = check_tx_in_chain(job.dispute_txid, logger=logger, tx_label='dispute tx')
# If the dispute is there, we can check the justice tx
if dispute_in_chain:
justice_in_chain, justice_confirmations = check_tx_in_chain(job.justice_txid, parent='Responder',
justice_in_chain, justice_confirmations = check_tx_in_chain(job.justice_txid, logger=logger,
tx_label='justice tx')
# If both transactions are there, we only need to update the justice tx confirmation count

View File

@@ -2,12 +2,12 @@ import re
from http.client import HTTPException
import pisa.conf as conf
from pisa import logging, bitcoin_cli
from pisa import bitcoin_cli, Logger
from pisa.utils.auth_proxy import JSONRPCException
from pisa.rpc_errors import RPC_INVALID_ADDRESS_OR_KEY
def check_tx_in_chain(tx_id, parent='', tx_label='transaction'):
def check_tx_in_chain(tx_id, logger=Logger(), tx_label='transaction'):
tx_in_chain = False
confirmations = 0
@@ -17,18 +17,18 @@ def check_tx_in_chain(tx_id, parent='', tx_label='transaction'):
if tx_info.get("confirmations"):
confirmations = int(tx_info.get("confirmations"))
tx_in_chain = True
logging.error("[{}] {} found in the blockchain (txid: {}) ".format(parent, tx_label, tx_id))
logger.error("{} found in the blockchain (txid: {}) ".format(tx_label), txid=tx_id)
else:
logging.error("[{}] {} found in mempool (txid: {}) ".format(parent, tx_label, tx_id))
logger.error("{} found in mempool (txid: {}) ".format(tx_label), txid=tx_id)
except JSONRPCException as e:
if e.error.get('code') == RPC_INVALID_ADDRESS_OR_KEY:
logging.error("[{}] {} not found in mempool nor blockchain (txid: {}) ".format(parent, tx_label, tx_id))
logger.error("{} not found in mempool nor blockchain (txid: {}) ".format(tx_label), txid=tx_id)
else:
# ToDO: Unhandled errors, check this properly
logging.error("[{}] JSONRPCException. Error code {}".format(parent, e))
logger.error("JSONRPCException.", error_code=e)
return tx_in_chain, confirmations