mirror of
https://github.com/aljazceru/nutshell.git
synced 2025-12-20 02:24:20 +01:00
wallet can now handle PostMeltResponse_deprecated from v1 api (#642)
This commit is contained in:
@@ -7,6 +7,7 @@ import bolt11
|
|||||||
import httpx
|
import httpx
|
||||||
from httpx import Response
|
from httpx import Response
|
||||||
from loguru import logger
|
from loguru import logger
|
||||||
|
from pydantic import ValidationError
|
||||||
|
|
||||||
from ..core.base import (
|
from ..core.base import (
|
||||||
BlindedMessage,
|
BlindedMessage,
|
||||||
@@ -467,14 +468,26 @@ class LedgerAPI(LedgerAPIDeprecated):
|
|||||||
json=payload.dict(include=_meltrequest_include_fields(proofs, outputs)), # type: ignore
|
json=payload.dict(include=_meltrequest_include_fields(proofs, outputs)), # type: ignore
|
||||||
timeout=None,
|
timeout=None,
|
||||||
)
|
)
|
||||||
# BEGIN backwards compatibility < 0.15.0
|
try:
|
||||||
# assume the mint has not upgraded yet if we get a 404
|
self.raise_on_error_request(resp)
|
||||||
if resp.status_code == 404:
|
return_dict = resp.json()
|
||||||
invoice = await get_lightning_invoice(id=quote, db=self.db)
|
return PostMeltQuoteResponse.parse_obj(return_dict)
|
||||||
assert invoice, f"no invoice found for id {quote}"
|
except Exception as e:
|
||||||
ret: PostMeltResponse_deprecated = await self.melt_deprecated(
|
# BEGIN backwards compatibility < 0.15.0
|
||||||
proofs=proofs, outputs=outputs, invoice=invoice.bolt11
|
# 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(
|
return PostMeltQuoteResponse(
|
||||||
quote=quote,
|
quote=quote,
|
||||||
amount=0,
|
amount=0,
|
||||||
@@ -489,10 +502,7 @@ class LedgerAPI(LedgerAPIDeprecated):
|
|||||||
change=ret.change,
|
change=ret.change,
|
||||||
expiry=None,
|
expiry=None,
|
||||||
)
|
)
|
||||||
# END backwards compatibility < 0.15.0
|
# END backwards compatibility < 0.15.0
|
||||||
self.raise_on_error_request(resp)
|
|
||||||
return_dict = resp.json()
|
|
||||||
return PostMeltQuoteResponse.parse_obj(return_dict)
|
|
||||||
|
|
||||||
@async_set_httpx_client
|
@async_set_httpx_client
|
||||||
@async_ensure_mint_loaded
|
@async_ensure_mint_loaded
|
||||||
|
|||||||
Reference in New Issue
Block a user