async def get_block(self, header_hash) -> Optional[FullBlock]: try: response = await self.fetch("get_block", {"header_hash": header_hash.hex()}) except Exception: return None return FullBlock.from_json_dict(response["block"])
async def get_all_block(self, start: uint32, end: uint32) -> List[FullBlock]: response = await self.fetch("get_blocks", { "start": start, "end": end, "exclude_header_hash": True }) return [FullBlock.from_json_dict(r) for r in response["blocks"]]
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_dict(response["block"])
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_EPOCH": 12, # The number of blocks per epoch "DIFFICULTY_DELAY": 3, # EPOCH / WARP_FACTOR } block = bt.create_genesis_block(test_constants, bytes([0] * 32), b"0") dict_block = block.to_json_dict() assert FullBlock.from_json_dict(dict_block) == block
async def get_blockchain_state(self) -> Dict: response = await self.fetch("get_blockchain_state", {}) if response["blockchain_state"]["peak"] is not None: response["blockchain_state"]["peak"] = FullBlock.from_json_dict( response["blockchain_state"]["peak"]) return response["blockchain_state"]
def test_json(self): block = bt.create_genesis_block(test_constants, bytes([0] * 32), b"0") dict_block = block.to_json_dict() assert FullBlock.from_json_dict(dict_block) == block