Esempio n. 1
0
 async def get_block(self, header_hash) -> Optional[FullBlock]:
     try:
         response = await self.fetch("get_block",
                                     {"header_hash": header_hash.hex()})
     except aiohttp.client_exceptions.ClientResponseError as e:
         if e.message == "Not Found":
             return None
         raise
     return FullBlock.from_json(response)
Esempio n. 2
0
    def test_json(self):
        bt = BlockTools()

        test_constants: Dict[str, Any] = {
            "DIFFICULTY_STARTING": 5,
            "DISCRIMINANT_SIZE_BITS": 16,
            "BLOCK_TIME_TARGET": 10,
            "MIN_BLOCK_TIME": 2,
            "DIFFICULTY_FACTOR": 3,
            "DIFFICULTY_EPOCH": 12,  # The number of blocks per epoch
            "DIFFICULTY_WARP_FACTOR":
            4,  # DELAY divides EPOCH in order to warp efficiently.
            "DIFFICULTY_DELAY": 3,  # EPOCH / WARP_FACTOR
        }
        block = bt.create_genesis_block(test_constants, bytes([0] * 32), b"0")

        str_block = block.to_json()
        assert FullBlock.from_json(str_block) == block