From 5d7c26e1fb61af6bbf66c1b3fad914952e2689e9 Mon Sep 17 00:00:00 2001 From: callebtc <93376500+callebtc@users.noreply.github.com> Date: Mon, 8 Apr 2024 17:37:02 +0200 Subject: [PATCH] remove output.id optional --- cashu/core/base.py | 16 +++++++--------- cashu/mint/ledger.py | 23 ++++++++++++++--------- 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/cashu/core/base.py b/cashu/core/base.py index f6375f9e..25087588 100644 --- a/cashu/core/base.py +++ b/cashu/core/base.py @@ -101,12 +101,12 @@ class Proof(BaseModel): time_created: Union[None, str] = "" time_reserved: Union[None, str] = "" derivation_path: Union[None, str] = "" # derivation path of the proof - mint_id: Union[None, str] = ( - None # holds the id of the mint operation that created this proof - ) - melt_id: Union[None, str] = ( - None # holds the id of the melt operation that destroyed this proof - ) + mint_id: Union[ + None, str + ] = None # holds the id of the mint operation that created this proof + melt_id: Union[ + None, str + ] = None # holds the id of the melt operation that destroyed this proof def __init__(self, **data): super().__init__(**data) @@ -172,9 +172,7 @@ class BlindedMessage(BaseModel): """ amount: int - id: Optional[ - str - ] # DEPRECATION: Only Optional for backwards compatibility with old clients < 0.15 for deprecated API route. + id: str B_: str # Hex-encoded blinded message witness: Union[str, None] = None # witnesses (used for P2PK with SIG_ALL) diff --git a/cashu/mint/ledger.py b/cashu/mint/ledger.py index c4f2ea02..c885d7ea 100644 --- a/cashu/mint/ledger.py +++ b/cashu/mint/ledger.py @@ -517,6 +517,9 @@ async def mint( logger.trace("called mint") await self._verify_outputs(outputs) sum_amount_outputs = sum([b.amount for b in outputs]) + output_units = set([k.unit for k in [self.keysets[o.id] for o in outputs]]) + assert len(output_units) == 1, "outputs have different units" + output_unit = list(output_units)[0] self.locks[quote_id] = ( self.locks.get(quote_id) or asyncio.Lock() @@ -525,6 +528,9 @@ async def mint( quote = await self.get_mint_quote(quote_id=quote_id) assert quote.paid, QuoteNotPaidError() assert not quote.issued, "quote already issued" + assert ( + quote.unit == output_unit.name + ), "quote unit does not match output unit" assert ( quote.amount == sum_amount_outputs ), "amount to mint does not match quote amount" @@ -871,22 +877,21 @@ async def split( Tuple[List[BlindSignature],List[BlindSignature]]: Promises on both sides of the split. """ logger.trace("split called") + # explicitly check that amount of inputs is equal to amount of outputs + # note: we check this again in verify_inputs_and_outputs but only if any + # outputs are provided at all. To make sure of that before calling + # verify_inputs_and_outputs, we check it here. + self._verify_equation_balanced(proofs, outputs) + # verify spending inputs, outputs, and spending conditions + await self.verify_inputs_and_outputs(proofs=proofs, outputs=outputs) await self._set_proofs_pending(proofs) try: - # explicitly check that amount of inputs is equal to amount of outputs - # note: we check this again in verify_inputs_and_outputs but only if any - # outputs are provided at all. To make sure of that before calling - # verify_inputs_and_outputs, we check it here. - self._verify_equation_balanced(proofs, outputs) - # verify spending inputs, outputs, and spending conditions - await self.verify_inputs_and_outputs(proofs=proofs, outputs=outputs) - # Mark proofs as used and prepare new promises async with get_db_connection(self.db) as conn: # we do this in a single db transaction - promises = await self._generate_promises(outputs, keyset, conn) await self._invalidate_proofs(proofs=proofs, conn=conn) + promises = await self._generate_promises(outputs, keyset, conn) except Exception as e: logger.trace(f"split failed: {e}")