Skip to content

Commit

Permalink
feat: add tx hash in completion email
Browse files Browse the repository at this point in the history
  • Loading branch information
Bisht13 committed Oct 21, 2024
1 parent 029ffe0 commit 0a25d10
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
6 changes: 3 additions & 3 deletions packages/relayer/src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ impl ChainClient {
request: RequestModel,
email_auth_msg: EmailAuthMsg,
relayer_state: RelayerState,
) -> Result<()> {
) -> Result<String> {
update_request(
&relayer_state.db,
request.id,
Expand Down Expand Up @@ -246,10 +246,10 @@ impl ChainClient {
info!(
LOG,
"tx hash: {:?}",
receipt.expect("tx not found").transaction_hash
receipt.clone().expect("tx not found").transaction_hash
);

Ok(())
Ok(receipt.expect("tx not found").transaction_hash.to_string())
}
}

Expand Down
15 changes: 13 additions & 2 deletions packages/relayer/src/mail.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ pub enum EmailEvent {
request_id: Uuid,
original_subject: String,
original_message_id: Option<String>,
explorer_url: String,
tx_hash: String,
},
Error {
email_addr: String,
Expand Down Expand Up @@ -140,13 +142,16 @@ pub async fn handle_email_event(event: EmailEvent, relayer_state: RelayerState)
request_id,
original_subject,
original_message_id,
explorer_url,
tx_hash,
} => {
let subject = format!("Re: {}", original_subject);
let body_plain = format!("Your request ID is #{} is now complete.", request_id);

// Prepare data for HTML rendering
let render_data = serde_json::json!({
"requestId": request_id,
"explorerUrl": format!("{}/tx/{}", explorer_url, tx_hash)
});
let body_html = render_html(
"completion_template.html",
Expand Down Expand Up @@ -361,17 +366,23 @@ pub async fn handle_email(
let email_auth_msg = get_email_auth_msg(&email, request.clone(), relayer_state.clone()).await?;

info!(LOG, "Hitting chain");
chain_client
let tx_hash = chain_client
.call(request.clone(), email_auth_msg, relayer_state.clone())
.await?;

update_request(&relayer_state.db, request.id, RequestStatus::Finished).await?;

let explorer_url = relayer_state.config.chains[&request.email_tx_auth.chain.to_string()]
.clone()
.explorer_url;

Ok(EmailEvent::Completion {
email_addr: parsed_email.get_from_addr()?,
request_id: request.id,
request_id: request.id.clone(),
original_subject: parsed_email.get_subject_all()?,
original_message_id: parsed_email.get_message_id().ok(),
explorer_url,
tx_hash,
})
}

Expand Down

0 comments on commit 0a25d10

Please sign in to comment.