diff --git a/cashu/core/base.py b/cashu/core/base.py index 66b4bce8..7253c515 100644 --- a/cashu/core/base.py +++ b/cashu/core/base.py @@ -274,6 +274,7 @@ class Invoice(BaseModel): paid: Union[None, bool] = False time_created: Union[None, str, int, float] = "" time_paid: Union[None, str, int, float] = "" + mint: Union[None, str] = None class MeltQuoteState(Enum): diff --git a/cashu/wallet/crud.py b/cashu/wallet/crud.py index 62b5456e..0b8562d8 100644 --- a/cashu/wallet/crud.py +++ b/cashu/wallet/crud.py @@ -246,8 +246,8 @@ async def store_lightning_invoice( await (conn or db).execute( """ INSERT INTO invoices - (amount, bolt11, id, payment_hash, preimage, paid, time_created, time_paid, out) - VALUES (:amount, :bolt11, :id, :payment_hash, :preimage, :paid, :time_created, :time_paid, :out) + (amount, bolt11, id, payment_hash, preimage, paid, time_created, time_paid, out, mint) + VALUES (:amount, :bolt11, :id, :payment_hash, :preimage, :paid, :time_created, :time_paid, :out, :mint) """, { "amount": invoice.amount, @@ -259,6 +259,7 @@ async def store_lightning_invoice( "time_created": invoice.time_created, "time_paid": invoice.time_paid, "out": invoice.out, + "mint": invoice.mint, }, ) @@ -301,6 +302,7 @@ async def get_lightning_invoices( db: Database, paid: Optional[bool] = None, pending: Optional[bool] = None, + mint: Optional[str] = None, conn: Optional[Connection] = None, ) -> List[Invoice]: clauses = [] @@ -316,6 +318,10 @@ async def get_lightning_invoices( clauses.append("out = :out") values["out"] = False + if mint: + clauses.append("mint = :mint") + values["mint"] = mint + where = "" if clauses: where = f"WHERE {' AND '.join(clauses)}" diff --git a/cashu/wallet/migrations.py b/cashu/wallet/migrations.py index 41937318..12104c5f 100644 --- a/cashu/wallet/migrations.py +++ b/cashu/wallet/migrations.py @@ -245,6 +245,12 @@ async def m012_add_fee_to_keysets(db: Database): await conn.execute("UPDATE keysets SET input_fee_ppk = 0") +async def m013_add_mint_column_invoices(db: Database): + async with db.connect() as conn: + # add column for storing the mint of an invoice + await conn.execute("ALTER TABLE invoices ADD COLUMN mint TEXT") + + # # async def m020_add_state_to_mint_and_melt_quotes(db: Database): # # async with db.connect() as conn: # # await conn.execute( diff --git a/cashu/wallet/wallet.py b/cashu/wallet/wallet.py index 6533aac2..f4de24ec 100644 --- a/cashu/wallet/wallet.py +++ b/cashu/wallet/wallet.py @@ -411,6 +411,7 @@ async def request_mint_with_callback( id=mint_qoute.quote, out=False, time_created=int(time.time()), + mint=self.url, ) await store_lightning_invoice(db=self.db, invoice=invoice) return invoice, subscriptions @@ -435,6 +436,7 @@ async def request_mint(self, amount: int, memo: Optional[str] = None) -> Invoice id=mint_quote_response.quote, out=False, time_created=int(time.time()), + mint=self.url, ) await store_lightning_invoice(db=self.db, invoice=invoice) return invoice @@ -502,6 +504,7 @@ async def mint_quote(self, amount: int, memo: Optional[str] = None) -> Invoice: id=mint_quote_response.quote, out=False, time_created=int(time.time()), + mint=self.url, ) await store_lightning_invoice(db=self.db, invoice=invoice) return invoice @@ -775,6 +778,7 @@ async def melt( time_paid=int(time.time()), id=quote_id, # store the same ID in the invoice out=True, # outgoing invoice + mint=self.url, ) # store invoice in db as not paid yet await store_lightning_invoice(db=self.db, invoice=invoice_obj)