async def get_additions_and_removals(self, header_hash: bytes32) -> Tuple[List[CoinRecord], List[CoinRecord]]:
     try:
         response = await self.fetch("get_additions_and_removals", {"header_hash": header_hash.hex()})
     except Exception:
         return [], []
     removals = []
     additions = []
     for coin_record in response["removals"]:
         removals.append(CoinRecord.from_json_dict(coin_record))
     for coin_record in response["additions"]:
         additions.append(CoinRecord.from_json_dict(coin_record))
     return additions, removals
示例#2
0
 async def get_coin_record_by_name(
         self, coin_id: bytes32) -> Optional[CoinRecord]:
     try:
         response = await self.fetch("get_coin_record_by_name",
                                     {"name": coin_id.hex()})
     except Exception:
         return None
     return CoinRecord.from_json_dict(response["coin_record"])
 async def get_coin_records_by_puzzle_hash(
     self,
     puzzle_hash: bytes32,
     include_spent_coins: bool = True,
     start_height: Optional[int] = None,
     end_height: Optional[int] = None,
 ) -> List:
     d = {"puzzle_hash": puzzle_hash.hex(), "include_spent_coins": include_spent_coins}
     if start_height is not None:
         d["start_height"] = start_height
     if end_height is not None:
         d["end_height"] = end_height
     return [
         CoinRecord.from_json_dict(coin)
         for coin in (await self.fetch("get_coin_records_by_puzzle_hash", d))["coin_records"]
     ]
 async def get_coin_records_by_parent_ids(
     self,
     parent_ids: List[bytes32],
     include_spent_coins: bool = True,
     start_height: Optional[int] = None,
     end_height: Optional[int] = None,
 ) -> List:
     parent_ids_hex = [pid.hex() for pid in parent_ids]
     d = {"parent_ids": parent_ids_hex, "include_spent_coins": include_spent_coins}
     if start_height is not None:
         d["start_height"] = start_height
     if end_height is not None:
         d["end_height"] = end_height
     return [
         CoinRecord.from_json_dict(coin)
         for coin in (await self.fetch("get_coin_records_by_parent_ids", d))["coin_records"]
     ]
    async def get_coin_records_by_names(
        self,
        names: List[bytes32],
        include_spent_coins: bool = True,
        start_height: Optional[int] = None,
        end_height: Optional[int] = None,
    ) -> List:
        names_hex = [name.hex() for name in names]
        d = {"names": names_hex, "include_spent_coins": include_spent_coins}
        if start_height is not None:
            d["start_height"] = start_height
        if end_height is not None:
            d["end_height"] = end_height

        response = await self.fetch("get_coin_records_by_names", d)
        return [
            CoinRecord.from_json_dict(coin_record_dict_backwards_compat(coin))
            for coin in response["coin_records"]
        ]