Skip to content

Commit

Permalink
Fix error on cancelling cyber escrow
Browse files Browse the repository at this point in the history
Signed-off-by: alfred richardsn <rchrdsn@protonmail.ch>
  • Loading branch information
r4rdsn committed Jun 13, 2020
1 parent 0030b9b commit ab50e5f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
14 changes: 13 additions & 1 deletion src/escrow/blockchain/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,12 +353,24 @@ class StreamBlockchain(BaseBlockchain):

_queue: typing.List[typing.Dict[str, typing.Any]] = []

def check_timeout(self, offer_id: ObjectId) -> None:
def remove_from_queue(
self, offer_id: ObjectId
) -> typing.Optional[typing.Mapping[str, typing.Any]]:
"""Remove transaction with specified ``offer_id`` value from ``self._queue``.
:param offer_id: ``_id`` of escrow offer.
:return: True if transaction was found and False otherwise.
"""
for queue_member in self._queue:
if queue_member["offer_id"] == offer_id:
if "timeout_handler" in queue_member:
queue_member["timeout_handler"].cancel()
self._queue.remove(queue_member)
return queue_member
return None

def check_timeout(self, offer_id: ObjectId) -> None:
self.remove_from_queue(offer_id)
super().check_timeout(offer_id)

@abstractmethod
Expand Down
5 changes: 3 additions & 2 deletions src/handlers/escrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -796,8 +796,9 @@ async def cancel_offer(call: types.CallbackQuery, offer: EscrowOffer):
escrow_user = offer.counter
if call.from_user.id != escrow_user["id"]:
return await call.answer(i18n("cancel_before_verification"))
req = get_escrow_instance(offer.escrow).remove_from_queue(offer._id)
req["timeout_handler"].cancel()
escrow_instance = get_escrow_instance(offer.escrow)
if isinstance(escrow_instance, StreamBlockchain):
escrow_instance.remove_from_queue(offer._id)

sell_answer = i18n("escrow_cancelled", locale=offer.init["locale"])
buy_answer = i18n("escrow_cancelled", locale=offer.counter["locale"])
Expand Down

0 comments on commit ab50e5f

Please sign in to comment.