mirror of
https://github.com/aljazceru/nutshell.git
synced 2026-01-04 17:34:20 +01:00
WIP: New melt flow (#622)
* `PaymentResult` * ledger: rely on PaymentResult instead of paid flag. Double check for payments marked pending. * `None` is `PENDING` * make format * reflected changes API tests where `PaymentStatus` is used + reflected changes in lnbits * reflect changes in blink backend and tests * fix lnbits get_payment_status * remove paid flag * fix mypy * remove more paid flags * fix strike mypy * green * shorten all state checks * fix * fix some tests * gimme ✅ * fix............ * fix lnbits * fix error * lightning refactor * add more regtest tests * add tests for pending state and failure * shorten checks * use match case for startup check - and remember modified checking_id from pay_invoice * fix strike pending return * new tests? * refactor startup routine into get_melt_quote * test with purge * refactor blink * cleanup responses * blink: return checking_id on failure * fix lndgrpc try except * add more testing for melt branches * speed things up a bit * remove comments * remove comments * block pending melt quotes * remove comments --------- Co-authored-by: lollerfirst <lollerfirst@gmail.com>
This commit is contained in:
@@ -201,16 +201,6 @@ class LedgerCrud(ABC):
|
||||
) -> None:
|
||||
...
|
||||
|
||||
# @abstractmethod
|
||||
# async def update_mint_quote_paid(
|
||||
# self,
|
||||
# *,
|
||||
# quote_id: str,
|
||||
# paid: bool,
|
||||
# db: Database,
|
||||
# conn: Optional[Connection] = None,
|
||||
# ) -> None: ...
|
||||
|
||||
@abstractmethod
|
||||
async def store_melt_quote(
|
||||
self,
|
||||
@@ -233,6 +223,16 @@ class LedgerCrud(ABC):
|
||||
) -> Optional[MeltQuote]:
|
||||
...
|
||||
|
||||
@abstractmethod
|
||||
async def get_melt_quote_by_request(
|
||||
self,
|
||||
*,
|
||||
request: str,
|
||||
db: Database,
|
||||
conn: Optional[Connection] = None,
|
||||
) -> Optional[MeltQuote]:
|
||||
...
|
||||
|
||||
@abstractmethod
|
||||
async def update_melt_quote(
|
||||
self,
|
||||
@@ -433,8 +433,8 @@ class LedgerCrudSqlite(LedgerCrud):
|
||||
await (conn or db).execute(
|
||||
f"""
|
||||
INSERT INTO {db.table_with_schema('mint_quotes')}
|
||||
(quote, method, request, checking_id, unit, amount, issued, paid, state, created_time, paid_time)
|
||||
VALUES (:quote, :method, :request, :checking_id, :unit, :amount, :issued, :paid, :state, :created_time, :paid_time)
|
||||
(quote, method, request, checking_id, unit, amount, issued, state, created_time, paid_time)
|
||||
VALUES (:quote, :method, :request, :checking_id, :unit, :amount, :issued, :state, :created_time, :paid_time)
|
||||
""",
|
||||
{
|
||||
"quote": quote.quote,
|
||||
@@ -443,8 +443,7 @@ class LedgerCrudSqlite(LedgerCrud):
|
||||
"checking_id": quote.checking_id,
|
||||
"unit": quote.unit,
|
||||
"amount": quote.amount,
|
||||
"issued": quote.issued,
|
||||
"paid": quote.paid,
|
||||
"issued": quote.issued, # this is deprecated! we need to store it because we have a NOT NULL constraint | we could also remove the column but sqlite doesn't support that (we would have to make a new table)
|
||||
"state": quote.state.name,
|
||||
"created_time": db.to_timestamp(
|
||||
db.timestamp_from_seconds(quote.created_time) or ""
|
||||
@@ -513,10 +512,8 @@ class LedgerCrudSqlite(LedgerCrud):
|
||||
conn: Optional[Connection] = None,
|
||||
) -> None:
|
||||
await (conn or db).execute(
|
||||
f"UPDATE {db.table_with_schema('mint_quotes')} SET issued = :issued, paid = :paid, state = :state, paid_time = :paid_time WHERE quote = :quote",
|
||||
f"UPDATE {db.table_with_schema('mint_quotes')} SET state = :state, paid_time = :paid_time WHERE quote = :quote",
|
||||
{
|
||||
"issued": quote.issued,
|
||||
"paid": quote.paid,
|
||||
"state": quote.state.name,
|
||||
"paid_time": db.to_timestamp(
|
||||
db.timestamp_from_seconds(quote.paid_time) or ""
|
||||
@@ -525,23 +522,6 @@ class LedgerCrudSqlite(LedgerCrud):
|
||||
},
|
||||
)
|
||||
|
||||
# async def update_mint_quote_paid(
|
||||
# self,
|
||||
# *,
|
||||
# quote_id: str,
|
||||
# paid: bool,
|
||||
# db: Database,
|
||||
# conn: Optional[Connection] = None,
|
||||
# ) -> None:
|
||||
# await (conn or db).execute(
|
||||
# f"UPDATE {db.table_with_schema('mint_quotes')} SET paid = ? WHERE"
|
||||
# " quote = ?",
|
||||
# (
|
||||
# paid,
|
||||
# quote_id,
|
||||
# ),
|
||||
# )
|
||||
|
||||
async def store_melt_quote(
|
||||
self,
|
||||
*,
|
||||
@@ -552,8 +532,8 @@ class LedgerCrudSqlite(LedgerCrud):
|
||||
await (conn or db).execute(
|
||||
f"""
|
||||
INSERT INTO {db.table_with_schema('melt_quotes')}
|
||||
(quote, method, request, checking_id, unit, amount, fee_reserve, paid, state, created_time, paid_time, fee_paid, proof, change, expiry)
|
||||
VALUES (:quote, :method, :request, :checking_id, :unit, :amount, :fee_reserve, :paid, :state, :created_time, :paid_time, :fee_paid, :proof, :change, :expiry)
|
||||
(quote, method, request, checking_id, unit, amount, fee_reserve, state, created_time, paid_time, fee_paid, proof, change, expiry)
|
||||
VALUES (:quote, :method, :request, :checking_id, :unit, :amount, :fee_reserve, :state, :created_time, :paid_time, :fee_paid, :proof, :change, :expiry)
|
||||
""",
|
||||
{
|
||||
"quote": quote.quote,
|
||||
@@ -563,7 +543,6 @@ class LedgerCrudSqlite(LedgerCrud):
|
||||
"unit": quote.unit,
|
||||
"amount": quote.amount,
|
||||
"fee_reserve": quote.fee_reserve or 0,
|
||||
"paid": quote.paid,
|
||||
"state": quote.state.name,
|
||||
"created_time": db.to_timestamp(
|
||||
db.timestamp_from_seconds(quote.created_time) or ""
|
||||
@@ -610,8 +589,22 @@ class LedgerCrudSqlite(LedgerCrud):
|
||||
""",
|
||||
values,
|
||||
)
|
||||
if row is None:
|
||||
return None
|
||||
return MeltQuote.from_row(row) if row else None
|
||||
|
||||
async def get_melt_quote_by_request(
|
||||
self,
|
||||
*,
|
||||
request: str,
|
||||
db: Database,
|
||||
conn: Optional[Connection] = None,
|
||||
) -> Optional[MeltQuote]:
|
||||
row = await (conn or db).fetchone(
|
||||
f"""
|
||||
SELECT * from {db.table_with_schema('melt_quotes')}
|
||||
WHERE request = :request
|
||||
""",
|
||||
{"request": request},
|
||||
)
|
||||
return MeltQuote.from_row(row) if row else None
|
||||
|
||||
async def update_melt_quote(
|
||||
@@ -623,10 +616,9 @@ class LedgerCrudSqlite(LedgerCrud):
|
||||
) -> None:
|
||||
await (conn or db).execute(
|
||||
f"""
|
||||
UPDATE {db.table_with_schema('melt_quotes')} SET paid = :paid, state = :state, fee_paid = :fee_paid, paid_time = :paid_time, proof = :proof, change = :change WHERE quote = :quote
|
||||
UPDATE {db.table_with_schema('melt_quotes')} SET state = :state, fee_paid = :fee_paid, paid_time = :paid_time, proof = :proof, change = :change, checking_id = :checking_id WHERE quote = :quote
|
||||
""",
|
||||
{
|
||||
"paid": quote.paid,
|
||||
"state": quote.state.name,
|
||||
"fee_paid": quote.fee_paid,
|
||||
"paid_time": db.to_timestamp(
|
||||
@@ -637,6 +629,7 @@ class LedgerCrudSqlite(LedgerCrud):
|
||||
if quote.change
|
||||
else None,
|
||||
"quote": quote.quote,
|
||||
"checking_id": quote.checking_id,
|
||||
},
|
||||
)
|
||||
|
||||
@@ -678,7 +671,7 @@ class LedgerCrudSqlite(LedgerCrud):
|
||||
db: Database,
|
||||
conn: Optional[Connection] = None,
|
||||
) -> int:
|
||||
row = await (conn or db).fetchone(
|
||||
row: List = await (conn or db).fetchone(
|
||||
f"""
|
||||
SELECT * from {db.table_with_schema('balance')}
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user