Skip to content

Commit

Permalink
Rename
Browse files Browse the repository at this point in the history
  • Loading branch information
Dzejkop committed Oct 23, 2023
1 parent e9fb7d7 commit 290e2fa
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 40 deletions.
11 changes: 5 additions & 6 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -53,10 +53,9 @@ impl From<InclusionProof> 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
}
Expand Down
26 changes: 13 additions & 13 deletions src/database/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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?;
Expand Down Expand Up @@ -686,7 +686,7 @@ impl Database {

pub async fn get_eligible_unprocessed_commitments(
&self,
status: PendingStatus,
status: UnprocessedStatus,
) -> Result<Vec<types::UnprocessedCommitment>, Error> {
let query = sqlx::query(
r#"
Expand Down Expand Up @@ -716,7 +716,7 @@ impl Database {
pub async fn get_unprocessed_commit_status(
&self,
commitment: &Hash,
) -> Result<Option<(PendingStatus, String)>, Error> {
) -> Result<Option<(UnprocessedStatus, String)>, Error> {
let query = sqlx::query(
r#"
SELECT status, error_message FROM unprocessed_identities WHERE commitment = $1
Expand Down Expand Up @@ -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?;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);

Expand All @@ -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);

Expand Down
4 changes: 2 additions & 2 deletions src/database/types.rs
Original file line number Diff line number Diff line change
@@ -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<Utc>,
pub processed_at: Option<DateTime<Utc>>,
pub error_message: Option<String>,
Expand Down
2 changes: 1 addition & 1 deletion src/identity_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ mod status;
pub type PoseidonTree<Version> = LazyMerkleTree<PoseidonHash, Version>;
pub type Hash = <PoseidonHash as Hasher>::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 {
Expand Down
28 changes: 14 additions & 14 deletions src/identity_tree/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -43,7 +43,7 @@ pub enum PendingStatus {
#[serde(rename_all = "camelCase")]
#[serde(untagged)]
pub enum ApiStatus {
Unprocessed(PendingStatus),
Unprocessed(UnprocessedStatus),
Processed(Status),
}

Expand Down Expand Up @@ -78,7 +78,7 @@ impl FromStr for ApiStatus {
type Err = UnknownStatus;

fn from_str(s: &str) -> Result<Self, Self::Err> {
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))
Expand All @@ -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<Self, Self::Err> {
Expand All @@ -100,17 +100,17 @@ impl FromStr for PendingStatus {
}
}

impl From<PendingStatus> for &str {
fn from(scope: PendingStatus) -> Self {
impl From<UnprocessedStatus> for &str {
fn from(scope: UnprocessedStatus) -> Self {
match scope {
PendingStatus::New => "new",
PendingStatus::Failed => "failed",
UnprocessedStatus::New => "new",
UnprocessedStatus::Failed => "failed",
}
}
}

impl From<PendingStatus> for ApiStatus {
fn from(status: PendingStatus) -> Self {
impl From<UnprocessedStatus> for ApiStatus {
fn from(status: UnprocessedStatus) -> Self {
Self::Unprocessed(status)
}
}
Expand All @@ -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();

Expand All @@ -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}\"");
Expand Down
4 changes: 2 additions & 2 deletions src/task_monitor/tasks/insert_identities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Database>,
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions tests/recover_identities.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -162,7 +162,7 @@ async fn recover_identities() -> anyhow::Result<()> {
&uri,
&client,
&identities_ref[recovery_leaf_index],
PendingStatus::New,
UnprocessedStatus::New,
)
.await;
}
Expand Down

0 comments on commit 290e2fa

Please sign in to comment.