Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop nostr_last_checked table, remove references #647

Merged
merged 3 commits into from
Mar 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions crates/cdk-redb/src/wallet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ const MINT_KEYS_TABLE: TableDefinition<&str, &str> = TableDefinition::new("mint_
const PROOFS_TABLE: TableDefinition<&[u8], &str> = TableDefinition::new("proofs");
const CONFIG_TABLE: TableDefinition<&str, &str> = TableDefinition::new("config");
const KEYSET_COUNTER: TableDefinition<&str, u32> = TableDefinition::new("keyset_counter");
const NOSTR_LAST_CHECKED: TableDefinition<&str, u32> = TableDefinition::new("keyset_counter");

const DATABASE_VERSION: u32 = 2;

Expand Down Expand Up @@ -133,7 +132,6 @@ impl WalletRedbDatabase {
let _ = write_txn.open_table(MINT_KEYS_TABLE)?;
let _ = write_txn.open_table(PROOFS_TABLE)?;
let _ = write_txn.open_table(KEYSET_COUNTER)?;
let _ = write_txn.open_table(NOSTR_LAST_CHECKED)?;
table.insert("db_version", DATABASE_VERSION.to_string().as_str())?;
}

Expand Down
54 changes: 1 addition & 53 deletions crates/cdk-rexie/src/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@ const MELT_QUOTES: &str = "melt_quotes";
const PROOFS: &str = "proofs";
const CONFIG: &str = "config";
const KEYSET_COUNTER: &str = "keyset_counter";
const NOSTR_LAST_CHECKED: &str = "nostr_last_check";

const DATABASE_VERSION: u32 = 3;
const DATABASE_VERSION: u32 = 4;

/// Rexie Database Error
#[derive(Debug, Error)]
Expand Down Expand Up @@ -98,7 +97,6 @@ impl WalletRexieDatabase {
.add_object_store(ObjectStore::new(MELT_QUOTES))
.add_object_store(ObjectStore::new(CONFIG))
.add_object_store(ObjectStore::new(KEYSET_COUNTER))
.add_object_store(ObjectStore::new(NOSTR_LAST_CHECKED))
// Build the database
.build()
.await
Expand Down Expand Up @@ -747,54 +745,4 @@ impl WalletDatabase for WalletRexieDatabase {

Ok(current_count)
}

async fn add_nostr_last_checked(
&self,
verifying_key: PublicKey,
last_checked: u32,
) -> Result<(), Self::Err> {
let rexie = self.db.lock().await;

let transaction = rexie
.transaction(&[NOSTR_LAST_CHECKED], TransactionMode::ReadWrite)
.map_err(Error::from)?;

let counter_store = transaction.store(NOSTR_LAST_CHECKED).map_err(Error::from)?;

let verifying_key = serde_wasm_bindgen::to_value(&verifying_key).map_err(Error::from)?;

let last_checked = serde_wasm_bindgen::to_value(&last_checked).map_err(Error::from)?;

counter_store
.put(&last_checked, Some(&verifying_key))
.await
.map_err(Error::from)?;

transaction.done().await.map_err(Error::from)?;

Ok(())
}

async fn get_nostr_last_checked(
&self,
verifying_key: &PublicKey,
) -> Result<Option<u32>, Self::Err> {
let rexie = self.db.lock().await;

let transaction = rexie
.transaction(&[NOSTR_LAST_CHECKED], TransactionMode::ReadOnly)
.map_err(Error::from)?;

let nostr_last_check_store = transaction.store(NOSTR_LAST_CHECKED).map_err(Error::from)?;

let verifying_key = serde_wasm_bindgen::to_value(verifying_key).map_err(Error::from)?;

let last_checked = nostr_last_check_store
.get(verifying_key)
.await
.map_err(Error::from)?
.and_then(|l| serde_wasm_bindgen::from_value(l).ok());

Ok(last_checked)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DROP TABLE IF EXISTS nostr_last_checked;
Loading