Skip to content

Commit

Permalink
Allow 0x account code in the request to handle_acceptance_request
Browse files Browse the repository at this point in the history
  • Loading branch information
SoraSuegami committed Dec 18, 2024
1 parent de12947 commit be63421
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions packages/relayer/src/modules/web_server/rest_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,13 @@ pub async fn handle_acceptance_request(
// return Err(ApiError::Validation("Not permitted bytecode".to_string()));
// }

let mut account_code = payload.account_code.clone();
if account_code.starts_with("0x") {
account_code = account_code[2..].to_string();
}

// Check if the account code is already used
if let Ok(Some(creds)) = DB.get_credentials(&payload.account_code).await {
if let Ok(Some(creds)) = DB.get_credentials(&account_code).await {
return Err(ApiError::Validation(
"Account code already used".to_string(),
));
Expand All @@ -137,7 +142,7 @@ pub async fn handle_acceptance_request(
request_id = rand::thread_rng().gen::<u32>();
}

let account_salt = calculate_account_salt(&payload.guardian_email_addr, &payload.account_code);
let account_salt = calculate_account_salt(&payload.guardian_email_addr, &account_code);

DB.insert_request(&Request {
request_id,
Expand Down Expand Up @@ -171,7 +176,7 @@ pub async fn handle_acceptance_request(
{
// Update credentials and send acceptance request email
DB.update_credentials_of_wallet_and_email(&Credentials {
account_code: payload.account_code.clone(),
account_code: account_code.clone(),
account_eth_addr: account_eth_addr.clone(),
guardian_email_addr: payload.guardian_email_addr.clone(),
is_set: false,
Expand All @@ -183,13 +188,13 @@ pub async fn handle_acceptance_request(
guardian_email_addr: payload.guardian_email_addr.clone(),
request_id,
command: payload.command.clone(),
account_code: payload.account_code.clone(),
account_code: account_code.clone(),
})
.await?;
} else {
// Insert new credentials and send acceptance request email
DB.insert_credentials(&Credentials {
account_code: payload.account_code.clone(),
account_code: account_code.clone(),
account_eth_addr: account_eth_addr.clone(),
guardian_email_addr: payload.guardian_email_addr.clone(),
is_set: false,
Expand All @@ -201,7 +206,7 @@ pub async fn handle_acceptance_request(
guardian_email_addr: payload.guardian_email_addr.clone(),
request_id,
command: payload.command.clone(),
account_code: payload.account_code.clone(),
account_code: account_code.clone(),
})
.await?;
}
Expand Down Expand Up @@ -302,7 +307,6 @@ pub async fn handle_recovery_request(
let account = DB
.get_credentials_from_wallet_and_email(&account_eth_addr, &payload.guardian_email_addr)
.await?;

let account_salt = if let Some(account_details) = account {
calculate_account_salt(&payload.guardian_email_addr, &account_details.account_code)
} else {
Expand Down

0 comments on commit be63421

Please sign in to comment.