Skip to content

Commit

Permalink
Rebase solve conflicts of body-parser refacor
Browse files Browse the repository at this point in the history
  • Loading branch information
DimiDumo committed Sep 11, 2024
1 parent 3507756 commit 1c9b2d5
Show file tree
Hide file tree
Showing 7 changed files with 261 additions and 759 deletions.
1 change: 0 additions & 1 deletion packages/relayer/src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use ethers::middleware::Middleware;
use ethers::prelude::*;
use ethers::signers::Signer;
use relayer_utils::converters::u64_to_u8_array_32;
use relayer_utils::LOG;

const CONFIRMATIONS: usize = 1;

Expand Down
676 changes: 174 additions & 502 deletions packages/relayer/src/core.rs

Large diffs are not rendered by default.

17 changes: 2 additions & 15 deletions packages/relayer/src/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,12 +168,10 @@ impl Database {
Ok(())
}

#[named]
pub(crate) async fn insert_credentials(
&self,
row: &Credentials,
) -> std::result::Result<(), DatabaseError> {
info!(LOG, "insert row {:?}", row; "func" => function_name!());
let row = sqlx::query(
"INSERT INTO credentials (account_code, account_eth_addr, guardian_email_addr, is_set) VALUES ($1, $2, $3, $4) RETURNING *",
)
Expand All @@ -184,11 +182,7 @@ impl Database {
.fetch_one(&self.db)
.await
.map_err(|e| DatabaseError::new("Failed to insert credentials", e))?;
info!(
LOG,
"{} row inserted",
row.len(); "func" => function_name!()
);
info!(LOG, "Credentials inserted",);
Ok(())
}

Expand All @@ -210,7 +204,6 @@ impl Database {
}
}

#[named]
pub(crate) async fn get_request(
&self,
request_id: u32,
Expand Down Expand Up @@ -329,12 +322,10 @@ impl Database {
}
}

#[named]
pub(crate) async fn insert_request(
&self,
row: &Request,
) -> std::result::Result<(), DatabaseError> {
info!(LOG, "insert row {:?}", row; "func" => function_name!());
let row = sqlx::query(
"INSERT INTO requests (request_id, account_eth_addr, controller_eth_addr, guardian_email_addr, is_for_recovery, template_idx, is_processed, is_success, email_nullifier, account_salt) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10) RETURNING *",
)
Expand All @@ -351,11 +342,7 @@ impl Database {
.fetch_one(&self.db)
.await
.map_err(|e| DatabaseError::new("Failed to insert request", e))?;
info!(
LOG,
"{} row inserted",
row.len(); "func" => function_name!()
);
info!(LOG, "Request inserted");
Ok(())
}
}
2 changes: 1 addition & 1 deletion packages/relayer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub use utils::*;

use tokio::sync::Mutex;

use anyhow::{anyhow, bail, Result};
use anyhow::{anyhow, Result};
use dotenv::dotenv;
use ethers::prelude::*;
use lazy_static::lazy_static;
Expand Down
12 changes: 9 additions & 3 deletions packages/relayer/src/modules/web_server/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ pub enum ApiError {

#[derive(Error, Debug)]
pub enum EmailError {
#[error("Subject error: {0}")]
Subject(String),
#[error("Email body error: {0}")]
Body(String),
#[error("Email address error: {0}")]
EmailAddress(String),
#[error("Parse error: {0}")]
Expand All @@ -56,6 +56,10 @@ pub enum EmailError {
Render(#[from] RenderError),
#[error("Failed to send email: {0}")]
Send(String),
#[error("Hex error: {0}")]
HexError(#[from] hex::FromHexError),
#[error("ABI encode error: {0}")]
AbiError(String),
// Currently used with some relayer-utils errors
#[error("Anyhow error: {0}")]
Anyhow(#[from] anyhow::Error),
Expand Down Expand Up @@ -190,13 +194,15 @@ impl IntoResponse for ApiError {
ApiError::Anyhow(e) => (StatusCode::INTERNAL_SERVER_ERROR, e.to_string()),
ApiError::Internal(e) => (StatusCode::INTERNAL_SERVER_ERROR, e.to_string()),
ApiError::Email(e) => match e {
EmailError::Subject(e) => (StatusCode::BAD_REQUEST, e.to_string()),
EmailError::Body(e) => (StatusCode::BAD_REQUEST, e.to_string()),
EmailError::EmailAddress(e) => (StatusCode::BAD_REQUEST, e.to_string()),
EmailError::Parse(e) => (StatusCode::BAD_REQUEST, e.to_string()),
EmailError::NotFound(e) => (StatusCode::BAD_REQUEST, e.to_string()),
EmailError::Dkim(e) => (StatusCode::INTERNAL_SERVER_ERROR, e.to_string()),
EmailError::ZkRegex(e) => (StatusCode::INTERNAL_SERVER_ERROR, e.to_string()),
EmailError::Database(e) => (StatusCode::INTERNAL_SERVER_ERROR, e.to_string()),
EmailError::HexError(e) => (StatusCode::INTERNAL_SERVER_ERROR, e.to_string()),
EmailError::AbiError(e) => (StatusCode::INTERNAL_SERVER_ERROR, e.to_string()),
EmailError::Circuit(e) => (StatusCode::INTERNAL_SERVER_ERROR, e.to_string()),
EmailError::Chain(e) => (StatusCode::INTERNAL_SERVER_ERROR, e.to_string()),
EmailError::FileNotFound(e) => (StatusCode::INTERNAL_SERVER_ERROR, e.to_string()),
Expand Down
Loading

0 comments on commit 1c9b2d5

Please sign in to comment.