From 290e2fae305d6f118c9c641e2d72a6d9657ab132 Mon Sep 17 00:00:00 2001 From: Dzejkop Date: Mon, 23 Oct 2023 20:21:06 +0200 Subject: [PATCH] Rename --- src/app.rs | 11 ++++---- src/database/mod.rs | 26 +++++++++---------- src/database/types.rs | 4 +-- src/identity_tree.rs | 2 +- src/identity_tree/status.rs | 28 ++++++++++----------- src/task_monitor/tasks/insert_identities.rs | 4 +-- tests/recover_identities.rs | 4 +-- 7 files changed, 39 insertions(+), 40 deletions(-) diff --git a/src/app.rs b/src/app.rs index bffb7a39..e8a8a16b 100644 --- a/src/app.rs +++ b/src/app.rs @@ -16,8 +16,8 @@ use crate::contracts::{IdentityManager, SharedIdentityManager}; use crate::database::{self, Database}; use crate::ethereum::{self, Ethereum}; use crate::identity_tree::{ - ApiStatus, CanonicalTreeBuilder, Hash, InclusionProof, PendingStatus, RootItem, Status, - TreeState, TreeUpdate, TreeVersionReadOps, + ApiStatus, CanonicalTreeBuilder, Hash, InclusionProof, RootItem, Status, TreeState, TreeUpdate, + TreeVersionReadOps, UnprocessedStatus, }; use crate::prover::map::initialize_prover_maps; use crate::prover::{self, ProverConfiguration, ProverType, Provers}; @@ -53,10 +53,9 @@ impl From for InclusionProofResponse { impl ToResponseCode for InclusionProofResponse { fn to_response_code(&self) -> StatusCode { match self.0.status { - ApiStatus::Unprocessed(PendingStatus::Failed) => StatusCode::BAD_REQUEST, - ApiStatus::Unprocessed(PendingStatus::New) | ApiStatus::Processed(Status::Pending) => { - StatusCode::ACCEPTED - } + ApiStatus::Unprocessed(UnprocessedStatus::Failed) => StatusCode::BAD_REQUEST, + ApiStatus::Unprocessed(UnprocessedStatus::New) + | ApiStatus::Processed(Status::Pending) => StatusCode::ACCEPTED, ApiStatus::Processed(Status::Mined) | ApiStatus::Processed(Status::Processed) => { StatusCode::OK } diff --git a/src/database/mod.rs b/src/database/mod.rs index e72b15d2..911b790e 100644 --- a/src/database/mod.rs +++ b/src/database/mod.rs @@ -16,7 +16,7 @@ use thiserror::Error; use tracing::{error, info, instrument, warn}; use self::types::{DeletionEntry, LatestDeletionEntry, RecoveryEntry}; -use crate::identity_tree::{Hash, PendingStatus, RootItem, Status, TreeItem, TreeUpdate}; +use crate::identity_tree::{Hash, RootItem, Status, TreeItem, TreeUpdate, UnprocessedStatus}; pub mod types; use crate::prover::{ProverConfiguration, ProverType, Provers}; @@ -522,7 +522,7 @@ impl Database { "#, ) .bind(identity) - .bind(<&str>::from(PendingStatus::New)) + .bind(<&str>::from(UnprocessedStatus::New)) .bind(eligibility_timestamp); self.pool.execute(query).await?; @@ -686,7 +686,7 @@ impl Database { pub async fn get_eligible_unprocessed_commitments( &self, - status: PendingStatus, + status: UnprocessedStatus, ) -> Result, Error> { let query = sqlx::query( r#" @@ -716,7 +716,7 @@ impl Database { pub async fn get_unprocessed_commit_status( &self, commitment: &Hash, - ) -> Result, Error> { + ) -> Result, Error> { let query = sqlx::query( r#" SELECT status, error_message FROM unprocessed_identities WHERE commitment = $1 @@ -760,7 +760,7 @@ impl Database { "#, ) .bind(message) - .bind(<&str>::from(PendingStatus::Failed)) + .bind(<&str>::from(UnprocessedStatus::Failed)) .bind(commitment); self.pool.execute(query).await?; @@ -820,7 +820,7 @@ mod test { use semaphore::Field; use super::{Database, Options}; - use crate::identity_tree::{Hash, PendingStatus, Status}; + use crate::identity_tree::{Hash, Status, UnprocessedStatus}; use crate::prover::{ProverConfiguration, ProverType}; use crate::secret::SecretUrl; @@ -915,10 +915,10 @@ mod test { .get_unprocessed_commit_status(&commit_hash) .await? .expect("expected commitment status"); - assert_eq!(commit.0, PendingStatus::New); + assert_eq!(commit.0, UnprocessedStatus::New); let identity_count = db - .get_eligible_unprocessed_commitments(PendingStatus::New) + .get_eligible_unprocessed_commitments(UnprocessedStatus::New) .await? .len(); @@ -1092,7 +1092,7 @@ mod test { .await?; let unprocessed_commitments = db - .get_eligible_unprocessed_commitments(PendingStatus::New) + .get_eligible_unprocessed_commitments(UnprocessedStatus::New) .await?; assert_eq!(unprocessed_commitments.len(), 1); @@ -1125,7 +1125,7 @@ mod test { .await?; let unprocessed_commitments = db - .get_eligible_unprocessed_commitments(PendingStatus::New) + .get_eligible_unprocessed_commitments(UnprocessedStatus::New) .await?; // Assert unprocessed commitments against expected values @@ -1168,12 +1168,12 @@ mod test { .await?; let commitments = db - .get_eligible_unprocessed_commitments(PendingStatus::New) + .get_eligible_unprocessed_commitments(UnprocessedStatus::New) .await?; assert_eq!(commitments.len(), 1); let eligible_commitments = db - .get_eligible_unprocessed_commitments(PendingStatus::New) + .get_eligible_unprocessed_commitments(UnprocessedStatus::New) .await?; assert_eq!(eligible_commitments.len(), 1); @@ -1188,7 +1188,7 @@ mod test { .await?; let eligible_commitments = db - .get_eligible_unprocessed_commitments(PendingStatus::New) + .get_eligible_unprocessed_commitments(UnprocessedStatus::New) .await?; assert_eq!(eligible_commitments.len(), 1); diff --git a/src/database/types.rs b/src/database/types.rs index f0b21524..2d64d719 100644 --- a/src/database/types.rs +++ b/src/database/types.rs @@ -1,10 +1,10 @@ use chrono::{DateTime, Utc}; -use crate::identity_tree::{Hash, PendingStatus}; +use crate::identity_tree::{Hash, UnprocessedStatus}; pub struct UnprocessedCommitment { pub commitment: Hash, - pub status: PendingStatus, + pub status: UnprocessedStatus, pub created_at: DateTime, pub processed_at: Option>, pub error_message: Option, diff --git a/src/identity_tree.rs b/src/identity_tree.rs index 71a27ec0..8a65e49c 100644 --- a/src/identity_tree.rs +++ b/src/identity_tree.rs @@ -14,7 +14,7 @@ mod status; pub type PoseidonTree = LazyMerkleTree; pub type Hash = ::Hash; -pub use self::status::{ApiStatus, PendingStatus, Status, UnknownStatus}; +pub use self::status::{ApiStatus, Status, UnknownStatus, UnprocessedStatus}; #[derive(Clone, Eq, PartialEq, Hash, Debug)] pub struct TreeUpdate { diff --git a/src/identity_tree/status.rs b/src/identity_tree/status.rs index 6446e793..262ba06c 100644 --- a/src/identity_tree/status.rs +++ b/src/identity_tree/status.rs @@ -27,7 +27,7 @@ pub enum Status { #[derive(Clone, Copy, Debug, Serialize, Deserialize, PartialEq, Eq, Hash)] #[serde(rename_all = "camelCase")] -pub enum PendingStatus { +pub enum UnprocessedStatus { /// Unprocessed identity failed to be inserted into the tree for some reason /// /// Usually accompanied by an appropriate error message @@ -43,7 +43,7 @@ pub enum PendingStatus { #[serde(rename_all = "camelCase")] #[serde(untagged)] pub enum ApiStatus { - Unprocessed(PendingStatus), + Unprocessed(UnprocessedStatus), Processed(Status), } @@ -78,7 +78,7 @@ impl FromStr for ApiStatus { type Err = UnknownStatus; fn from_str(s: &str) -> Result { - if let Ok(s) = PendingStatus::from_str(s) { + if let Ok(s) = UnprocessedStatus::from_str(s) { Ok(Self::Unprocessed(s)) } else if let Ok(s) = Status::from_str(s) { Ok(Self::Processed(s)) @@ -88,7 +88,7 @@ impl FromStr for ApiStatus { } } -impl FromStr for PendingStatus { +impl FromStr for UnprocessedStatus { type Err = UnknownStatus; fn from_str(s: &str) -> Result { @@ -100,17 +100,17 @@ impl FromStr for PendingStatus { } } -impl From for &str { - fn from(scope: PendingStatus) -> Self { +impl From for &str { + fn from(scope: UnprocessedStatus) -> Self { match scope { - PendingStatus::New => "new", - PendingStatus::Failed => "failed", + UnprocessedStatus::New => "new", + UnprocessedStatus::Failed => "failed", } } } -impl From for ApiStatus { - fn from(status: PendingStatus) -> Self { +impl From for ApiStatus { + fn from(status: UnprocessedStatus) -> Self { Self::Unprocessed(status) } } @@ -129,8 +129,8 @@ mod tests { #[test_case(ApiStatus::Processed(Status::Pending) => "pending")] #[test_case(ApiStatus::Processed(Status::Mined) => "mined")] - #[test_case(ApiStatus::Unprocessed(PendingStatus::New) => "new")] - #[test_case(ApiStatus::Unprocessed(PendingStatus::Failed) => "failed")] + #[test_case(ApiStatus::Unprocessed(UnprocessedStatus::New) => "new")] + #[test_case(ApiStatus::Unprocessed(UnprocessedStatus::Failed) => "failed")] fn serialize_status(api_status: ApiStatus) -> &'static str { let s = serde_json::to_string(&api_status).unwrap(); @@ -142,8 +142,8 @@ mod tests { #[test_case("pending" => ApiStatus::Processed(Status::Pending))] #[test_case("mined" => ApiStatus::Processed(Status::Mined))] - #[test_case("new" => ApiStatus::Unprocessed(PendingStatus::New))] - #[test_case("failed" => ApiStatus::Unprocessed(PendingStatus::Failed))] + #[test_case("new" => ApiStatus::Unprocessed(UnprocessedStatus::New))] + #[test_case("failed" => ApiStatus::Unprocessed(UnprocessedStatus::Failed))] fn deserialize_status(s: &str) -> ApiStatus { // Wrapped because JSON expected `"something"` and not `something` let wrapped = format!("\"{s}\""); diff --git a/src/task_monitor/tasks/insert_identities.rs b/src/task_monitor/tasks/insert_identities.rs index d0d40e0f..f0700d13 100644 --- a/src/task_monitor/tasks/insert_identities.rs +++ b/src/task_monitor/tasks/insert_identities.rs @@ -9,7 +9,7 @@ use tracing::instrument; use crate::database::types::UnprocessedCommitment; use crate::database::Database; -use crate::identity_tree::{Hash, Latest, PendingStatus, TreeVersion, TreeVersionReadOps}; +use crate::identity_tree::{Hash, Latest, TreeVersion, TreeVersionReadOps, UnprocessedStatus}; pub struct InsertIdentities { database: Arc, @@ -43,7 +43,7 @@ async fn insert_identities_loop( loop { // get commits from database let unprocessed = database - .get_eligible_unprocessed_commitments(PendingStatus::New) + .get_eligible_unprocessed_commitments(UnprocessedStatus::New) .await?; if unprocessed.is_empty() { sleep(Duration::from_secs(5)).await; diff --git a/tests/recover_identities.rs b/tests/recover_identities.rs index 157d9d36..9beb1116 100644 --- a/tests/recover_identities.rs +++ b/tests/recover_identities.rs @@ -1,7 +1,7 @@ mod common; use common::prelude::*; -use signup_sequencer::identity_tree::{PendingStatus, Status}; +use signup_sequencer::identity_tree::{Status, UnprocessedStatus}; use crate::common::{test_inclusion_status, test_recover_identity}; const SUPPORTED_DEPTH: usize = 18; @@ -162,7 +162,7 @@ async fn recover_identities() -> anyhow::Result<()> { &uri, &client, &identities_ref[recovery_leaf_index], - PendingStatus::New, + UnprocessedStatus::New, ) .await; }