Skip to content

Commit

Permalink
Fix new invoice routing budget not accepted
Browse files Browse the repository at this point in the history
  • Loading branch information
Reckless-Satoshi committed May 2, 2024
1 parent e8283f2 commit 59579ae
Showing 1 changed file with 18 additions and 25 deletions.
43 changes: 18 additions & 25 deletions api/logics.py
Original file line number Diff line number Diff line change
Expand Up @@ -909,31 +909,24 @@ def update_invoice(cls, order, user, invoice, routing_budget_ppm):
if not payout["valid"]:
return False, payout["context"]

if order.payout:
order.payout.invoice = invoice
order.payout.status = LNPayment.Status.VALIDI
order.payout.num_satoshis = num_satoshis
order.payout.description = payout["description"]
order.payout.payment_hash = payout["payment_hash"]
order.payout.created_at = payout["created_at"]
order.payout.expires_at = payout["expires_at"]
order.payout.save()
else:
order.payout = LNPayment.objects.create(
concept=LNPayment.Concepts.PAYBUYER,
type=LNPayment.Types.NORM,
sender=User.objects.get(username=ESCROW_USERNAME),
receiver=user,
routing_budget_ppm=routing_budget_ppm,
routing_budget_sats=routing_budget_sats,
invoice=invoice,
status=LNPayment.Status.VALIDI,
num_satoshis=num_satoshis,
description=payout["description"],
payment_hash=payout["payment_hash"],
created_at=payout["created_at"],
expires_at=payout["expires_at"],
)
order.payout, _ = LNPayment.objects.update_or_create(
concept=LNPayment.Concepts.PAYBUYER,
type=LNPayment.Types.NORM,
sender=User.objects.get(username=ESCROW_USERNAME),
receiver=user,
routing_budget_ppm=routing_budget_ppm,
routing_budget_sats=routing_budget_sats,
# if there is a LNPayment matching these above, it updates that one with defaults below.
defaults={
"invoice": invoice,
"status": LNPayment.Status.VALIDI,
"num_satoshis": num_satoshis,
"description": payout["description"],
"payment_hash": payout["payment_hash"],
"created_at": payout["created_at"],
"expires_at": payout["expires_at"],
},
)

order.is_swap = False
order.save(update_fields=["payout", "is_swap"])
Expand Down

0 comments on commit 59579ae

Please sign in to comment.