diff --git a/cashu/core/base.py b/cashu/core/base.py index 9ac14185..f6375f9e 100644 --- a/cashu/core/base.py +++ b/cashu/core/base.py @@ -199,8 +199,8 @@ def from_row(cls, row: Row): return cls( id=row["id"], amount=row["amount"], - C_=row["C_"], - dleq=DLEQ(e=row["e"], s=row["s"]), + C_=row["c_"], + dleq=DLEQ(e=row["dleq_e"], s=row["dleq_s"]), ) diff --git a/cashu/mint/crud.py b/cashu/mint/crud.py index 234e5f9e..30d30b1c 100644 --- a/cashu/mint/crud.py +++ b/cashu/mint/crud.py @@ -129,8 +129,8 @@ async def store_promise( *, db: Database, amount: int, - B_: str, - C_: str, + b_: str, + c_: str, id: str, e: str = "", s: str = "", @@ -142,7 +142,7 @@ async def get_promise( self, *, db: Database, - B_: str, + b_: str, conn: Optional[Connection] = None, ) -> Optional[BlindedSignature]: ... @@ -233,8 +233,8 @@ async def store_promise( *, db: Database, amount: int, - B_: str, - C_: str, + b_: str, + c_: str, id: str, e: str = "", s: str = "", @@ -243,13 +243,13 @@ async def store_promise( await (conn or db).execute( f""" INSERT INTO {table_with_schema(db, 'promises')} - (amount, B_, C_, e, s, id, created) + (amount, b_, c_, dleq_e, dleq_s, id, created) VALUES (?, ?, ?, ?, ?, ?, ?) """, ( amount, - B_, - C_, + b_, + c_, e, s, id, @@ -261,15 +261,15 @@ async def get_promise( self, *, db: Database, - B_: str, + b_: str, conn: Optional[Connection] = None, ) -> Optional[BlindedSignature]: row = await (conn or db).fetchone( f""" SELECT * from {table_with_schema(db, 'promises')} - WHERE B_ = ? + WHERE b_ = ? """, - (str(B_),), + (str(b_),), ) return BlindedSignature.from_row(row) if row else None @@ -298,7 +298,7 @@ async def invalidate_proof( await (conn or db).execute( f""" INSERT INTO {table_with_schema(db, 'proofs_used')} - (amount, C, secret, Y, id, witness, created, melt_quote) + (amount, c, secret, y, id, witness, created, melt_quote) VALUES (?, ?, ?, ?, ?, ?, ?, ?) """, ( @@ -352,7 +352,7 @@ async def get_proofs_pending( rows = await (conn or db).fetchall( f""" SELECT * from {table_with_schema(db, 'proofs_pending')} - WHERE Y IN ({','.join(['?']*len(Ys))}) + WHERE y IN ({','.join(['?']*len(Ys))}) """, tuple(Ys), ) @@ -370,7 +370,7 @@ async def set_proof_pending( await (conn or db).execute( f""" INSERT INTO {table_with_schema(db, 'proofs_pending')} - (amount, C, secret, Y, id, witness, created, melt_quote) + (amount, c, secret, y, id, witness, created, melt_quote) VALUES (?, ?, ?, ?, ?, ?, ?, ?) """, ( @@ -668,7 +668,7 @@ async def get_proof_used( row = await (conn or db).fetchone( f""" SELECT * from {table_with_schema(db, 'proofs_used')} - WHERE Y = ? + WHERE y = ? """, (Y,), ) diff --git a/cashu/mint/ledger.py b/cashu/mint/ledger.py index 506cfe2e..c4f2ea02 100644 --- a/cashu/mint/ledger.py +++ b/cashu/mint/ledger.py @@ -907,7 +907,7 @@ async def restore( for output in outputs: logger.trace(f"looking for promise: {output}") promise = await self.crud.get_promise( - B_=output.B_, db=self.db, conn=conn + b_=output.B_, db=self.db, conn=conn ) if promise is not None: # BEGIN backwards compatibility mints pre `m007_proofs_and_promises_store_id` @@ -974,8 +974,8 @@ async def _generate_promises( await self.crud.store_promise( amount=amount, id=keyset_id, - B_=B_.serialize().hex(), - C_=C_.serialize().hex(), + b_=B_.serialize().hex(), + c_=C_.serialize().hex(), e=e.serialize(), s=s.serialize(), db=self.db, diff --git a/cashu/mint/migrations.py b/cashu/mint/migrations.py index af2cf41b..3f9c5377 100644 --- a/cashu/mint/migrations.py +++ b/cashu/mint/migrations.py @@ -20,10 +20,10 @@ async def m001_initial(db: Database): f""" CREATE TABLE IF NOT EXISTS {table_with_schema(db, 'promises')} ( amount {db.big_int} NOT NULL, - B_b TEXT NOT NULL, - C_b TEXT NOT NULL, + b_b TEXT NOT NULL, + c_b TEXT NOT NULL, - UNIQUE (B_b) + UNIQUE (b_b) ); """ @@ -33,7 +33,7 @@ async def m001_initial(db: Database): f""" CREATE TABLE IF NOT EXISTS {table_with_schema(db, 'proofs_used')} ( amount {db.big_int} NOT NULL, - C TEXT NOT NULL, + c TEXT NOT NULL, secret TEXT NOT NULL, UNIQUE (secret) @@ -129,7 +129,7 @@ async def m003_mint_keysets(db: Database): f""" CREATE TABLE IF NOT EXISTS {table_with_schema(db, 'mint_pubkeys')} ( id TEXT NOT NULL, - amount INTEGER NOT NULL, + amount {db.big_int} NOT NULL, pubkey TEXT NOT NULL, UNIQUE (id, pubkey) @@ -157,8 +157,8 @@ async def m005_pending_proofs_table(db: Database) -> None: await conn.execute( f""" CREATE TABLE IF NOT EXISTS {table_with_schema(db, 'proofs_pending')} ( - amount INTEGER NOT NULL, - C TEXT NOT NULL, + amount {db.big_int} NOT NULL, + c TEXT NOT NULL, secret TEXT NOT NULL, UNIQUE (secret) @@ -283,7 +283,7 @@ async def m011_add_quote_tables(db: Database): request TEXT NOT NULL, checking_id TEXT NOT NULL, unit TEXT NOT NULL, - amount INTEGER NOT NULL, + amount {db.big_int} NOT NULL, paid BOOL NOT NULL, issued BOOL NOT NULL, created_time TIMESTAMP, @@ -303,12 +303,12 @@ async def m011_add_quote_tables(db: Database): request TEXT NOT NULL, checking_id TEXT NOT NULL, unit TEXT NOT NULL, - amount INTEGER NOT NULL, - fee_reserve INTEGER, + amount {db.big_int} NOT NULL, + fee_reserve {db.big_int}, paid BOOL NOT NULL, created_time TIMESTAMP, paid_time TIMESTAMP, - fee_paid INTEGER, + fee_paid {db.big_int}, proof TEXT, UNIQUE (quote) @@ -440,11 +440,11 @@ async def m014_proofs_add_Y_column(db: Database): await drop_balance_views(db, conn) await conn.execute( - f"ALTER TABLE {table_with_schema(db, 'proofs_used')} ADD COLUMN Y TEXT" + f"ALTER TABLE {table_with_schema(db, 'proofs_used')} ADD COLUMN y TEXT" ) for proof in proofs_used: await conn.execute( - f"UPDATE {table_with_schema(db, 'proofs_used')} SET Y = '{proof.Y}'" + f"UPDATE {table_with_schema(db, 'proofs_used')} SET y = '{proof.Y}'" f" WHERE secret = '{proof.secret}'" ) # Copy proofs_used to proofs_used_old and create a new table proofs_used @@ -461,11 +461,11 @@ async def m014_proofs_add_Y_column(db: Database): await conn.execute( f""" CREATE TABLE IF NOT EXISTS {table_with_schema(db, 'proofs_used')} ( - amount INTEGER NOT NULL, - C TEXT NOT NULL, + amount {db.big_int} NOT NULL, + c TEXT NOT NULL, secret TEXT NOT NULL, id TEXT, - Y TEXT, + y TEXT, created TIMESTAMP, witness TEXT, @@ -475,19 +475,19 @@ async def m014_proofs_add_Y_column(db: Database): """ ) await conn.execute( - f"INSERT INTO {table_with_schema(db, 'proofs_used')} (amount, C, " - "secret, id, Y, created, witness) SELECT amount, C, secret, id, Y," + f"INSERT INTO {table_with_schema(db, 'proofs_used')} (amount, c, " + "secret, id, y, created, witness) SELECT amount, c, secret, id, y," f" created, witness FROM {table_with_schema(db, 'proofs_used_old')}" ) await conn.execute(f"DROP TABLE {table_with_schema(db, 'proofs_used_old')}") - # add column Y to proofs_pending + # add column y to proofs_pending await conn.execute( - f"ALTER TABLE {table_with_schema(db, 'proofs_pending')} ADD COLUMN Y TEXT" + f"ALTER TABLE {table_with_schema(db, 'proofs_pending')} ADD COLUMN y TEXT" ) for proof in proofs_pending: await conn.execute( - f"UPDATE {table_with_schema(db, 'proofs_pending')} SET Y = '{proof.Y}'" + f"UPDATE {table_with_schema(db, 'proofs_pending')} SET y = '{proof.Y}'" f" WHERE secret = '{proof.secret}'" ) @@ -507,10 +507,10 @@ async def m014_proofs_add_Y_column(db: Database): await conn.execute( f""" CREATE TABLE IF NOT EXISTS {table_with_schema(db, 'proofs_pending')} ( - amount INTEGER NOT NULL, - C TEXT NOT NULL, + amount {db.big_int} NOT NULL, + c TEXT NOT NULL, secret TEXT NOT NULL, - Y TEXT, + y TEXT, id TEXT, created TIMESTAMP, @@ -520,8 +520,8 @@ async def m014_proofs_add_Y_column(db: Database): """ ) await conn.execute( - f"INSERT INTO {table_with_schema(db, 'proofs_pending')} (amount, C, " - "secret, Y, id, created) SELECT amount, C, secret, Y, id, created" + f"INSERT INTO {table_with_schema(db, 'proofs_pending')} (amount, c, " + "secret, y, id, created) SELECT amount, c, secret, y, id, created" f" FROM {table_with_schema(db, 'proofs_pending_old')}" ) @@ -576,12 +576,12 @@ async def m016_recompute_Y_with_new_h2c(db: Database): f"('{y}', '{secret}')" for y, secret in proofs_used_data ) await conn.execute( - f"INSERT INTO tmp_proofs_used (Y, secret) VALUES {values_placeholder}", + f"INSERT INTO tmp_proofs_used (y, secret) VALUES {values_placeholder}", ) await conn.execute( f""" UPDATE {table_with_schema(db, 'proofs_used')} - SET Y = tmp_proofs_used.Y + SET y = tmp_proofs_used.y FROM tmp_proofs_used WHERE {table_with_schema(db, 'proofs_used')}.secret = tmp_proofs_used.secret """ @@ -596,12 +596,12 @@ async def m016_recompute_Y_with_new_h2c(db: Database): f"('{y}', '{secret}')" for y, secret in proofs_pending_data ) await conn.execute( - f"INSERT INTO tmp_proofs_used (Y, secret) VALUES {values_placeholder}", + f"INSERT INTO tmp_proofs_used (y, secret) VALUES {values_placeholder}", ) await conn.execute( f""" UPDATE {table_with_schema(db, 'proofs_pending')} - SET Y = tmp_proofs_pending.Y + SET y = tmp_proofs_pending.y FROM tmp_proofs_pending WHERE {table_with_schema(db, 'proofs_pending')}.secret = tmp_proofs_pending.secret """ @@ -634,23 +634,23 @@ async def m017_foreign_keys_proof_tables(db: Database): await conn.execute( f""" CREATE TABLE IF NOT EXISTS {table_with_schema(db, 'proofs_used_new')} ( - amount INTEGER NOT NULL, + amount {db.big_int} NOT NULL, id TEXT, - C TEXT NOT NULL, + c TEXT NOT NULL, secret TEXT NOT NULL, - Y TEXT, + y TEXT, witness TEXT, created TIMESTAMP, melt_quote TEXT, FOREIGN KEY (melt_quote) REFERENCES {table_with_schema(db, 'melt_quotes')}(quote), - UNIQUE (Y) + UNIQUE (y) ); """ ) await conn.execute( - f"INSERT INTO {table_with_schema(db, 'proofs_used_new')} (amount, id, C, secret, Y, witness, created) SELECT amount, id, C, secret, Y, witness, created FROM {table_with_schema(db, 'proofs_used')}" + f"INSERT INTO {table_with_schema(db, 'proofs_used_new')} (amount, id, c, secret, y, witness, created) SELECT amount, id, c, secret, y, witness, created FROM {table_with_schema(db, 'proofs_used')}" ) await conn.execute(f"DROP TABLE {table_with_schema(db, 'proofs_used')}") await conn.execute( @@ -661,23 +661,23 @@ async def m017_foreign_keys_proof_tables(db: Database): await conn.execute( f""" CREATE TABLE IF NOT EXISTS {table_with_schema(db, 'proofs_pending_new')} ( - amount INTEGER NOT NULL, + amount {db.big_int} NOT NULL, id TEXT, - C TEXT NOT NULL, + c TEXT NOT NULL, secret TEXT NOT NULL, - Y TEXT, + y TEXT, witness TEXT, created TIMESTAMP, melt_quote TEXT, FOREIGN KEY (melt_quote) REFERENCES {table_with_schema(db, 'melt_quotes')}(quote), - UNIQUE (Y) + UNIQUE (y) ); """ ) await conn.execute( - f"INSERT INTO {table_with_schema(db, 'proofs_pending_new')} (amount, id, C, secret, Y, created) SELECT amount, id, C, secret, Y, created FROM {table_with_schema(db, 'proofs_pending')}" + f"INSERT INTO {table_with_schema(db, 'proofs_pending_new')} (amount, id, c, secret, y, created) SELECT amount, id, c, secret, y, created FROM {table_with_schema(db, 'proofs_pending')}" ) await conn.execute(f"DROP TABLE {table_with_schema(db, 'proofs_pending')}") await conn.execute( @@ -688,25 +688,25 @@ async def m017_foreign_keys_proof_tables(db: Database): await conn.execute( f""" CREATE TABLE IF NOT EXISTS {table_with_schema(db, 'promises_new')} ( - amount INTEGER NOT NULL, + amount {db.big_int} NOT NULL, id TEXT, - B_ TEXT NOT NULL, - C_ TEXT NOT NULL, - e TEXT, - s TEXT, + b_ TEXT NOT NULL, + c_ TEXT NOT NULL, + dleq_e TEXT, + dleq_s TEXT, created TIMESTAMP, mint_quote TEXT, swap_id TEXT, FOREIGN KEY (mint_quote) REFERENCES {table_with_schema(db, 'mint_quotes')}(quote), - UNIQUE (B_) + UNIQUE (b_) ); """ ) await conn.execute( - f"INSERT INTO {table_with_schema(db, 'promises_new')} (amount, id, B_, C_, e, s, created) SELECT amount, id, B_b, C_b, e, s, created FROM {table_with_schema(db, 'promises')}" + f"INSERT INTO {table_with_schema(db, 'promises_new')} (amount, id, b_, c_, dleq_e, dleq_s, created) SELECT amount, id, b_b, c_b, e, s, created FROM {table_with_schema(db, 'promises')}" ) await conn.execute(f"DROP TABLE {table_with_schema(db, 'promises')}") await conn.execute( diff --git a/cashu/mint/verification.py b/cashu/mint/verification.py index de38dca3..c11fbe66 100644 --- a/cashu/mint/verification.py +++ b/cashu/mint/verification.py @@ -143,7 +143,7 @@ async def _check_outputs_issued_before(self, outputs: List[BlindedMessage]): async with self.db.connect() as conn: for output in outputs: promise = await self.crud.get_promise( - B_=output.B_, db=self.db, conn=conn + b_=output.B_, db=self.db, conn=conn ) result.append(False if promise is None else True) return result