From c7a14fbc56cc7e0ec0a1a693b75bfaa2d6b7c4b5 Mon Sep 17 00:00:00 2001 From: Reckless_Satoshi Date: Mon, 11 Sep 2023 08:23:11 -0700 Subject: [PATCH] Fix order status change must happen exactly when last sats update on contract finalization --- api/logics.py | 8 +++++--- api/views.py | 12 +++++++++++- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/api/logics.py b/api/logics.py index 89d037b7..d2b4ee99 100644 --- a/api/logics.py +++ b/api/logics.py @@ -1310,22 +1310,24 @@ class Logics: # (This is the last update to "last_satoshis", it becomes the escrow amount next) order.last_satoshis = cls.satoshis_now(order) order.last_satoshis_time = timezone.now() - order.taker_bond.status = LNPayment.Status.LOCKED - order.taker_bond.save(update_fields=["status"]) # With the bond confirmation the order is extended 'public_order_duration' hours order.expires_at = timezone.now() + timedelta( seconds=order.t_to_expire(Order.Status.WF2) ) - order.update_status(Order.Status.WF2) + order.status = Order.Status.WF2 order.save( update_fields=[ + "status", "last_satoshis", "last_satoshis_time", "expires_at", ] ) + order.taker_bond.status = LNPayment.Status.LOCKED + order.taker_bond.save(update_fields=["status"]) + # Both users robots are added one more contract // Unsafe can add more than once. order.maker.robot.total_contracts += 1 order.taker.robot.total_contracts += 1 diff --git a/api/views.py b/api/views.py index 1320bada..f4cf083f 100644 --- a/api/views.py +++ b/api/views.py @@ -307,7 +307,17 @@ class OrderView(viewsets.ViewSet): data["escrow_locked"] = False # If both bonds are locked, participants can see the final trade amount in sats. - if order.taker_bond: + if order.status in [ + Order.Status.WF2, + Order.Status.WFI, + Order.Status.WFE, + Order.Status.CCA, + Order.Status.FSE, + Order.Status.DIS, + Order.Status.PAY, + Order.Status.SUC, + Order.Status.FAI, + ]: if ( order.maker_bond.status == order.taker_bond.status