def test_get_block_index(self): """Test validity of getting block index.""" db = rocksdb.DB(DB_PATH, rocksdb.Options(create_if_missing=True, max_open_files=10000), read_only=True) block_index = '25308' block_hash = '0x31a2bdcaed45ff75bd2d4803731b4200719f6fe1c07e3661f33e3a9a2c996a6e' gatherer = DatabaseGatherer(db) gathered_data = gatherer.get_block_hash_by_index(block_index) self.assertEqual(block_hash, gathered_data)
def get_hash_by_index(block_index: str, db: Any = None) -> None: """ Get block hash by its index. Args: block_index: Index of the block. db: Read-only database instance. """ try: int(block_index) except ValueError: return 'Index {} couldn\'t be parsed'.format(block_index), 400 gatherer = DatabaseGatherer(db) block_hash = gatherer.get_block_hash_by_index(block_index) if block_hash is None: return 'Block with index {} not found'.format(block_index), 404 return block_hash