示例#1
0
 async def get_offer(self,
                     trade_id: bytes32,
                     file_contents: bool = False) -> TradeRecord:
     res = await self.fetch("get_offer", {
         "trade_id": trade_id.hex(),
         "file_contents": file_contents
     })
     offer_str = bytes(Offer.from_bech32(
         res["offer"])).hex() if file_contents else ""
     return TradeRecord.from_json_dict_convenience(res["trade_record"],
                                                   offer_str)
示例#2
0
    async def create_offer_for_ids(
            self,
            offer_dict: Dict[uint32, int],
            fee=uint64(0),
            validate_only: bool = False
    ) -> Tuple[Optional[Offer], TradeRecord]:
        send_dict: Dict[str, int] = {}
        for key in offer_dict:
            send_dict[str(key)] = offer_dict[key]

        res = await self.fetch("create_offer_for_ids", {
            "offer": send_dict,
            "validate_only": validate_only,
            "fee": fee
        })
        offer: Optional[Offer] = None if validate_only else Offer.from_bech32(
            res["offer"])
        offer_str: str = "" if offer is None else bytes(offer).hex()
        return offer, TradeRecord.from_json_dict_convenience(
            res["trade_record"], offer_str)
示例#3
0
    async def get_all_offers(
        self,
        start: int = 0,
        end: int = 50,
        sort_key: str = None,
        reverse: bool = False,
        file_contents: bool = False,
        exclude_my_offers: bool = False,
        exclude_taken_offers: bool = False,
        include_completed: bool = False,
    ) -> List[TradeRecord]:
        res = await self.fetch(
            "get_all_offers",
            {
                "start": start,
                "end": end,
                "sort_key": sort_key,
                "reverse": reverse,
                "file_contents": file_contents,
                "exclude_my_offers": exclude_my_offers,
                "exclude_taken_offers": exclude_taken_offers,
                "include_completed": include_completed,
            },
        )

        records = []
        if file_contents:
            optional_offers = [
                bytes(Offer.from_bech32(o)).hex() for o in res["offers"]
            ]
        else:
            optional_offers = [""] * len(res["trade_records"])
        for record, offer in zip(res["trade_records"], optional_offers):
            records.append(
                TradeRecord.from_json_dict_convenience(record, offer))

        return records
示例#4
0
 async def take_offer(self, offer: Offer, fee=uint64(0)) -> TradeRecord:
     res = await self.fetch("take_offer", {
         "offer": offer.to_bech32(),
         "fee": fee
     })
     return TradeRecord.from_json_dict_convenience(res["trade_record"])