Exemplo n.º 1
0
 async def get_block_record(self, header_hash: bytes32) -> BlockRecord:
     cursor = await self.db_connection.execute(
         "SELECT * from block_records WHERE header_hash=?", (header_hash.hex(),)
     )
     row = await cursor.fetchone()
     await cursor.close()
     return BlockRecord.from_bytes(row[3])
Exemplo n.º 2
0
 async def get_block_record(self, header_hash: bytes32) -> Optional[BlockRecord]:
     """Gets a block record from the database, if present"""
     cursor = await self.db_connection.execute(
         "SELECT * from block_records WHERE header_hash=?", (header_hash.hex(),)
     )
     row = await cursor.fetchone()
     await cursor.close()
     if row is not None:
         return BlockRecord.from_bytes(row[3])
     else:
         return None
Exemplo n.º 3
0
 async def get_lca_path(self) -> Dict[bytes32, BlockRecord]:
     """
     Returns block records representing the blockchain from the genesis
     block up to the LCA (least common ancestor). Note that the DB also
     contains many blocks not on this path, due to reorgs.
     """
     cursor = await self.db_connection.execute(
         "SELECT * from block_records WHERE in_lca_path=1")
     rows = await cursor.fetchall()
     await cursor.close()
     hash_to_br: Dict = {}
     max_height = -1
     for row in rows:
         br = BlockRecord.from_bytes(row[4])
         hash_to_br[bytes.fromhex(row[0])] = br
         assert row[0] == br.header_hash.hex()
         assert row[1] == br.height
         if br.height > max_height:
             max_height = br.height
     # Makes sure there's exactly one block per height
     assert max_height == len(list(rows)) - 1
     return hash_to_br