diff --git a/cashu/wallet/cli/cli.py b/cashu/wallet/cli/cli.py index 332acfd4..786f5e31 100644 --- a/cashu/wallet/cli/cli.py +++ b/cashu/wallet/cli/cli.py @@ -146,13 +146,13 @@ async def cli(ctx: Context, host: str, walletname: str, unit: str, tests: bool): # otherwise it will create a mnemonic and store it in the database if ctx.invoked_subcommand == "restore": wallet = await Wallet.with_db( - ctx.obj["HOST"], db_path, name=walletname, skip_private_key=True + ctx.obj["HOST"], db_path, name=walletname, skip_db_read=True ) else: # # we need to run the migrations before we load the wallet for the first time # # otherwise the wallet will not be able to generate a new private key and store it wallet = await Wallet.with_db( - ctx.obj["HOST"], db_path, name=walletname, skip_private_key=True + ctx.obj["HOST"], db_path, name=walletname, skip_db_read=True ) # now with the migrations done, we can load the wallet and generate a new mnemonic if needed wallet = await Wallet.with_db(ctx.obj["HOST"], db_path, name=walletname) diff --git a/cashu/wallet/migrations.py b/cashu/wallet/migrations.py index 5d68cdef..9fa43ade 100644 --- a/cashu/wallet/migrations.py +++ b/cashu/wallet/migrations.py @@ -139,24 +139,24 @@ async def m007_nostr(db: Database): """ Stores timestamps of nostr operations. """ - # async with db.connect() as conn: - # await conn.execute(""" - # CREATE TABLE IF NOT EXISTS nostr ( - # type TEXT NOT NULL, - # last TIMESTAMP DEFAULT NULL - # ) - # """) - # await conn.execute( - # """ - # INSERT INTO nostr - # (type, last) - # VALUES (?, ?) - # """, - # ( - # "dm", - # None, - # ), - # ) + async with db.connect() as conn: + await conn.execute(""" + CREATE TABLE IF NOT EXISTS nostr ( + type TEXT NOT NULL, + last TIMESTAMP DEFAULT NULL + ) + """) + await conn.execute( + """ + INSERT INTO nostr + (type, last) + VALUES (?, ?) + """, + ( + "dm", + None, + ), + ) async def m008_keysets_add_public_keys(db: Database): diff --git a/cashu/wallet/wallet.py b/cashu/wallet/wallet.py index fab75294..f120cad7 100644 --- a/cashu/wallet/wallet.py +++ b/cashu/wallet/wallet.py @@ -721,7 +721,7 @@ async def with_db( url: str, db: str, name: str = "no_name", - skip_private_key: bool = False, + skip_db_read: bool = False, ): """Initializes a wallet with a database and initializes the private key. @@ -729,7 +729,9 @@ async def with_db( url (str): URL of the mint. db (str): Path to the database. name (str, optional): Name of the wallet. Defaults to "no_name". - skip_private_key (bool, optional): If true, the private key is not initialized. Defaults to False. + skip_db_read (bool, optional): If true, values from db like private key and + keysets are not loaded. Useful for running only migrations and returning. + Defaults to False. Returns: Wallet: Initialized wallet. @@ -737,11 +739,11 @@ async def with_db( logger.debug(f"Initializing wallet with database: {db}") self = cls(url=url, db=db, name=name) await self._migrate_database() - if not skip_private_key: + if not skip_db_read: await self._init_private_key() + keysets_list = await get_keysets(mint_url=url, db=self.db) + self.keysets = {k.id: k for k in keysets_list} - keysets_list = await get_keysets(mint_url=url, db=self.db) - self.keysets = {k.id: k for k in keysets_list} return self async def _migrate_database(self):