NUT-04 and NUT-05: Add state field to quotes (#560)

* wip adding states, tests failing

* add state field to quotes

* responses from quotes

* store correct state

* cleaner test

* fix swap check

* oops
This commit is contained in:
callebtc
2024-06-26 03:06:01 +02:00
committed by GitHub
parent e846acf946
commit 6b38ef6c29
26 changed files with 330 additions and 84 deletions

View File

@@ -15,7 +15,7 @@ import click
from click import Context
from loguru import logger
from ...core.base import Invoice, Method, TokenV3, Unit
from ...core.base import Invoice, Method, MintQuoteState, TokenV3, Unit
from ...core.helpers import sum_proofs
from ...core.json_rpc.base import JSONRPCNotficationParams
from ...core.logging import configure_logger
@@ -296,8 +296,10 @@ async def invoice(ctx: Context, amount: float, id: str, split: int, no_check: bo
except Exception:
return
logger.debug(f"Received callback for quote: {quote}")
# we need to sleep to give the callback map some time to be populated
time.sleep(0.1)
if (
quote.paid
(quote.paid or quote.state == MintQuoteState.paid.value)
and quote.request == invoice.bolt11
and msg.subId in subscription.callback_map.keys()
):
@@ -310,6 +312,9 @@ async def invoice(ctx: Context, amount: float, id: str, split: int, no_check: bo
except Exception as e:
print(f"Error during mint: {str(e)}")
return
else:
logger.debug("Quote not paid yet.")
return
# user requests an invoice
if amount and not id: