def is_block_to_tx_valid(tx_id: str, bdb_connection: BigchainDB) -> bool:
"""
Checks if block with transaction is valid
:param tx_id: Id of transaction which should be included in the
:type tx_id: str
:param bdb_connection: Connection object for BigchainDB
:type bdb_connection: BigchainDB
:return: True if transactions is in block and block is valid
:rtype: bool
"""
node = random.choice(bdb_connection.nodes)
res = requests.get(node + bdb_connection.blocks.path + '?transaction_id=' + tx_id)
block_id = res.json()
if len(block_id) < 1 or len(block_id) > 1:
raise exceptions.TransactionIdNotFound(tx_id)
res = requests.get(node + bdb_connection.api_prefix + '/statuses?block_id=' + block_id[0])
if res.status_code != 200:
raise exceptions.BlockIdNotFound(block_id[0])
status = res.json()['status']
if status == 'valid':
return True
return False
评论列表
文章目录