From 20a6a6390c8b396542049991b0b38c0dd417a8d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jon=20H=C3=A4ggblad?= Date: Fri, 17 Jan 2025 17:35:05 +0100 Subject: [PATCH] wip --- .../migrations/01_initial.sql | 7 +++--- .../src/commands/request_zknym.rs | 25 +++++++++++++++++-- .../pending_credential_requests/sqlite.rs | 12 ++++++++- 3 files changed, 38 insertions(+), 6 deletions(-) diff --git a/nym-vpn-core/crates/nym-vpn-account-controller/migrations/01_initial.sql b/nym-vpn-core/crates/nym-vpn-account-controller/migrations/01_initial.sql index 4e404edb58..c16cb24ce5 100644 --- a/nym-vpn-core/crates/nym-vpn-account-controller/migrations/01_initial.sql +++ b/nym-vpn-core/crates/nym-vpn-account-controller/migrations/01_initial.sql @@ -5,7 +5,8 @@ CREATE TABLE pending_zk_nym_requests ( - id TEXT NOT NULL PRIMARY KEY, - expiration_date TEXT NOT NULL, - request_info BLOB NOT NULL + id TEXT NOT NULL PRIMARY KEY, + expiration_date TEXT NOT NULL, + request_info BLOB NOT NULL, + timestamp TIMESTAMP WITHOUT TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP ); diff --git a/nym-vpn-core/crates/nym-vpn-account-controller/src/commands/request_zknym.rs b/nym-vpn-core/crates/nym-vpn-account-controller/src/commands/request_zknym.rs index 43e2522b87..4de3df18ab 100644 --- a/nym-vpn-core/crates/nym-vpn-account-controller/src/commands/request_zknym.rs +++ b/nym-vpn-core/crates/nym-vpn-account-controller/src/commands/request_zknym.rs @@ -218,9 +218,30 @@ impl RequestZkNymCommandHandler { .await .map_err(|err| RequestZkNymError::CredentialStorage(err.to_string()))?; + // WIP(JON) + let zk_nyms_available_for_download = self + .vpn_api_client + .get_zk_nyms_available_for_download(&self.account, &self.device) + .await + .unwrap(); + + let zk_nyms_available_for_download_ids = zk_nyms_available_for_download + .items + .iter() + .map(|item| item.id.clone()); + + let pending_requests: Vec<_> = pending_requests + .into_iter() + .filter(|pending_request| { + zk_nyms_available_for_download_ids + .clone() + .any(|id| id == pending_request.id) + }) + .collect(); + let resumed_requests = if !pending_requests.is_empty() { tracing::info!("Resuming {} zk-nym requests", pending_requests.len()); - self.resume_request_zk_nym_inner(pending_requests).await + self.resume_request_zk_nyms_inner(pending_requests).await } else { Vec::new() }; @@ -276,7 +297,7 @@ impl RequestZkNymCommandHandler { join_set.join_all().await } - async fn resume_request_zk_nym_inner( + async fn resume_request_zk_nyms_inner( &self, pending_requests: Vec, ) -> Vec> { diff --git a/nym-vpn-core/crates/nym-vpn-account-controller/src/storage/credentials/pending_credential_requests/sqlite.rs b/nym-vpn-core/crates/nym-vpn-account-controller/src/storage/credentials/pending_credential_requests/sqlite.rs index 8ea33137bc..364f6711d2 100644 --- a/nym-vpn-core/crates/nym-vpn-account-controller/src/storage/credentials/pending_credential_requests/sqlite.rs +++ b/nym-vpn-core/crates/nym-vpn-account-controller/src/storage/credentials/pending_credential_requests/sqlite.rs @@ -1,7 +1,7 @@ // Copyright 2024 - Nym Technologies SA // SPDX-License-Identifier: GPL-3.0-only -use time::Date; +use time::{Date, OffsetDateTime}; use super::models::PendingCredentialRequestStored; @@ -27,6 +27,16 @@ impl SqliteZkNymRequestsStorageManager { .await } + pub async fn get_pending_requests_older_than( + &self, + cutoff: OffsetDateTime, + ) -> Result, sqlx::Error> { + sqlx::query_as("SELECT * FROM pending_zk_nym_requests WHERE timestamp > ?") + .bind(cutoff) + .fetch_all(&self.connection_pool) + .await + } + pub async fn get_pending_request_by_id( &self, id: &str,