Skip to content

Commit

Permalink
remove output.id optional
Browse files Browse the repository at this point in the history
  • Loading branch information
callebtc committed Apr 8, 2024
1 parent 3b2f1aa commit 5d7c26e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 18 deletions.
16 changes: 7 additions & 9 deletions cashu/core/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)

Expand Down
23 changes: 14 additions & 9 deletions cashu/mint/ledger.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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"
Expand Down Expand Up @@ -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}")
Expand Down

0 comments on commit 5d7c26e

Please sign in to comment.