示例#1
0
def read_block(block_hash: str, db: Any = None) -> None:
    """
    Read one block by its hash.

    Args:
        block_hash: Unique hash of the block.
        db: Read-only database instance.
    """
    gatherer = DatabaseGatherer(db)
    block = gatherer.get_block_by_hash(block_hash.lower())
    if block is None:
        return 'Block with hash {} not found'.format(block_hash), 404

    return block
    def test_get_block(self):
        """Test validity of block data."""
        db = rocksdb.DB(DB_PATH,
                        rocksdb.Options(create_if_missing=True,
                                        max_open_files=10000),
                        read_only=True)
        with open('tests/resources/block_data.txt', 'r') as f:
            compare_data = json.loads(f.read())

        block_hash = '0x31a2bdcaed45ff75bd2d4803731b4200719f6fe1c07e3661f33e3a9a2c996a6e'
        gatherer = DatabaseGatherer(db)
        gathered_data = gatherer.get_block_by_hash(block_hash)

        self.assertEqual(compare_data, gathered_data)