Skip to content

Commit

Permalink
clean up literals
Browse files Browse the repository at this point in the history
  • Loading branch information
callebtc committed Jan 7, 2024
1 parent 32461b7 commit 9cfc2f7
Showing 1 changed file with 32 additions and 14 deletions.
46 changes: 32 additions & 14 deletions cashu/mint/ledger.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ async def mint_quote(self, quote_request: PostMintQuoteRequest) -> MintQuote:
if settings.mint_peg_out_only:
raise NotAllowedError("Mint does not allow minting new tokens.")
unit = Unit[quote_request.unit]
method = Method["bolt11"]
method = Method.bolt11
if settings.mint_max_balance:
balance = await self.get_balance()
if balance + quote_request.amount > settings.mint_max_balance:
Expand All @@ -313,7 +313,7 @@ async def mint_quote(self, quote_request: PostMintQuoteRequest) -> MintQuote:
unit
].create_invoice(Amount(unit=unit, amount=quote_request.amount))
logger.trace(
f"got invoice {invoice_response.payment_request} with check id"
f"got invoice {invoice_response.payment_request} with checking id"
f" {invoice_response.checking_id}"
)

Expand All @@ -326,7 +326,7 @@ async def mint_quote(self, quote_request: PostMintQuoteRequest) -> MintQuote:

quote = MintQuote(
quote=random_hash(),
method="bolt11",
method=method.name,
request=invoice_response.payment_request,
checking_id=invoice_response.checking_id,
unit=quote_request.unit,
Expand Down Expand Up @@ -356,7 +356,7 @@ async def get_mint_quote(self, quote_id: str) -> MintQuote:
"""
quote = await self.crud.get_mint_quote(quote_id=quote_id, db=self.db)
assert quote, "quote not found"
assert quote.method == "bolt11", "only bolt11 supported"
assert quote.method == Method.bolt11.name, "only bolt11 supported"
unit = Unit[quote.unit]
method = Method[quote.method]

Expand All @@ -382,14 +382,15 @@ async def mint(
Args:
outputs (List[BlindedMessage]): Outputs (blinded messages) to sign.
quote_id (str): Quote id of mint payment.
quote_id (str): Mint quote id.
keyset (Optional[MintKeyset], optional): Keyset to use. If not provided, uses active keyset. Defaults to None.
Raises:
Exception: Lightning invoice is not paid.
Exception: Lightning is turned on but no payment hash is provided.
Exception: Something went wrong with the invoice check.
Exception: Amount too large.
Exception: Validation of outputs failed.
Exception: Quote not paid.
Exception: Quote already issued.
Exception: Quote expired.
Exception: Amount to mint does not match quote amount.
Returns:
List[BlindedSignature]: Signatures on the outputs.
Expand Down Expand Up @@ -428,11 +429,16 @@ async def melt_quote(
Args:
melt_quote (PostMeltQuoteRequest): Melt quote request.
Raises:
Exception: Quote invalid.
Exception: Quote already paid.
Exception: Quote already issued.
Returns:
PostMeltQuoteResponse: Melt quote response.
"""
unit = Unit[melt_quote.unit]
method = Method["bolt11"]
method = Method.bolt11
invoice_obj = bolt11.decode(melt_quote.request)
assert invoice_obj.amount_msat, "invoice has no amount."

Expand Down Expand Up @@ -473,7 +479,7 @@ async def melt_quote(

quote = MeltQuote(
quote=random_hash(),
method="bolt11",
method=method.name,
request=melt_quote.request,
checking_id=payment_quote.checking_id,
unit=melt_quote.unit,
Expand All @@ -493,9 +499,9 @@ async def melt_quote(
async def get_melt_quote(self, quote_id: str) -> MeltQuote:
"""Returns a melt quote.
If it is not paid yet, checks with the backend for the payment state of the melt request.
If melt quote is not paid yet, checks with the backend for the state of the payment request.
Updates the melt quote in the database.
If the quote has been paid, updates the melt quote in the database.
Args:
quote_id (str): ID of the melt quote.
Expand All @@ -508,7 +514,7 @@ async def get_melt_quote(self, quote_id: str) -> MeltQuote:
"""
melt_quote = await self.crud.get_melt_quote(quote_id=quote_id, db=self.db)
assert melt_quote, "quote not found"
assert melt_quote.method == "bolt11", "only bolt11 supported"
assert melt_quote.method == Method.bolt11.name, "only bolt11 supported"
unit = Unit[melt_quote.unit]
method = Method[melt_quote.method]

Expand Down Expand Up @@ -539,6 +545,18 @@ async def get_melt_quote(self, quote_id: str) -> MeltQuote:
return melt_quote

async def melt_mint_settle_internally(self, melt_quote: MeltQuote) -> MeltQuote:
"""Settles a melt quote internally if there is a mint quote with the same payment request.
Args:
melt_quote (MeltQuote): Melt quote to settle.
Raises:
Exception: Melt quote already paid.
Exception: Melt quote already issued.
Returns:
MeltQuote: Settled melt quote.
"""
# first we check if there is a mint quote with the same payment request
# so that we can handle the transaction internally without the backend
mint_quote = await self.crud.get_mint_quote_by_checking_id(
Expand Down

0 comments on commit 9cfc2f7

Please sign in to comment.