From 39aa84987a12a1a8ab66bc9fde6c8d5e44231d7d Mon Sep 17 00:00:00 2001 From: lollerfirst Date: Sat, 21 Sep 2024 21:04:43 +0200 Subject: [PATCH] fix order of `sorted_merkle_hash` --- cashu/core/crypto/dlc.py | 2 +- cashu/mint/db/write.py | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/cashu/core/crypto/dlc.py b/cashu/core/crypto/dlc.py index bf21694c..49f3c10c 100644 --- a/cashu/core/crypto/dlc.py +++ b/cashu/core/crypto/dlc.py @@ -8,7 +8,7 @@ def sorted_merkle_hash(left: bytes, right: bytes) -> bytes: '''Sorts `left` and `right` in non-ascending order and computes the hash of their concatenation ''' - if left < right: + if right < left: left, right = right, left return sha256(left+right).digest() diff --git a/cashu/mint/db/write.py b/cashu/mint/db/write.py index 279a2047..add0e774 100644 --- a/cashu/mint/db/write.py +++ b/cashu/mint/db/write.py @@ -374,16 +374,16 @@ async def _verify_and_update_dlc_payouts( eligible_amount = dlc.debts[payout.pubkey] # Verify the amount of the blind messages is LEQ than the eligible amount - if blind_messages_amount > eligible_amount: + if blind_messages_amount != eligible_amount: raise DlcPayoutFail(detail=f"amount requested ({blind_messages_amount}) is bigger than eligible amount ({eligible_amount})") - # Discriminate what to do next based on whether the requested amount is exact or less - if blind_messages_amount == eligible_amount: - del dlc.debts[payout.pubkey] - else: - dlc.debts[payout.pubkey] -= blind_messages_amount + # Remove the payout from the map + del dlc.debts[payout.pubkey] + # Update the database await self.crud.set_dlc_settled_and_debts(dlc.dlc_root, json.dumps(dlc.debts), self.db, conn) + + # Append payout to verified results verified.append(payout) except (CashuError, Exception) as e: errors.append(DlcPayout(