From 3c334d299ae8784588e07f02062c55d0762f2a86 Mon Sep 17 00:00:00 2001 From: sihamon Date: Fri, 8 Sep 2023 22:28:02 +0200 Subject: [PATCH] Store preimage as well --- cashu/mint/crud.py | 6 ++++-- cashu/mint/ledger.py | 4 +++- cashu/mint/migrations.py | 3 ++- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/cashu/mint/crud.py b/cashu/mint/crud.py index 4d56ca20..68e0f3cf 100644 --- a/cashu/mint/crud.py +++ b/cashu/mint/crud.py @@ -273,19 +273,21 @@ async def get_keyset( async def store_invoice_and_proofs( db: Database, invoice: bolt11_invoice, + preimage: str, proof: Proof, conn: Optional[Connection] = None, ): await (conn or db).execute( f""" INSERT INTO {table_with_schema(db, 'payments')} - (invoice_amount, date, payment_hash, proof_amount, proof_C, proof_secret) - VALUES (?, ?, ?, ?, ?, ?) + (invoice_amount, date, payment_hash, preimage, proof_amount, proof_C, proof_secret) + VALUES (?, ?, ?, ?, ?, ?, ?) """, ( invoice.amount_msat / 1000, invoice.date, invoice.payment_hash, + preimage, proof.amount, proof.C, proof.secret, diff --git a/cashu/mint/ledger.py b/cashu/mint/ledger.py index 2e0abeda..f5fbdc43 100644 --- a/cashu/mint/ledger.py +++ b/cashu/mint/ledger.py @@ -956,7 +956,9 @@ async def melt( if status: for p in proofs: - await self.crud.store_invoice_and_proofs(self.db, invoice_obj, p) + await self.crud.store_invoice_and_proofs( + self.db, invoice_obj, preimage, p + ) logger.trace("invalidating proofs") await self._invalidate_proofs(proofs) logger.trace("invalidated proofs") diff --git a/cashu/mint/migrations.py b/cashu/mint/migrations.py index 3c0046c3..48547400 100644 --- a/cashu/mint/migrations.py +++ b/cashu/mint/migrations.py @@ -167,7 +167,8 @@ async def m008_paid_invoices_and_proofs(db: Database): invoice_amount {db.big_int} NOT NULL, date TEXT NOT NULL, payment_hash TEXT NOT NULL, - proof_amount TEXT NOT NULL, + preimage TEXT NOT NULL, + proof_amount {db.big_int} NOT NULL, proof_C TEXT NOT NULL, proof_secret TEXT NOT NULL,