diff --git a/database/src/structs/request_status.rs b/database/src/structs/request_status.rs index 1ca8eec9..df24a9d1 100644 --- a/database/src/structs/request_status.rs +++ b/database/src/structs/request_status.rs @@ -18,11 +18,12 @@ pub enum RequestFail { TimedOut, } -impl Into for RequestFail { - fn into(self) -> RequestStatus { - match self { - RequestFail::Rejected => RequestStatus::Rejected, - RequestFail::TimedOut => RequestStatus::TimedOut, +impl From<&Option> for RequestStatus { + fn from(fail: &Option) -> Self { + match fail { + Some(RequestFail::Rejected) => RequestStatus::Rejected, + Some(RequestFail::TimedOut) => RequestStatus::TimedOut, + None => RequestStatus::Completed, } } } diff --git a/database/src/tables/events/change_network/update.rs b/database/src/tables/events/change_network/update.rs index 4c2c7249..d93b37b2 100644 --- a/database/src/tables/events/change_network/update.rs +++ b/database/src/tables/events/change_network/update.rs @@ -41,7 +41,7 @@ impl Db { tx: &mut Transaction<'_, Postgres>, request_id: &String, request_status: RequestStatus, - new_network: Option, + new_network: &Option, ) -> Result<(), DbError> { let query_body = format!( "UPDATE {EVENT_CHANGE_NETWORK_TABLE_NAME} SET request_status = $1, new_network = $2 WHERE request_id = $3", diff --git a/database/src/tables/events/change_wallet/update.rs b/database/src/tables/events/change_wallet/update.rs index 111e0e6a..4879a7ea 100644 --- a/database/src/tables/events/change_wallet/update.rs +++ b/database/src/tables/events/change_wallet/update.rs @@ -12,7 +12,7 @@ impl Db { pub async fn create_new_event_change_wallet( &self, tx: &mut Transaction<'_, Postgres>, - event_id: &i64, + event_id: i64, session_id: &String, request_id: &String, network_id: &String, @@ -47,7 +47,7 @@ impl Db { tx: &mut Transaction<'_, Postgres>, request_id: &String, request_status: RequestStatus, - new_wallet_address: Option, + new_wallet_address: &Option, ) -> Result<(), DbError> { let query_body = format!( "UPDATE {EVENT_CHANGE_WALLET_TABLE_NAME} SET request_status = $1, new_wallet_address = $2 WHERE request_id = $3", diff --git a/database/src/tables/events/sign_and_send_transaction/update.rs b/database/src/tables/events/sign_and_send_transaction/update.rs index 29f9a76e..8272877d 100644 --- a/database/src/tables/events/sign_and_send_transaction/update.rs +++ b/database/src/tables/events/sign_and_send_transaction/update.rs @@ -41,7 +41,7 @@ impl Db { tx: &mut Transaction<'_, Postgres>, request_id: &String, request_status: RequestStatus, - tx_hash: Option, + tx_hash: &Option, ) -> Result<(), DbError> { let query_body = format!( "UPDATE {EVENT_SIGN_AND_SEND_TRANSACTION_TABLE_NAME} SET request_status = $1, tx_hash = $2 WHERE request_id = $3" diff --git a/database/src/tables/events/sign_transaction/update.rs b/database/src/tables/events/sign_transaction/update.rs index 0b3d6a11..53e1b329 100644 --- a/database/src/tables/events/sign_transaction/update.rs +++ b/database/src/tables/events/sign_transaction/update.rs @@ -42,7 +42,7 @@ impl Db { tx: &mut Transaction<'_, Postgres>, request_id: &String, request_status: RequestStatus, - tx_hash: Option, + tx_hash: &Option, ) -> Result<(), DbError> { let query_body = format!( "UPDATE {EVENT_SIGN_TRANSACTION_TABLE_NAME} SET request_status = $1, tx_hash = $2 WHERE request_id = $3" diff --git a/server/bindings/ChangeNetworkEvent.ts b/server/bindings/ChangeNetworkEvent.ts index 825b32ed..5042d325 100644 --- a/server/bindings/ChangeNetworkEvent.ts +++ b/server/bindings/ChangeNetworkEvent.ts @@ -1,3 +1,3 @@ // This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. -export interface ChangeNetworkEvent { sessionId: string, requestId: string, oldNetwork: string, newNetwork: string, } \ No newline at end of file +export interface ChangeNetworkEvent { sessionId: string, requestId: string, oldNetwork: string, } \ No newline at end of file diff --git a/server/bindings/ChangeNetworkResolveEvent.ts b/server/bindings/ChangeNetworkResolveEvent.ts index 71d3d9d9..9912ea45 100644 --- a/server/bindings/ChangeNetworkResolveEvent.ts +++ b/server/bindings/ChangeNetworkResolveEvent.ts @@ -1,4 +1,4 @@ // This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. import type { RequestFail } from "./RequestFail"; -export interface ChangeNetworkResolveEvent { sessionId: string, requestId: string, failureReason?: RequestFail, } \ No newline at end of file +export interface ChangeNetworkResolveEvent { sessionId: string, requestId: string, newNetwork: string | null, failureReason?: RequestFail, } \ No newline at end of file diff --git a/server/bindings/ClientConnectEvent.ts b/server/bindings/ClientConnectEvent.ts index a3916955..4378e6e5 100644 --- a/server/bindings/ClientConnectEvent.ts +++ b/server/bindings/ClientConnectEvent.ts @@ -1,3 +1,4 @@ // This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. +import type { SessionType } from "./SessionType"; -export interface ClientConnectEvent { clientId: string, publicKeys: Array, sessionId: string, device: string | null, metadata: string | null, notification: string | null, } \ No newline at end of file +export interface ClientConnectEvent { clientId: string, sessionId: string, walletName: string, walletType: string, sessionType: SessionType, } \ No newline at end of file diff --git a/server/bindings/ClientConnectResolveEvent.ts b/server/bindings/ClientConnectResolveEvent.ts index e8260452..dd86834f 100644 --- a/server/bindings/ClientConnectResolveEvent.ts +++ b/server/bindings/ClientConnectResolveEvent.ts @@ -1,3 +1,3 @@ // This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. -export interface ClientConnectResolveEvent { clientId: string, sessionId: string, addresses: Array, success: boolean, } \ No newline at end of file +export interface ClientConnectResolveEvent { clientId: string, sessionId: string, addresses: Array, walletName: string, walletType: string, success: boolean, } \ No newline at end of file diff --git a/server/bindings/ClientDisconnectEvent.ts b/server/bindings/ClientDisconnectEvent.ts index af29b597..c969f18c 100644 --- a/server/bindings/ClientDisconnectEvent.ts +++ b/server/bindings/ClientDisconnectEvent.ts @@ -1,3 +1,3 @@ // This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. -export interface ClientDisconnectEvent { disconnectedSessionId: string, } \ No newline at end of file +export interface ClientDisconnectEvent { clientId: string, disconnectedSessionId: string, } \ No newline at end of file diff --git a/server/bindings/EventData.ts b/server/bindings/EventData.ts index b766bc63..772506a2 100644 --- a/server/bindings/EventData.ts +++ b/server/bindings/EventData.ts @@ -3,7 +3,7 @@ import type { AppConnectEvent } from "./AppConnectEvent"; import type { AppDisconnectEvent } from "./AppDisconnectEvent"; import type { ChangeNetworkEvent } from "./ChangeNetworkEvent"; import type { ChangeWalletEvent } from "./ChangeWalletEvent"; -import type { ClientConnectInitEvent } from "./ClientConnectInitEvent"; +import type { ClientConnectEvent } from "./ClientConnectEvent"; import type { ClientConnectResolveEvent } from "./ClientConnectResolveEvent"; import type { ClientDisconnectEvent } from "./ClientDisconnectEvent"; import type { SignAndSendTransactionEvent } from "./SignAndSendTransactionEvent"; @@ -13,4 +13,4 @@ import type { SignMessageResolveEvent } from "./SignMessageResolveEvent"; import type { SignTransactionEvent } from "./SignTransactionEvent"; import type { SignTransactionResolveEvent } from "./SignTransactionResolveEvent"; -export type EventData = { type: "AppConnect" } & AppConnectEvent | { type: "AppDisconnect" } & AppDisconnectEvent | { type: "ClientConnectInit" } & ClientConnectInitEvent | { type: "ClientConnectResolve" } & ClientConnectResolveEvent | { type: "ClientDisconnect" } & ClientDisconnectEvent | { type: "SignMessage" } & SignMessageEvent | { type: "SignMessageResolve" } & SignMessageResolveEvent | { type: "SignTransaction" } & SignTransactionEvent | { type: "SignTransactionResolve" } & SignTransactionResolveEvent | { type: "SignAndSendTransaction" } & SignAndSendTransactionEvent | { type: "SignAndSendTransactionResolve" } & SignAndSendTransactionResolveEvent | { type: "ChangeNetwork" } & ChangeNetworkEvent | { type: "ChangeWallet" } & ChangeWalletEvent; \ No newline at end of file +export type EventData = { type: "AppConnect" } & AppConnectEvent | { type: "AppDisconnect" } & AppDisconnectEvent | { type: "ClientConnect" } & ClientConnectEvent | { type: "ClientConnectResolve" } & ClientConnectResolveEvent | { type: "ClientDisconnect" } & ClientDisconnectEvent | { type: "SignMessage" } & SignMessageEvent | { type: "SignMessageResolve" } & SignMessageResolveEvent | { type: "SignTransaction" } & SignTransactionEvent | { type: "SignTransactionResolve" } & SignTransactionResolveEvent | { type: "SignAndSendTransaction" } & SignAndSendTransactionEvent | { type: "SignAndSendTransactionResolve" } & SignAndSendTransactionResolveEvent | { type: "ChangeNetwork" } & ChangeNetworkEvent | { type: "ChangeWallet" } & ChangeWalletEvent; \ No newline at end of file diff --git a/server/src/http/cloud/events/events_handler.rs b/server/src/http/cloud/events/events_handler.rs index 4c04314f..7e26326f 100644 --- a/server/src/http/cloud/events/events_handler.rs +++ b/server/src/http/cloud/events/events_handler.rs @@ -3,9 +3,17 @@ use super::{ processors::{ process_event_app_connect::process_event_app_connect, process_event_app_disconnect::process_event_app_disconnect, + process_event_change_network::process_event_change_network, + process_event_change_wallet::process_event_change_wallet, process_event_client_connect::process_event_client_connect_init, process_event_client_connect_resolve::process_event_client_connect_resolve, process_event_client_disconnect::process_event_client_disconnect, + process_event_sign_and_send_transaction::process_event_sign_and_send_transaction, + process_event_sign_and_send_transaction_resolve::process_event_sign_and_send_transaction_resolve, + process_event_sign_message::process_event_sign_message, + process_event_sign_message_resolve::process_event_sign_message_resolve, + process_event_sign_transaction::process_event_sign_transaction, + process_event_sign_transaction_resolve::process_event_sign_transaction_resolve, }, }; use crate::{ @@ -54,13 +62,36 @@ pub async fn process_event( EventData::ClientDisconnect(event) => { process_event_client_disconnect(event, &event_payload.app_id, ip, db_connection).await; } - EventData::SignMessage(_) => todo!(), - EventData::SignMessageResolve(_) => todo!(), - EventData::SignTransaction(_) => todo!(), - EventData::SignTransactionResolve(_) => todo!(), - EventData::SignAndSendTransaction(_) => todo!(), - EventData::SignAndSendTransactionResolve(_) => todo!(), - EventData::ChangeNetwork(_) => todo!(), - EventData::ChangeWallet(_) => todo!(), + EventData::SignMessage(event) => { + process_event_sign_message(event, &event_payload.app_id, db_connection).await; + } + EventData::SignMessageResolve(event) => { + process_event_sign_message_resolve(event, &event_payload.app_id, db_connection).await; + } + EventData::SignTransaction(event) => { + process_event_sign_transaction(event, &event_payload.app_id, db_connection).await; + } + EventData::SignTransactionResolve(event) => { + process_event_sign_transaction_resolve(event, &event_payload.app_id, db_connection) + .await; + } + EventData::SignAndSendTransaction(event) => { + process_event_sign_and_send_transaction(event, &event_payload.app_id, db_connection) + .await; + } + EventData::SignAndSendTransactionResolve(event) => { + process_event_sign_and_send_transaction_resolve( + event, + &event_payload.app_id, + db_connection, + ) + .await; + } + EventData::ChangeNetwork(event) => { + process_event_change_network(event, &event_payload.app_id, db_connection).await; + } + EventData::ChangeWallet(event) => { + process_event_change_wallet(event, &event_payload.app_id, db_connection).await; + } } } diff --git a/server/src/http/cloud/events/processors/mod.rs b/server/src/http/cloud/events/processors/mod.rs index 66ea5480..f6a6f50e 100644 --- a/server/src/http/cloud/events/processors/mod.rs +++ b/server/src/http/cloud/events/processors/mod.rs @@ -1,5 +1,15 @@ pub mod process_event_app_connect; pub mod process_event_app_disconnect; +pub mod process_event_change_network; +pub mod process_event_change_network_resolve; +pub mod process_event_change_wallet; +pub mod process_event_change_wallet_resolve; pub mod process_event_client_connect; pub mod process_event_client_connect_resolve; pub mod process_event_client_disconnect; +pub mod process_event_sign_and_send_transaction; +pub mod process_event_sign_and_send_transaction_resolve; +pub mod process_event_sign_message; +pub mod process_event_sign_message_resolve; +pub mod process_event_sign_transaction; +pub mod process_event_sign_transaction_resolve; diff --git a/server/src/http/cloud/events/processors/process_event_app_connect.rs b/server/src/http/cloud/events/processors/process_event_app_connect.rs index f74abfc9..4b70b9ba 100644 --- a/server/src/http/cloud/events/processors/process_event_app_connect.rs +++ b/server/src/http/cloud/events/processors/process_event_app_connect.rs @@ -119,58 +119,29 @@ pub async fn process_event_app_connect( async fn save_event_app_connect(db: &Arc, app_id: &String, event: &AppConnectEvent) { // Establish a new transaction - match db.connection_pool.begin().await { - Ok(mut tx) => { - // Create a new event index in the database - match db - .create_new_event_entry(&mut tx, &app_id, &EventType::AppConnect) - .await - { - Ok(event_id) => { - // Now create a new event app connect corresponding to the event - match db - .create_new_event_app_connect( - &mut tx, - event_id, - &event.session_id, - &event - .device_metadata - .to_string() - .unwrap_or("Failed to serialize device metadata".to_string()), - &event.language, - &event.timezone, - event.new_session, - ) - .await - { - Ok(_) => { - // Commit the transaction - if let Err(err) = tx.commit().await { - error!( - "Failed to commit transaction for new app connection event, app_id: [{}], event: [{:?}], err: [{}]", - app_id, event, err - ); - } + let mut tx = match db.connection_pool.begin().await { + Ok(tx) => tx, + Err(err) => { + error!( + "Failed to create new transaction to save app connection event, app_id: [{}], event: [{:?}], err: [{}]", + app_id, event, err + ); + return; + } + }; - return; - } - Err(err) => { - error!( - "Failed to create new app connection event, app_id: [{}], event: [{:?}], err: [{}]", - app_id, event, err - ); - } - } - } - Err(err) => { - error!( - "Failed to create new event index, app_id: [{}], event: [{:?}], err: [{}]", - app_id, event, err - ); - } - } + // Create a new event index + let event_id = match db + .create_new_event_entry(&mut tx, &app_id, &EventType::AppConnect) + .await + { + Ok(event_id) => event_id, + Err(err) => { + error!( + "Failed to create new event index, app_id: [{}], event: [{:?}], err: [{}]", + app_id, event, err + ); - // If we have not returned yet, then we have failed to save the event // Rollback the transaction if let Err(err) = tx.rollback().await { error!( @@ -178,12 +149,49 @@ async fn save_event_app_connect(db: &Arc, app_id: &String, event: &AppConnec app_id, event, err ); } + + return; + } + }; + + // Now create a new event app connect corresponding to the event + match db + .create_new_event_app_connect( + &mut tx, + event_id, + &event.session_id, + &event + .device_metadata + .to_string() + .unwrap_or("Failed to serialize device metadata".to_string()), + &event.language, + &event.timezone, + event.new_session, + ) + .await + { + Ok(_) => { + // Commit the transaction + if let Err(err) = tx.commit().await { + error!( + "Failed to commit transaction for new app connection event, app_id: [{}], event: [{:?}], err: [{}]", + app_id, event, err + ); + } } Err(err) => { error!( - "Failed to create new transaction to save app connection event, app_id: [{}], event: [{:?}], err: [{}]", + "Failed to create new app connection event, app_id: [{}], event: [{:?}], err: [{}]", app_id, event, err ); + + // Rollback the transaction + if let Err(err) = tx.rollback().await { + error!( + "Failed to rollback transaction for new app connection event, app_id: [{}], event: [{:?}], err: [{}]", + app_id, event, err + ); + } } } } diff --git a/server/src/http/cloud/events/processors/process_event_app_disconnect.rs b/server/src/http/cloud/events/processors/process_event_app_disconnect.rs index 824326e9..77ff8b19 100644 --- a/server/src/http/cloud/events/processors/process_event_app_disconnect.rs +++ b/server/src/http/cloud/events/processors/process_event_app_disconnect.rs @@ -12,10 +12,10 @@ pub async fn process_event_app_disconnect( // Save event to Db save_event_app_disconnect(db, app_id, event).await; - // Close app connection in the database + // Close app disconnect in the database if let Err(err) = db.close_app_connection(&event.session_id, &app_id).await { error!( - "Failed to close app connection, app_id: [{}], ip: [{}], event: [{:?}], err: [{}]", + "Failed to close app disconnect, app_id: [{}], ip: [{}], event: [{:?}], err: [{}]", app_id, ip, event, err ); } @@ -23,47 +23,29 @@ pub async fn process_event_app_disconnect( async fn save_event_app_disconnect(db: &Arc, app_id: &String, event: &AppDisconnectEvent) { // Establish a new transaction - match db.connection_pool.begin().await { - Ok(mut tx) => { - // Create a new event index in the database - match db - .create_new_event_entry(&mut tx, &app_id, &EventType::AppDisconnect) - .await - { - Ok(event_id) => { - // Now create a new event app disconnect corresponding to the event - match db - .create_new_event_app_disconnect(&mut tx, event_id, &event.session_id) - .await - { - Ok(_) => { - // Commit the transaction - if let Err(err) = tx.commit().await { - error!( - "Failed to commit transaction for new app disconnect event, app_id: [{}], event: [{:?}], err: [{}]", - app_id, event, err - ); - } + let mut tx = match db.connection_pool.begin().await { + Ok(tx) => tx, + Err(err) => { + error!( + "Failed to create new transaction to save app disconnect event, app_id: [{}], event: [{:?}], err: [{}]", + app_id, event, err + ); + return; + } + }; - return; - } - Err(err) => { - error!( - "Failed to create new app disconnect event, app_id: [{}], event: [{:?}], err: [{}]", - app_id, event, err - ); - } - } - } - Err(err) => { - error!( - "Failed to create new event index, app_id: [{}], event: [{:?}], err: [{}]", - app_id, event, err - ); - } - } + // Create a new event index + let event_id = match db + .create_new_event_entry(&mut tx, &app_id, &EventType::AppDisconnect) + .await + { + Ok(event_id) => event_id, + Err(err) => { + error!( + "Failed to create new event index, app_id: [{}], event: [{:?}], err: [{}]", + app_id, event, err + ); - // If we have not returned yet, then we have failed to save the event // Rollback the transaction if let Err(err) = tx.rollback().await { error!( @@ -71,12 +53,38 @@ async fn save_event_app_disconnect(db: &Arc, app_id: &String, event: &AppDis app_id, event, err ); } + + return; + } + }; + + // Now create a new event app disconnect corresponding to the event + match db + .create_new_event_app_disconnect(&mut tx, event_id, &event.session_id) + .await + { + Ok(_) => { + // Commit the transaction + if let Err(err) = tx.commit().await { + error!( + "Failed to commit transaction for new app disconnect event, app_id: [{}], event: [{:?}], err: [{}]", + app_id, event, err + ); + } } Err(err) => { error!( - "Failed to create new transaction to save app disconnect event, app_id: [{}], event: [{:?}], err: [{}]", + "Failed to create new app disconnect event, app_id: [{}], event: [{:?}], err: [{}]", app_id, event, err ); + + // Rollback the transaction + if let Err(err) = tx.rollback().await { + error!( + "Failed to rollback transaction for new app disconnect event, app_id: [{}], event: [{:?}], err: [{}]", + app_id, event, err + ); + } } } } diff --git a/server/src/http/cloud/events/processors/process_event_change_network.rs b/server/src/http/cloud/events/processors/process_event_change_network.rs new file mode 100644 index 00000000..987ac81b --- /dev/null +++ b/server/src/http/cloud/events/processors/process_event_change_network.rs @@ -0,0 +1,82 @@ +use crate::structs::cloud::cloud_events::event_types::change_network_event::ChangeNetworkEvent; +use database::{db::Db, structs::event_type::EventType}; +use log::error; +use std::sync::Arc; + +pub async fn process_event_change_network( + event: &ChangeNetworkEvent, + app_id: &String, + db: &Arc, +) { + // Establish a new transaction + let mut tx = match db.connection_pool.begin().await { + Ok(tx) => tx, + Err(err) => { + error!( + "Failed to create new transaction to save change network event, app_id: [{}], event: [{:?}], err: [{}]", + app_id, event, err + ); + return; + } + }; + + // Create a new event index + let event_id = match db + .create_new_event_entry(&mut tx, &app_id, &EventType::ChangeNetwork) + .await + { + Ok(event_id) => event_id, + Err(err) => { + error!( + "Failed to create new event index, app_id: [{}], event: [{:?}], err: [{}]", + app_id, event, err + ); + + // Rollback the transaction + if let Err(err) = tx.rollback().await { + error!( + "Failed to rollback transaction for new change network event, app_id: [{}], event: [{:?}], err: [{}]", + app_id, event, err + ); + } + + return; + } + }; + + // Now create a new event change network corresponding to the event + match db + .create_new_event_change_network( + &mut tx, + event_id, + &event.session_id, + &event.request_id, + &event.old_network, + ) + .await + { + Ok(_) => { + // Commit the transaction + if let Err(err) = tx.commit().await { + error!( + "Failed to commit transaction for new change network event, app_id: [{}], event: [{:?}], err: [{}]", + app_id, event, err + ); + } + } + Err(err) => { + error!( + "Failed to create new change network event, app_id: [{}], event: [{:?}], err: [{}]", + app_id, event, err + ); + + // Rollback the transaction + if let Err(err) = tx.rollback().await { + error!( + "Failed to rollback transaction for new change network event, app_id: [{}], event: [{:?}], err: [{}]", + app_id, event, err + ); + } + } + } +} diff --git a/server/src/http/cloud/events/processors/process_event_change_network_resolve.rs b/server/src/http/cloud/events/processors/process_event_change_network_resolve.rs new file mode 100644 index 00000000..a6cff247 --- /dev/null +++ b/server/src/http/cloud/events/processors/process_event_change_network_resolve.rs @@ -0,0 +1,57 @@ +use crate::structs::cloud::cloud_events::event_types::change_network_resolve_event::ChangeNetworkResolveEvent; +use database::{db::Db, structs::request_status::RequestStatus}; +use log::error; +use std::sync::Arc; + +pub async fn process_event_change_network_resolve( + event: &ChangeNetworkResolveEvent, + app_id: &String, + db: &Arc, +) { + // Establish a new transaction + let mut tx = match db.connection_pool.begin().await { + Ok(tx) => tx, + Err(err) => { + error!( + "Failed to create new transaction to save change network event, app_id: [{}], event: [{:?}], err: [{}]", + app_id, event, err + ); + return; + } + }; + + // Update the change network event in the database + match db + .update_event_change_network( + &mut tx, + &event.request_id, + RequestStatus::from(&event.failure_reason), + &event.new_network, + ) + .await + { + Ok(_) => { + // Commit the transaction + if let Err(err) = tx.commit().await { + error!( + "Failed to commit transaction for update change network event, app_id: [{}], event: [{:?}], err: [{}]", + app_id, event, err + ); + } + } + Err(err) => { + error!( + "Failed to update change network status, app_id: [{}], event: [{:?}], err: [{}]", + app_id, event, err + ); + + // Rollback the transaction + if let Err(err) = tx.rollback().await { + error!( + "Failed to rollback transaction for update change network event, app_id: [{}], event: [{:?}], err: [{}]", + app_id, event, err + ); + } + } + } +} diff --git a/server/src/http/cloud/events/processors/process_event_change_wallet.rs b/server/src/http/cloud/events/processors/process_event_change_wallet.rs new file mode 100644 index 00000000..fd1fde1e --- /dev/null +++ b/server/src/http/cloud/events/processors/process_event_change_wallet.rs @@ -0,0 +1,81 @@ +use crate::structs::cloud::cloud_events::event_types::change_wallet_event::ChangeWalletEvent; +use database::{db::Db, structs::event_type::EventType}; +use log::error; +use std::sync::Arc; + +pub async fn process_event_change_wallet(event: &ChangeWalletEvent, app_id: &String, db: &Arc) { + // Establish a new transaction + let mut tx = match db.connection_pool.begin().await { + Ok(tx) => tx, + Err(err) => { + error!( + "Failed to create new transaction to save change wallet event, app_id: [{}], event: [{:?}], err: [{}]", + app_id, event, err + ); + return; + } + }; + + // Create a new event index + let event_id = match db + .create_new_event_entry(&mut tx, &app_id, &EventType::ChangeWallet) + .await + { + Ok(event_id) => event_id, + Err(err) => { + error!( + "Failed to create new event index, app_id: [{}], event: [{:?}], err: [{}]", + app_id, event, err + ); + + // Rollback the transaction + if let Err(err) = tx.rollback().await { + error!( + "Failed to rollback transaction for new change wallet event, app_id: [{}], event: [{:?}], err: [{}]", + app_id, event, err + ); + } + + return; + } + }; + + // Now create a new event change wallet corresponding to the event + match db + .create_new_event_change_wallet( + &mut tx, + event_id, + &event.session_id, + &event.request_id, + &event.network, + &event.wallet_name, + &event.wallet_type, + &event.old_wallet_address, + ) + .await + { + Ok(_) => { + // Commit the transaction + if let Err(err) = tx.commit().await { + error!( + "Failed to commit transaction for new change wallet event, app_id: [{}], event: [{:?}], err: [{}]", + app_id, event, err + ); + } + } + Err(err) => { + error!( + "Failed to create new change wallet event, app_id: [{}], event: [{:?}], err: [{}]", + app_id, event, err + ); + + // Rollback the transaction + if let Err(err) = tx.rollback().await { + error!( + "Failed to rollback transaction for new change wallet event, app_id: [{}], event: [{:?}], err: [{}]", + app_id, event, err + ); + } + } + } +} diff --git a/server/src/http/cloud/events/processors/process_event_change_wallet_resolve.rs b/server/src/http/cloud/events/processors/process_event_change_wallet_resolve.rs new file mode 100644 index 00000000..576c4e0f --- /dev/null +++ b/server/src/http/cloud/events/processors/process_event_change_wallet_resolve.rs @@ -0,0 +1,57 @@ +use crate::structs::cloud::cloud_events::event_types::change_wallet_resolve_event::ChangeWalletResolveEvent; +use database::{db::Db, structs::request_status::RequestStatus}; +use log::error; +use std::sync::Arc; + +pub async fn process_event_change_network_resolve( + event: &ChangeWalletResolveEvent, + app_id: &String, + db: &Arc, +) { + // Establish a new transaction + let mut tx = match db.connection_pool.begin().await { + Ok(tx) => tx, + Err(err) => { + error!( + "Failed to create new transaction to save change wallet event, app_id: [{}], event: [{:?}], err: [{}]", + app_id, event, err + ); + return; + } + }; + + // Update the change wallet event in the database + match db + .update_event_change_wallet( + &mut tx, + &event.request_id, + RequestStatus::from(&event.failure_reason), + &event.new_wallet_address, + ) + .await + { + Ok(_) => { + // Commit the transaction + if let Err(err) = tx.commit().await { + error!( + "Failed to commit transaction for update change wallet event, app_id: [{}], event: [{:?}], err: [{}]", + app_id, event, err + ); + } + } + Err(err) => { + error!( + "Failed to update change wallet status, app_id: [{}], event: [{:?}], err: [{}]", + app_id, event, err + ); + + // Rollback the transaction + if let Err(err) = tx.rollback().await { + error!( + "Failed to rollback transaction for update change wallet event, app_id: [{}], event: [{:?}], err: [{}]", + app_id, event, err + ); + } + } + } +} diff --git a/server/src/http/cloud/events/processors/process_event_client_connect.rs b/server/src/http/cloud/events/processors/process_event_client_connect.rs index 08e4804d..10f13a93 100644 --- a/server/src/http/cloud/events/processors/process_event_client_connect.rs +++ b/server/src/http/cloud/events/processors/process_event_client_connect.rs @@ -54,55 +54,29 @@ pub async fn process_event_client_connect_init( async fn save_event_client_connect(db: &Arc, app_id: &String, event: &ClientConnectEvent) { // Establish a new transaction - match db.connection_pool.begin().await { - Ok(mut tx) => { - // Create a new event index in the database - match db - .create_new_event_entry(&mut tx, &app_id, &EventType::ClientConnect) - .await - { - Ok(event_id) => { - // Now create a new event client connect corresponding to the event - match db - .create_new_event_client_connect( - &mut tx, - event_id, - &event.client_id, - &event.session_id, - &event.wallet_name, - &event.wallet_type, - &event.session_type, - ) - .await - { - Ok(_) => { - // Commit the transaction - if let Err(err) = tx.commit().await { - error!( - "Failed to commit transaction for new client connect event, app_id: [{}], event: [{:?}], err: [{}]", - app_id, event, err - ); - } + let mut tx = match db.connection_pool.begin().await { + Ok(tx) => tx, + Err(err) => { + error!( + "Failed to create new transaction to save client connect event, app_id: [{}], event: [{:?}], err: [{}]", + app_id, event, err + ); + return; + } + }; - return; - } - Err(err) => { - error!( - "Failed to create new client connect event, app_id: [{}], event: [{:?}], err: [{}]", - app_id, event, err - ); - } - } - } - Err(err) => { - error!( - "Failed to create new event index, app_id: [{}], event: [{:?}], err: [{}]", - app_id, event, err - ); - } - } + // Create a new event index + let event_id = match db + .create_new_event_entry(&mut tx, &app_id, &EventType::ClientConnect) + .await + { + Ok(event_id) => event_id, + Err(err) => { + error!( + "Failed to create new event index, app_id: [{}], event: [{:?}], err: [{}]", + app_id, event, err + ); - // If we have not returned yet, then we have failed to save the event // Rollback the transaction if let Err(err) = tx.rollback().await { error!( @@ -110,12 +84,46 @@ async fn save_event_client_connect(db: &Arc, app_id: &String, event: &Client app_id, event, err ); } + + return; + } + }; + + // Now create a event client connect corresponding to the event + match db + .create_new_event_client_connect( + &mut tx, + event_id, + &event.client_id, + &event.session_id, + &event.wallet_name, + &event.wallet_type, + &event.session_type, + ) + .await + { + Ok(_) => { + // Commit the transaction + if let Err(err) = tx.commit().await { + error!( + "Failed to commit transaction for new client connect event, app_id: [{}], event: [{:?}], err: [{}]", + app_id, event, err + ); + } } Err(err) => { error!( - "Failed to create new transaction to save client connect event, app_id: [{}], event: [{:?}], err: [{}]", + "Failed to create new client connect event, app_id: [{}], event: [{:?}], err: [{}]", app_id, event, err ); + + // Rollback the transaction + if let Err(err) = tx.rollback().await { + error!( + "Failed to rollback transaction for new client connect event, app_id: [{}], event: [{:?}], err: [{}]", + app_id, event, err + ); + } } } } diff --git a/server/src/http/cloud/events/processors/process_event_client_connect_resolve.rs b/server/src/http/cloud/events/processors/process_event_client_connect_resolve.rs index 2dd05e53..9ff47ae4 100644 --- a/server/src/http/cloud/events/processors/process_event_client_connect_resolve.rs +++ b/server/src/http/cloud/events/processors/process_event_client_connect_resolve.rs @@ -40,51 +40,50 @@ async fn save_event_client_connect_resolve( event: &ClientConnectResolveEvent, ) { // Establish a new transaction - match db.connection_pool.begin().await { - Ok(mut tx) => { - // Update the connection status for the user - match db - .update_event_client_connect( - &mut tx, - &event.client_id, - &event.session_id, - event.success, - &event.addresses, - ) - .await - { - Ok(_) => { - // Commit the transaction - if let Err(err) = tx.commit().await { - error!( - "Failed to commit transaction for update client connect event, app_id: [{}], event: [{:?}], err: [{}]", - app_id, event, err - ); - } - } - Err(err) => { - error!( - "Failed to update client connect status, app_id: [{}], event: [{:?}], err: [{}]", - app_id, event, err - ); - - // Rollback the transaction - if let Err(err) = tx.rollback().await { - error!( - "Failed to rollback transaction for update client connect event, app_id: [{}], event: [{:?}], err: [{}]", - app_id, event, err - ); + let mut tx = match db.connection_pool.begin().await { + Ok(tx) => tx, + Err(err) => { + error!( + "Failed to create new transaction to save client connect event, app_id: [{}], event: [{:?}], err: [{}]", + app_id, event, err + ); + return; + } + }; - return; - } - } + // Update the event in the database + match db + .update_event_client_connect( + &mut tx, + &event.client_id, + &event.session_id, + event.success, + &event.addresses, + ) + .await + { + Ok(_) => { + // Commit the transaction + if let Err(err) = tx.commit().await { + error!( + "Failed to commit transaction for update client connect event, app_id: [{}], event: [{:?}], err: [{}]", + app_id, event, err + ); } } Err(err) => { error!( - "Failed to create new transaction to save client disconnect event, app_id: [{}], event: [{:?}], err: [{}]", + "Failed to update client connect status, app_id: [{}], event: [{:?}], err: [{}]", app_id, event, err ); + + // Rollback the transaction + if let Err(err) = tx.rollback().await { + error!( + "Failed to rollback transaction for update client connect event, app_id: [{}], event: [{:?}], err: [{}]", + app_id, event, err + ); + } } } } diff --git a/server/src/http/cloud/events/processors/process_event_client_disconnect.rs b/server/src/http/cloud/events/processors/process_event_client_disconnect.rs index 7d8838dc..8cf89a00 100644 --- a/server/src/http/cloud/events/processors/process_event_client_disconnect.rs +++ b/server/src/http/cloud/events/processors/process_event_client_disconnect.rs @@ -43,52 +43,29 @@ async fn save_event_client_disconnect( event: &ClientDisconnectEvent, ) { // Establish a new transaction - match db.connection_pool.begin().await { - Ok(mut tx) => { - // Create a new event index in the database - match db - .create_new_event_entry(&mut tx, &app_id, &EventType::ClientDisconnect) - .await - { - Ok(event_id) => { - // Now create a new event client disconnect corresponding to the event - match db - .create_new_event_client_disconnect( - &mut tx, - event_id, - &event.client_id, - &event.disconnected_session_id, - ) - .await - { - Ok(_) => { - // Commit the transaction - if let Err(err) = tx.commit().await { - error!( - "Failed to commit transaction for new client disconnect event, app_id: [{}], event: [{:?}], err: [{}]", - app_id, event, err - ); - } + let mut tx = match db.connection_pool.begin().await { + Ok(tx) => tx, + Err(err) => { + error!( + "Failed to create new transaction to save client disconnect event, app_id: [{}], event: [{:?}], err: [{}]", + app_id, event, err + ); + return; + } + }; - return; - } - Err(err) => { - error!( - "Failed to create new client disconnect event, app_id: [{}], event: [{:?}], err: [{}]", - app_id, event, err - ); - } - } - } - Err(err) => { - error!( - "Failed to create new event index, app_id: [{}], event: [{:?}], err: [{}]", - app_id, event, err - ); - } - } + // Create a new event index + let event_id = match db + .create_new_event_entry(&mut tx, &app_id, &EventType::ClientDisconnect) + .await + { + Ok(event_id) => event_id, + Err(err) => { + error!( + "Failed to create new event index, app_id: [{}], event: [{:?}], err: [{}]", + app_id, event, err + ); - // If we have not returned yet, then we have failed to save the event // Rollback the transaction if let Err(err) = tx.rollback().await { error!( @@ -96,12 +73,43 @@ async fn save_event_client_disconnect( app_id, event, err ); } + + return; + } + }; + + // Now create a event client disconnect corresponding to the event + match db + .create_new_event_client_disconnect( + &mut tx, + event_id, + &event.client_id, + &event.disconnected_session_id, + ) + .await + { + Ok(_) => { + // Commit the transaction + if let Err(err) = tx.commit().await { + error!( + "Failed to commit transaction for new client disconnect event, app_id: [{}], event: [{:?}], err: [{}]", + app_id, event, err + ); + } } Err(err) => { error!( - "Failed to create new transaction to save client disconnect event, app_id: [{}], event: [{:?}], err: [{}]", + "Failed to create new client disconnect event, app_id: [{}], event: [{:?}], err: [{}]", app_id, event, err ); + + // Rollback the transaction + if let Err(err) = tx.rollback().await { + error!( + "Failed to rollback transaction for new client disconnect event, app_id: [{}], event: [{:?}], err: [{}]", + app_id, event, err + ); + } } } } diff --git a/server/src/http/cloud/events/processors/process_event_sign_and_send_transaction.rs b/server/src/http/cloud/events/processors/process_event_sign_and_send_transaction.rs new file mode 100644 index 00000000..875d6a2d --- /dev/null +++ b/server/src/http/cloud/events/processors/process_event_sign_and_send_transaction.rs @@ -0,0 +1,82 @@ +use crate::structs::cloud::cloud_events::event_types::sign_and_send_transaction_event::SignAndSendTransactionEvent; +use database::{db::Db, structs::event_type::EventType}; +use log::error; +use std::sync::Arc; + +pub async fn process_event_sign_and_send_transaction( + event: &SignAndSendTransactionEvent, + app_id: &String, + db: &Arc, +) { + // Establish a new transaction + let mut tx = match db.connection_pool.begin().await { + Ok(tx) => tx, + Err(err) => { + error!( + "Failed to create new transaction to save change network event, app_id: [{}], event: [{:?}], err: [{}]", + app_id, event, err + ); + return; + } + }; + + // Create a new event index + let event_id = match db + .create_new_event_entry(&mut tx, &app_id, &EventType::SignAndSendTransaction) + .await + { + Ok(event_id) => event_id, + Err(err) => { + error!( + "Failed to create new event index, app_id: [{}], event: [{:?}], err: [{}]", + app_id, event, err + ); + + // Rollback the transaction + if let Err(err) = tx.rollback().await { + error!( + "Failed to rollback transaction for new change network event, app_id: [{}], event: [{:?}], err: [{}]", + app_id, event, err + ); + } + + return; + } + }; + + // Now create a new event change network corresponding to the event + match db + .create_new_event_sign_transaction( + &mut tx, + event_id, + &event.session_id, + &event.request_id, + &event.network, + ) + .await + { + Ok(_) => { + // Commit the transaction + if let Err(err) = tx.commit().await { + error!( + "Failed to commit transaction for new change network event, app_id: [{}], event: [{:?}], err: [{}]", + app_id, event, err + ); + } + } + Err(err) => { + error!( + "Failed to create new change network event, app_id: [{}], event: [{:?}], err: [{}]", + app_id, event, err + ); + + // Rollback the transaction + if let Err(err) = tx.rollback().await { + error!( + "Failed to rollback transaction for new change network event, app_id: [{}], event: [{:?}], err: [{}]", + app_id, event, err + ); + } + } + } +} diff --git a/server/src/http/cloud/events/processors/process_event_sign_and_send_transaction_resolve.rs b/server/src/http/cloud/events/processors/process_event_sign_and_send_transaction_resolve.rs new file mode 100644 index 00000000..d4bea462 --- /dev/null +++ b/server/src/http/cloud/events/processors/process_event_sign_and_send_transaction_resolve.rs @@ -0,0 +1,57 @@ +use crate::structs::cloud::cloud_events::event_types::sign_and_send_transaction_resolve_event::SignAndSendTransactionResolveEvent; +use database::{db::Db, structs::request_status::RequestStatus}; +use log::error; +use std::sync::Arc; + +pub async fn process_event_sign_and_send_transaction_resolve( + event: &SignAndSendTransactionResolveEvent, + app_id: &String, + db: &Arc, +) { + // Establish a new transaction + let mut tx = match db.connection_pool.begin().await { + Ok(tx) => tx, + Err(err) => { + error!( + "Failed to create new transaction to save sign and send transaction event, app_id: [{}], event: [{:?}], err: [{}]", + app_id, event, err + ); + return; + } + }; + + // Update the sign and send transaction event in the database + match db + .update_event_sign_and_send_transaction( + &mut tx, + &event.request_id, + RequestStatus::from(&event.failure_reason), + &event.tx_hash, + ) + .await + { + Ok(_) => { + // Commit the transaction + if let Err(err) = tx.commit().await { + error!( + "Failed to commit transaction for update sign and send transaction event, app_id: [{}], event: [{:?}], err: [{}]", + app_id, event, err + ); + } + } + Err(err) => { + error!( + "Failed to update sign and send transaction status, app_id: [{}], event: [{:?}], err: [{}]", + app_id, event, err + ); + + // Rollback the transaction + if let Err(err) = tx.rollback().await { + error!( + "Failed to rollback transaction for update sign and send transaction event, app_id: [{}], event: [{:?}], err: [{}]", + app_id, event, err + ); + } + } + } +} diff --git a/server/src/http/cloud/events/processors/process_event_sign_message.rs b/server/src/http/cloud/events/processors/process_event_sign_message.rs new file mode 100644 index 00000000..c964b301 --- /dev/null +++ b/server/src/http/cloud/events/processors/process_event_sign_message.rs @@ -0,0 +1,78 @@ +use crate::structs::cloud::cloud_events::event_types::sign_message_event::SignMessageEvent; +use database::{db::Db, structs::event_type::EventType}; +use log::error; +use std::sync::Arc; + +pub async fn process_event_sign_message(event: &SignMessageEvent, app_id: &String, db: &Arc) { + // Establish a new transaction + let mut tx = match db.connection_pool.begin().await { + Ok(tx) => tx, + Err(err) => { + error!( + "Failed to create new transaction to save sign message event, app_id: [{}], event: [{:?}], err: [{}]", + app_id, event, err + ); + return; + } + }; + + // Create a new event index + let event_id = match db + .create_new_event_entry(&mut tx, &app_id, &EventType::SignMessage) + .await + { + Ok(event_id) => event_id, + Err(err) => { + error!( + "Failed to create new event index, app_id: [{}], event: [{:?}], err: [{}]", + app_id, event, err + ); + + // Rollback the transaction + if let Err(err) = tx.rollback().await { + error!( + "Failed to rollback transaction for new sign message event, app_id: [{}], event: [{:?}], err: [{}]", + app_id, event, err + ); + } + + return; + } + }; + + // Now create a new event sign message corresponding to the event + match db + .create_new_event_sign_message( + &mut tx, + event_id, + &event.session_id, + &event.request_id, + &event.network, + ) + .await + { + Ok(_) => { + // Commit the transaction + if let Err(err) = tx.commit().await { + error!( + "Failed to commit transaction for new sign message event, app_id: [{}], event: [{:?}], err: [{}]", + app_id, event, err + ); + } + } + Err(err) => { + error!( + "Failed to create new sign message event, app_id: [{}], event: [{:?}], err: [{}]", + app_id, event, err + ); + + // Rollback the transaction + if let Err(err) = tx.rollback().await { + error!( + "Failed to rollback transaction for new sign message event, app_id: [{}], event: [{:?}], err: [{}]", + app_id, event, err + ); + } + } + } +} diff --git a/server/src/http/cloud/events/processors/process_event_sign_message_resolve.rs b/server/src/http/cloud/events/processors/process_event_sign_message_resolve.rs new file mode 100644 index 00000000..7b7f4514 --- /dev/null +++ b/server/src/http/cloud/events/processors/process_event_sign_message_resolve.rs @@ -0,0 +1,56 @@ +use crate::structs::cloud::cloud_events::event_types::sign_message_resolve_event::SignMessageResolveEvent; +use database::{db::Db, structs::request_status::RequestStatus}; +use log::error; +use std::sync::Arc; + +pub async fn process_event_sign_message_resolve( + event: &SignMessageResolveEvent, + app_id: &String, + db: &Arc, +) { + // Establish a new transaction + let mut tx = match db.connection_pool.begin().await { + Ok(tx) => tx, + Err(err) => { + error!( + "Failed to create new transaction to save sign message event, app_id: [{}], event: [{:?}], err: [{}]", + app_id, event, err + ); + return; + } + }; + + // Update the sign message event in the database + match db + .update_event_sign_message( + &mut tx, + &event.request_id, + RequestStatus::from(&event.failure_reason), + ) + .await + { + Ok(_) => { + // Commit the transaction + if let Err(err) = tx.commit().await { + error!( + "Failed to commit transaction for update sign message event, app_id: [{}], event: [{:?}], err: [{}]", + app_id, event, err + ); + } + } + Err(err) => { + error!( + "Failed to update sign message status, app_id: [{}], event: [{:?}], err: [{}]", + app_id, event, err + ); + + // Rollback the transaction + if let Err(err) = tx.rollback().await { + error!( + "Failed to rollback transaction for update sign message event, app_id: [{}], event: [{:?}], err: [{}]", + app_id, event, err + ); + } + } + } +} diff --git a/server/src/http/cloud/events/processors/process_event_sign_transaction.rs b/server/src/http/cloud/events/processors/process_event_sign_transaction.rs new file mode 100644 index 00000000..c18dd78e --- /dev/null +++ b/server/src/http/cloud/events/processors/process_event_sign_transaction.rs @@ -0,0 +1,82 @@ +use crate::structs::cloud::cloud_events::event_types::sign_transaction_event::SignTransactionEvent; +use database::{db::Db, structs::event_type::EventType}; +use log::error; +use std::sync::Arc; + +pub async fn process_event_sign_transaction( + event: &SignTransactionEvent, + app_id: &String, + db: &Arc, +) { + // Establish a new transaction + let mut tx = match db.connection_pool.begin().await { + Ok(tx) => tx, + Err(err) => { + error!( + "Failed to create new transaction to save sign transaction event, app_id: [{}], event: [{:?}], err: [{}]", + app_id, event, err + ); + return; + } + }; + + // Create a new event index + let event_id = match db + .create_new_event_entry(&mut tx, &app_id, &EventType::SignTransaction) + .await + { + Ok(event_id) => event_id, + Err(err) => { + error!( + "Failed to create new event index, app_id: [{}], event: [{:?}], err: [{}]", + app_id, event, err + ); + + // Rollback the transaction + if let Err(err) = tx.rollback().await { + error!( + "Failed to rollback transaction for new sign transaction event, app_id: [{}], event: [{:?}], err: [{}]", + app_id, event, err + ); + } + + return; + } + }; + + // Now create a new event sign transaction corresponding to the event + match db + .create_new_event_sign_transaction( + &mut tx, + event_id, + &event.session_id, + &event.request_id, + &event.network, + ) + .await + { + Ok(_) => { + // Commit the transaction + if let Err(err) = tx.commit().await { + error!( + "Failed to commit transaction for new sign transaction event, app_id: [{}], event: [{:?}], err: [{}]", + app_id, event, err + ); + } + } + Err(err) => { + error!( + "Failed to create new sign transaction event, app_id: [{}], event: [{:?}], err: [{}]", + app_id, event, err + ); + + // Rollback the transaction + if let Err(err) = tx.rollback().await { + error!( + "Failed to rollback transaction for new sign transaction event, app_id: [{}], event: [{:?}], err: [{}]", + app_id, event, err + ); + } + } + } +} diff --git a/server/src/http/cloud/events/processors/process_event_sign_transaction_resolve.rs b/server/src/http/cloud/events/processors/process_event_sign_transaction_resolve.rs new file mode 100644 index 00000000..4119ce92 --- /dev/null +++ b/server/src/http/cloud/events/processors/process_event_sign_transaction_resolve.rs @@ -0,0 +1,57 @@ +use crate::structs::cloud::cloud_events::event_types::sign_transaction_resolve_event::SignTransactionResolveEvent; +use database::{db::Db, structs::request_status::RequestStatus}; +use log::error; +use std::sync::Arc; + +pub async fn process_event_sign_transaction_resolve( + event: &SignTransactionResolveEvent, + app_id: &String, + db: &Arc, +) { + // Establish a new transaction + let mut tx = match db.connection_pool.begin().await { + Ok(tx) => tx, + Err(err) => { + error!( + "Failed to create new transaction to save sign transaction event, app_id: [{}], event: [{:?}], err: [{}]", + app_id, event, err + ); + return; + } + }; + + // Update the sign transaction event in the database + match db + .update_event_sign_transaction( + &mut tx, + &event.request_id, + RequestStatus::from(&event.failure_reason), + &event.tx_hash, + ) + .await + { + Ok(_) => { + // Commit the transaction + if let Err(err) = tx.commit().await { + error!( + "Failed to commit transaction for update sign transaction event, app_id: [{}], event: [{:?}], err: [{}]", + app_id, event, err + ); + } + } + Err(err) => { + error!( + "Failed to update sign transaction status, app_id: [{}], event: [{:?}], err: [{}]", + app_id, event, err + ); + + // Rollback the transaction + if let Err(err) = tx.rollback().await { + error!( + "Failed to rollback transaction for update sign transaction event, app_id: [{}], event: [{:?}], err: [{}]", + app_id, event, err + ); + } + } + } +} diff --git a/server/src/structs/cloud/cloud_events/event_types/change_network_event.rs b/server/src/structs/cloud/cloud_events/event_types/change_network_event.rs index 3c1c75b4..3935c9d4 100644 --- a/server/src/structs/cloud/cloud_events/event_types/change_network_event.rs +++ b/server/src/structs/cloud/cloud_events/event_types/change_network_event.rs @@ -8,5 +8,4 @@ pub struct ChangeNetworkEvent { pub session_id: String, pub request_id: String, pub old_network: String, - pub new_network: String, } diff --git a/server/src/structs/cloud/cloud_events/event_types/change_network_resolve_event.rs b/server/src/structs/cloud/cloud_events/event_types/change_network_resolve_event.rs index 2bab7ec3..1175ee72 100644 --- a/server/src/structs/cloud/cloud_events/event_types/change_network_resolve_event.rs +++ b/server/src/structs/cloud/cloud_events/event_types/change_network_resolve_event.rs @@ -8,6 +8,7 @@ use ts_rs::TS; pub struct ChangeNetworkResolveEvent { pub session_id: String, pub request_id: String, + pub new_network: Option, #[ts(optional)] pub failure_reason: Option, }