mirror of
https://github.com/aljazceru/python-teos.git
synced 2025-12-17 22:24:23 +01:00
Moves tx_in_chain to Carrier
Also integrates it properly so it uses self.get_transaction() instead of bitcoin_cli straightaway. Error messages have also been merged / modified
This commit is contained in:
@@ -80,10 +80,28 @@ class Carrier:
|
|||||||
# reorged while we were querying bitcoind to get the confirmation count. In such a case we just
|
# reorged while we were querying bitcoind to get the confirmation count. In such a case we just
|
||||||
# restart the job
|
# restart the job
|
||||||
if e.error.get("code") == RPC_INVALID_ADDRESS_OR_KEY:
|
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:
|
else:
|
||||||
# If something else happens (unlikely but possible) log it so we can treat it in future releases
|
# 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)
|
logger.error("JSONRPCException.", method="Carrier.get_transaction", error=e.error)
|
||||||
|
|
||||||
return tx_info
|
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
|
||||||
|
|||||||
@@ -2,8 +2,6 @@ import re
|
|||||||
from http.client import HTTPException
|
from http.client import HTTPException
|
||||||
|
|
||||||
import pisa.conf as conf
|
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
|
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
|
# NOTCOVERED
|
||||||
def can_connect_to_bitcoind():
|
def can_connect_to_bitcoind():
|
||||||
can_connect = True
|
can_connect = True
|
||||||
|
|||||||
Reference in New Issue
Block a user