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:
Sergi Delgado Segura
2019-11-20 13:01:27 +00:00
parent f91413ebd8
commit 05961f1632
2 changed files with 19 additions and 31 deletions

View File

@@ -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