Skip to content

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
callebtc committed Sep 22, 2023
1 parent 17fa6f1 commit 6703367
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
6 changes: 3 additions & 3 deletions cashu/mint/conditions.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def _verify_input_spending_conditions(self, proof: Proof) -> bool:
Verify spending conditions:
Condition: P2SH - Witnesses proof.p2shscript
Condition: P2PK - Witness: proof.p2pksigs
Condition: HTLC - Witness: proof.htlcpreimage, proof.htlcsignature
"""
# P2SH
try:
Expand Down Expand Up @@ -201,9 +201,9 @@ def _verify_output_spending_conditions(
"""
Verify spending conditions:
Condition: P2PK - Witness: output.p2pksigs
"""
# P2SH

# P2PK
pubkeys_per_proof = []
n_sigs = []
for proof in proofs:
Expand Down
19 changes: 10 additions & 9 deletions cashu/mint/ledger.py
Original file line number Diff line number Diff line change
Expand Up @@ -600,11 +600,7 @@ async def melt(
await self._set_proofs_pending(proofs)

try:
self._check_proofs_spendable(proofs)

await self._verify_proofs_and_outputs(proofs)
logger.trace("verified proofs")

# verify amounts
total_provided = sum_proofs(proofs)
invoice_obj = bolt11.decode(invoice)
invoice_amount = math.ceil(invoice_obj.amount_msat / 1000)
Expand All @@ -613,13 +609,18 @@ async def melt(
f"Maximum melt amount is {settings.mint_max_peg_out} sat."
)
fees_msat = await self.check_fees(invoice)
# verify overspending attempt
assert (
total_provided >= invoice_amount + fees_msat / 1000
), TransactionError("provided proofs not enough for Lightning payment.")

# verify that proofs have not been spent yet
self._check_proofs_spendable(proofs)
# verify spending inputs, outputs, and spending conditions
await self._verify_proofs_and_outputs(proofs, outputs)

# promises to return for overpaid fees
return_promises: List[BlindedSignature] = []

if settings.lightning:
logger.trace("paying lightning invoice")
status, preimage, fee_msat = await self._pay_lightning_invoice(
Expand Down Expand Up @@ -739,13 +740,13 @@ async def split(
total_amount = sum_proofs(proofs)

try:
self._check_proofs_spendable(proofs)

# verify that amount is kosher
self._verify_amount(total_amount)

# verify overspending attempt
self._verify_equation_balanced(proofs, outputs)
# verify that proofs have not been spent yet
self._check_proofs_spendable(proofs)
# verify spending inputs, outputs, and spending conditions
await self._verify_proofs_and_outputs(proofs, outputs)
# Mark proofs as used and prepare new promises
await self._invalidate_proofs(proofs)
Expand Down

0 comments on commit 6703367

Please sign in to comment.