diff --git a/pisa/carrier.py b/pisa/carrier.py index c89f656..ff2d8b9 100644 --- a/pisa/carrier.py +++ b/pisa/carrier.py @@ -80,10 +80,28 @@ class Carrier: # reorged while we were querying bitcoind to get the confirmation count. In such a case we just # restart the job if e.error.get("code") == RPC_INVALID_ADDRESS_OR_KEY: - logger.info("Transaction got reorged before obtaining information", txid=txid) + logger.info("Transaction not found in mempool nor blockchain", txid=txid) else: # If something else happens (unlikely but possible) log it so we can treat it in future releases logger.error("JSONRPCException.", method="Carrier.get_transaction", error=e.error) return tx_info + + def check_tx_in_chain(self, txid): + tx_in_chain = False + confirmations = None + + tx_info = self.get_transaction(txid) + + if tx_info is not None: + confirmations = int(tx_info.get("confirmations")) if tx_info.get("confirmations") is not None else None + + if confirmations is not None: + tx_in_chain = True + logger.error("Transaction found in the blockchain", txid=txid) + + else: + logger.error("Transaction found in mempool", txid=txid) + + return tx_in_chain, confirmations diff --git a/pisa/tools.py b/pisa/tools.py index d0f88f2..9222e0c 100644 --- a/pisa/tools.py +++ b/pisa/tools.py @@ -2,8 +2,6 @@ import re from http.client import HTTPException import pisa.conf as conf -from pisa.logger import Logger -from pisa.rpc_errors import RPC_INVALID_ADDRESS_OR_KEY from pisa.utils.auth_proxy import AuthServiceProxy, JSONRPCException @@ -14,34 +12,6 @@ def bitcoin_cli(): ) -# TODO: currently only used in the Responder; might move there or in the BlockProcessor -# NOTCOVERED -def check_tx_in_chain(tx_id, logger=Logger(), tx_label="Transaction"): - tx_in_chain = False - confirmations = 0 - - try: - tx_info = bitcoin_cli().getrawtransaction(tx_id, 1) - - if tx_info.get("confirmations"): - confirmations = int(tx_info.get("confirmations")) - tx_in_chain = True - logger.error("{} found in the blockchain".format(tx_label), txid=tx_id) - - else: - logger.error("{} found in mempool".format(tx_label), txid=tx_id) - - except JSONRPCException as e: - if e.error.get("code") == RPC_INVALID_ADDRESS_OR_KEY: - logger.error("{} not found in mempool nor blockchain".format(tx_label), txid=tx_id) - - else: - # ToDO: Unhandled errors, check this properly - logger.error("JSONRPCException.", method="tools.check_tx_in_chain", error=e.error) - - return tx_in_chain, confirmations - - # NOTCOVERED def can_connect_to_bitcoind(): can_connect = True