Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
octol committed Jan 17, 2025
1 parent 583a940 commit 20a6a63
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
Original file line number Diff line number Diff line change
Expand Up @@ -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()
};
Expand Down Expand Up @@ -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<PendingCredentialRequest>,
) -> Vec<Result<RequestZkNymSuccess, RequestZkNymError>> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2024 - Nym Technologies SA <[email protected]>
// SPDX-License-Identifier: GPL-3.0-only

use time::Date;
use time::{Date, OffsetDateTime};

use super::models::PendingCredentialRequestStored;

Expand All @@ -27,6 +27,16 @@ impl SqliteZkNymRequestsStorageManager {
.await
}

pub async fn get_pending_requests_older_than(
&self,
cutoff: OffsetDateTime,
) -> Result<Vec<PendingCredentialRequestStored>, 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,
Expand Down

0 comments on commit 20a6a63

Please sign in to comment.