Skip to content

Commit

Permalink
wallet can now handle PostMeltResponse_deprecated from v1 api
Browse files Browse the repository at this point in the history
  • Loading branch information
callebtc committed Oct 14, 2024
1 parent 4490cc6 commit 0092891
Showing 1 changed file with 22 additions and 12 deletions.
34 changes: 22 additions & 12 deletions cashu/wallet/v1_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import httpx
from httpx import Response
from loguru import logger
from pydantic import ValidationError

from ..core.base import (
BlindedMessage,
Expand Down Expand Up @@ -467,14 +468,26 @@ def _meltrequest_include_fields(
json=payload.dict(include=_meltrequest_include_fields(proofs, outputs)), # type: ignore
timeout=None,
)
# BEGIN backwards compatibility < 0.15.0
# assume the mint has not upgraded yet if we get a 404
if resp.status_code == 404:
invoice = await get_lightning_invoice(id=quote, db=self.db)
assert invoice, f"no invoice found for id {quote}"
ret: PostMeltResponse_deprecated = await self.melt_deprecated(
proofs=proofs, outputs=outputs, invoice=invoice.bolt11
)
try:
self.raise_on_error_request(resp)
return_dict = resp.json()
return PostMeltQuoteResponse.parse_obj(return_dict)
except Exception as e:
# BEGIN backwards compatibility < 0.15.0
# assume the mint has not upgraded yet if we get a 404
if resp.status_code == 404:
invoice = await get_lightning_invoice(id=quote, db=self.db)
assert invoice, f"no invoice found for id {quote}"
ret: PostMeltResponse_deprecated = await self.melt_deprecated(
proofs=proofs, outputs=outputs, invoice=invoice.bolt11
)
elif isinstance(e, ValidationError):
# BEGIN backwards compatibility < 0.16.0
# before 0.16.0, mints return PostMeltResponse_deprecated
ret = PostMeltResponse_deprecated.parse_obj(return_dict)
# END backwards compatibility < 0.16.0
else:
raise e
return PostMeltQuoteResponse(
quote=quote,
amount=0,
Expand All @@ -489,10 +502,7 @@ def _meltrequest_include_fields(
change=ret.change,
expiry=None,
)
# END backwards compatibility < 0.15.0
self.raise_on_error_request(resp)
return_dict = resp.json()
return PostMeltQuoteResponse.parse_obj(return_dict)
# END backwards compatibility < 0.15.0

@async_set_httpx_client
@async_ensure_mint_loaded
Expand Down

0 comments on commit 0092891

Please sign in to comment.