Adds additional functionality that will be needed when deploying data persistence

This commit is contained in:
Sergi Delgado Segura
2019-10-04 13:50:43 +01:00
parent 9a37b211a0
commit 3ed9ccd466

View File

@@ -7,7 +7,7 @@ from pisa.utils.auth_proxy import JSONRPCException
class BlockProcessor: class BlockProcessor:
@staticmethod @staticmethod
def getblock(block_hash): def get_block(block_hash):
block = None block = None
try: try:
@@ -18,6 +18,18 @@ class BlockProcessor:
return block return block
@staticmethod
def get_best_block_hash():
block_hash = None
try:
block_hash = bitcoin_cli.getbestblockhash()
except JSONRPCException as e:
logging.error("[BlockProcessor] couldn't get block hash. Error code {}".format(e))
return block_hash
@staticmethod @staticmethod
def get_potential_matches(txids, locator_uuid_map): def get_potential_matches(txids, locator_uuid_map):
potential_locators = {sha256(binascii.unhexlify(txid)).hexdigest(): txid for txid in txids} potential_locators = {sha256(binascii.unhexlify(txid)).hexdigest(): txid for txid in txids}
@@ -55,3 +67,24 @@ class BlockProcessor:
return matches return matches
@staticmethod
def check_confirmations(txs, unconfirmed_txs, tx_job_map, missed_confirmations):
for tx in txs:
if tx in tx_job_map and tx in unconfirmed_txs:
unconfirmed_txs.remove(tx)
logging.info("[Responder] confirmation received for tx {}".format(tx))
elif tx in unconfirmed_txs:
if tx in missed_confirmations:
missed_confirmations[tx] += 1
else:
missed_confirmations[tx] = 1
logging.info("[Responder] tx {} missed a confirmation (total missed: {})"
.format(tx, missed_confirmations[tx]))
return unconfirmed_txs, missed_confirmations