From 3aa82dec21229b59737886fd9fbde8d4fd723d94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CGiems=E2=80=9D?= <“hubert.wabia@gmail.com”> Date: Thu, 21 Mar 2024 11:03:12 +0100 Subject: [PATCH] update existing event handlers --- .../tables/events/client_connect/update.rs | 8 +- .../src/tables/events/events_index/update.rs | 11 +- .../src/http/cloud/events/events_handler.rs | 4 +- .../src/http/cloud/events/processors/mod.rs | 2 +- .../processors/process_event_app_connect.rs | 79 +++++++++++- .../process_event_app_disconnect.rs | 65 +++++++++- .../process_event_client_connect.rs | 121 ++++++++++++++++++ .../process_event_client_connect_init.rs | 50 -------- .../process_event_client_connect_resolve.rs | 98 +++++++++++--- .../process_event_client_disconnect.rs | 74 ++++++++++- ..._init_event.rs => client_connect_event.rs} | 2 +- .../client_connect_resolve_event.rs | 2 + .../event_types/client_disconnect_event.rs | 1 + .../cloud/cloud_events/event_types/mod.rs | 2 +- .../src/structs/cloud/cloud_events/events.rs | 4 +- server/src/structs/cloud/device_metadata.rs | 10 ++ server/src/structs/common.rs | 2 +- 17 files changed, 443 insertions(+), 92 deletions(-) create mode 100644 server/src/http/cloud/events/processors/process_event_client_connect.rs delete mode 100644 server/src/http/cloud/events/processors/process_event_client_connect_init.rs rename server/src/structs/cloud/cloud_events/event_types/{client_connect_init_event.rs => client_connect_event.rs} (91%) diff --git a/database/src/tables/events/client_connect/update.rs b/database/src/tables/events/client_connect/update.rs index d39b0706..7d3b10dd 100644 --- a/database/src/tables/events/client_connect/update.rs +++ b/database/src/tables/events/client_connect/update.rs @@ -1,6 +1,6 @@ use crate::{ db::Db, - structs::db_error::DbError, + structs::{db_error::DbError, session_type::SessionType}, tables::events::client_connect::table_struct::{ EVENT_CLIENT_CONNECT_KEYS, EVENT_CLIENT_CONNECT_TABLE_NAME, }, @@ -16,7 +16,7 @@ impl Db { session_id: &String, wallet_name: &String, wallet_type: &String, - session_type: &String, + session_type: &SessionType, ) -> Result<(), DbError> { let query_body = format!( "INSERT INTO {EVENT_CLIENT_CONNECT_TABLE_NAME} ({EVENT_CLIENT_CONNECT_KEYS}) VALUES ($1, $2, $3, NULL, $4, $5, $6, false)" @@ -38,13 +38,13 @@ impl Db { } } - pub async fn update_event_client_connect_success( + pub async fn update_event_client_connect( &self, tx: &mut Transaction<'_, Postgres>, client_id: &String, session_id: &String, success: bool, - new_addresses: Vec, + new_addresses: &Vec, ) -> Result<(), DbError> { let query_body = format!( "UPDATE {EVENT_CLIENT_CONNECT_TABLE_NAME} SET success = $1, addresses = $2 WHERE client_id = $3 AND session_id = $4 AND success = false" diff --git a/database/src/tables/events/events_index/update.rs b/database/src/tables/events/events_index/update.rs index 9ed47a7e..e4b86cde 100644 --- a/database/src/tables/events/events_index/update.rs +++ b/database/src/tables/events/events_index/update.rs @@ -3,8 +3,7 @@ use crate::{ structs::{db_error::DbError, event_type::EventType}, tables::events::events_index::table_struct::{EVENTS_KEYS, EVENTS_TABLE_NAME}, }; -use sqlx::Transaction; -use sqlx::{query, Postgres}; +use sqlx::{query, Postgres, Row, Transaction}; impl Db { pub async fn create_new_event_entry( @@ -12,19 +11,19 @@ impl Db { tx: &mut Transaction<'_, Postgres>, app_id: &String, event_type: &EventType, - ) -> Result<(), DbError> { + ) -> Result { let query_body = format!( - "INSERT INTO {EVENTS_TABLE_NAME} ({EVENTS_KEYS}) VALUES (DEFAULT, $1, $2, DEFAULT)" + "INSERT INTO {EVENTS_TABLE_NAME} ({EVENTS_KEYS}) VALUES (DEFAULT, $1, $2, DEFAULT) RETURNING event_id" ); let query_result = query(&query_body) .bind(app_id) .bind(event_type) - .execute(&mut **tx) + .fetch_one(&mut **tx) .await; match query_result { - Ok(_) => Ok(()), + Ok(row) => Ok(row.get("event_id")), Err(e) => Err(e).map_err(|e| e.into()), } } diff --git a/server/src/http/cloud/events/events_handler.rs b/server/src/http/cloud/events/events_handler.rs index 5a95137a..4c04314f 100644 --- a/server/src/http/cloud/events/events_handler.rs +++ b/server/src/http/cloud/events/events_handler.rs @@ -3,7 +3,7 @@ use super::{ processors::{ process_event_app_connect::process_event_app_connect, process_event_app_disconnect::process_event_app_disconnect, - process_event_client_connect_init::process_event_client_connect_init, + 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, }, @@ -37,7 +37,7 @@ pub async fn process_event( EventData::AppDisconnect(event) => { process_event_app_disconnect(event, &event_payload.app_id, ip, db_connection).await; } - EventData::ClientConnectInit(event) => { + EventData::ClientConnect(event) => { process_event_client_connect_init( event, &event_payload.app_id, diff --git a/server/src/http/cloud/events/processors/mod.rs b/server/src/http/cloud/events/processors/mod.rs index 7d8de239..66ea5480 100644 --- a/server/src/http/cloud/events/processors/mod.rs +++ b/server/src/http/cloud/events/processors/mod.rs @@ -1,5 +1,5 @@ pub mod process_event_app_connect; pub mod process_event_app_disconnect; -pub mod process_event_client_connect_init; +pub mod process_event_client_connect; pub mod process_event_client_connect_resolve; pub mod process_event_client_disconnect; 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 0a690f6c..f74abfc9 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 @@ -5,6 +5,7 @@ use crate::{ }; use database::{ db::Db, + structs::event_type::EventType, tables::{ sessions::table_struct::DbNcSession, utils::{get_current_datetime, get_date_time}, @@ -21,6 +22,9 @@ pub async fn process_event_app_connect( geo_loc_requester: &Arc, sessions: &Sessions, ) { + // Save event to Db + save_event_app_connect(db, app_id, event).await; + if event.new_session { // New session, get the data from sessions and create a new session in the database let session_data = { @@ -98,17 +102,88 @@ pub async fn process_event_app_connect( // Commit the transaction if let Err(err) = tx.commit().await { error!( - "Failed to commit transaction for new app connection event, app_id: [{}], ip: [{}], event: [{:?}], err: [{}]", + "Failed to commit transaction for new app connection, app_id: [{}], ip: [{}], event: [{:?}], err: [{}]", app_id, ip, event, err ); } } Err(err) => { error!( - "Failed to create new connection event, app_id: [{}], ip: [{}], event: [{:?}], err: [{}]", + "Failed to create new connection, app_id: [{}], ip: [{}], event: [{:?}], err: [{}]", app_id, ip, event, err ); } } } } + +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 + ); + } + + 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 + ); + } + } + + // 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!( + "Failed to rollback 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: [{}]", + 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 1a9d81de..824326e9 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 @@ -1,5 +1,5 @@ use crate::structs::cloud::cloud_events::event_types::app_disconnect_event::AppDisconnectEvent; -use database::db::Db; +use database::{db::Db, structs::event_type::EventType}; use log::error; use std::{net::SocketAddr, sync::Arc}; @@ -9,6 +9,9 @@ pub async fn process_event_app_disconnect( ip: SocketAddr, db: &Arc, ) { + // Save event to Db + save_event_app_disconnect(db, app_id, event).await; + // Close app connection in the database if let Err(err) = db.close_app_connection(&event.session_id, &app_id).await { error!( @@ -17,3 +20,63 @@ 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 + ); + } + + 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 + ); + } + } + + // 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!( + "Failed to rollback 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: [{}]", + 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 new file mode 100644 index 00000000..08e4804d --- /dev/null +++ b/server/src/http/cloud/events/processors/process_event_client_connect.rs @@ -0,0 +1,121 @@ +use crate::{ + ip_geolocation::GeolocationRequester, + structs::cloud::cloud_events::event_types::client_connect_event::ClientConnectEvent, + utils::get_geolocation_data, +}; +use database::{db::Db, structs::event_type::EventType}; +use log::error; +use std::{net::SocketAddr, sync::Arc}; + +pub async fn process_event_client_connect_init( + event: &ClientConnectEvent, + app_id: &String, + ip: SocketAddr, + db: &Arc, + geo_loc_requester: &Arc, +) { + // Save event to Db + save_event_client_connect(db, app_id, event).await; + + // Save connection attempt by client + let mut tx = db.connection_pool.begin().await.unwrap(); + + // Get the geolocation data + let geo_location_data = get_geolocation_data(&db, &geo_loc_requester, &ip).await; + + match db + .create_new_connection_event_by_client( + &mut tx, + &app_id, + &event.session_id, + &event.session_type, + &ip.to_string(), + geo_location_data, + ) + .await + { + Ok(_) => { + // Commit the transaction + if let Err(err) = tx.commit().await { + error!( + "Failed to commit transaction for new app connection event, app_id: [{}], ip: [{}], event: [{:?}], err: [{}]", + app_id, ip, event, err + ); + } + } + Err(err) => { + error!( + "Failed to create new connection event, app_id: [{}], ip: [{}], event: [{:?}], err: [{}]", + app_id, ip, event, err + ); + } + } +} + +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 + ); + } + + 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 + ); + } + } + + // 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!( + "Failed to rollback 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: [{}]", + app_id, event, err + ); + } + } +} diff --git a/server/src/http/cloud/events/processors/process_event_client_connect_init.rs b/server/src/http/cloud/events/processors/process_event_client_connect_init.rs deleted file mode 100644 index c756d2ac..00000000 --- a/server/src/http/cloud/events/processors/process_event_client_connect_init.rs +++ /dev/null @@ -1,50 +0,0 @@ -use crate::{ - ip_geolocation::GeolocationRequester, - structs::cloud::cloud_events::event_types::client_connect_init_event::ClientConnectInitEvent, - utils::get_geolocation_data, -}; -use database::db::Db; -use log::error; -use std::{net::SocketAddr, sync::Arc}; - -pub async fn process_event_client_connect_init( - event: &ClientConnectInitEvent, - app_id: &String, - ip: SocketAddr, - db: &Arc, - geo_loc_requester: &Arc, -) { - // Save connection attempt by client - let mut tx = db.connection_pool.begin().await.unwrap(); - - // Get the geolocation data - let geo_location_data = get_geolocation_data(&db, &geo_loc_requester, &ip).await; - - match db - .create_new_connection_event_by_client( - &mut tx, - &app_id, - &event.session_id, - &event.session_type, - &ip.to_string(), - geo_location_data, - ) - .await - { - Ok(_) => { - // Commit the transaction - if let Err(err) = tx.commit().await { - error!( - "Failed to commit transaction for new app connection event, app_id: [{}], ip: [{}], event: [{:?}], err: [{}]", - app_id, ip, event, err - ); - } - } - Err(err) => { - error!( - "Failed to create new connection event, app_id: [{}], ip: [{}], event: [{:?}], err: [{}]", - app_id, ip, 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 faa557da..2dd05e53 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 @@ -9,24 +9,82 @@ pub async fn process_event_client_connect_resolve( ip: SocketAddr, db: &Arc, ) { - // // Check if connection attempt by client was successful, if not then there is nothing to do - // if event.success { - // if let Err(err) = db - // .connect_user_to_the_session( - // &event.client_id, - // &event.wallet_name, - // &event.wallet_type, - // &get_current_datetime(), - // &event.public_keys, - // &app_id.clone(), - // &event.session_id, - // ) - // .await - // { - // error!( - // "Failed to process user successful connect, app_id: [{}], ip: [{}], event: [{:?}], err: [{}]", - // app_id, ip, event, err - // ); - // } - // } + // Save event to Db + save_event_client_connect_resolve(db, app_id, event).await; + + // Check if connection attempt by client was successful, if not then there is nothing to do + if event.success { + if let Err(err) = db + .connect_user_to_the_session( + &event.client_id, + &event.wallet_name, + &event.wallet_type, + &get_current_datetime(), + &event.addresses, + &app_id.clone(), + &event.session_id, + ) + .await + { + error!( + "Failed to process user successful connect, app_id: [{}], ip: [{}], event: [{:?}], err: [{}]", + app_id, ip, event, err + ); + } + } +} + +async fn save_event_client_connect_resolve( + db: &Arc, + app_id: &String, + 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 + ); + + return; + } + } + } + } + Err(err) => { + error!( + "Failed to create new transaction to save client disconnect 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 5d971d83..7d8838dc 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 @@ -1,5 +1,5 @@ use crate::structs::cloud::cloud_events::event_types::client_disconnect_event::ClientDisconnectEvent; -use database::db::Db; +use database::{db::Db, structs::event_type::EventType}; use log::error; use std::{net::SocketAddr, sync::Arc}; @@ -9,6 +9,9 @@ pub async fn process_event_client_disconnect( ip: SocketAddr, db: &Arc, ) { + // Save event to Db + save_event_client_disconnect(db, app_id, event).await; + // Update connection status for user let mut tx = db.connection_pool.begin().await.unwrap(); @@ -33,3 +36,72 @@ pub async fn process_event_client_disconnect( } } } + +async fn save_event_client_disconnect( + db: &Arc, + app_id: &String, + 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 + ); + } + + 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 + ); + } + } + + // 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!( + "Failed to rollback 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: [{}]", + app_id, event, err + ); + } + } +} diff --git a/server/src/structs/cloud/cloud_events/event_types/client_connect_init_event.rs b/server/src/structs/cloud/cloud_events/event_types/client_connect_event.rs similarity index 91% rename from server/src/structs/cloud/cloud_events/event_types/client_connect_init_event.rs rename to server/src/structs/cloud/cloud_events/event_types/client_connect_event.rs index 3bc100d7..55a57b72 100644 --- a/server/src/structs/cloud/cloud_events/event_types/client_connect_init_event.rs +++ b/server/src/structs/cloud/cloud_events/event_types/client_connect_event.rs @@ -5,7 +5,7 @@ use ts_rs::TS; #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, TS)] #[ts(export)] #[serde(rename_all = "camelCase")] -pub struct ClientConnectInitEvent { +pub struct ClientConnectEvent { pub client_id: String, pub session_id: String, pub wallet_name: String, diff --git a/server/src/structs/cloud/cloud_events/event_types/client_connect_resolve_event.rs b/server/src/structs/cloud/cloud_events/event_types/client_connect_resolve_event.rs index b567b764..6cfe83a3 100644 --- a/server/src/structs/cloud/cloud_events/event_types/client_connect_resolve_event.rs +++ b/server/src/structs/cloud/cloud_events/event_types/client_connect_resolve_event.rs @@ -8,5 +8,7 @@ pub struct ClientConnectResolveEvent { pub client_id: String, pub session_id: String, pub addresses: Vec, + pub wallet_name: String, + pub wallet_type: String, pub success: bool, } diff --git a/server/src/structs/cloud/cloud_events/event_types/client_disconnect_event.rs b/server/src/structs/cloud/cloud_events/event_types/client_disconnect_event.rs index e69d14ba..1ba2b7b3 100644 --- a/server/src/structs/cloud/cloud_events/event_types/client_disconnect_event.rs +++ b/server/src/structs/cloud/cloud_events/event_types/client_disconnect_event.rs @@ -5,5 +5,6 @@ use ts_rs::TS; #[ts(export)] #[serde(rename_all = "camelCase")] pub struct ClientDisconnectEvent { + pub client_id: String, pub disconnected_session_id: String, } diff --git a/server/src/structs/cloud/cloud_events/event_types/mod.rs b/server/src/structs/cloud/cloud_events/event_types/mod.rs index 472a7a8d..efb7f919 100644 --- a/server/src/structs/cloud/cloud_events/event_types/mod.rs +++ b/server/src/structs/cloud/cloud_events/event_types/mod.rs @@ -4,7 +4,7 @@ pub mod change_network_event; pub mod change_network_resolve_event; pub mod change_wallet_event; pub mod change_wallet_resolve_event; -pub mod client_connect_init_event; +pub mod client_connect_event; pub mod client_connect_resolve_event; pub mod client_disconnect_event; pub mod sign_and_send_transaction_event; diff --git a/server/src/structs/cloud/cloud_events/events.rs b/server/src/structs/cloud/cloud_events/events.rs index 2e26e8e1..03316ec3 100644 --- a/server/src/structs/cloud/cloud_events/events.rs +++ b/server/src/structs/cloud/cloud_events/events.rs @@ -1,7 +1,7 @@ use super::event_types::{ app_connect_event::AppConnectEvent, app_disconnect_event::AppDisconnectEvent, change_network_event::ChangeNetworkEvent, change_wallet_event::ChangeWalletEvent, - client_connect_init_event::ClientConnectInitEvent, + client_connect_event::ClientConnectEvent, client_connect_resolve_event::ClientConnectResolveEvent, client_disconnect_event::ClientDisconnectEvent, sign_and_send_transaction_event::SignAndSendTransactionEvent, @@ -19,7 +19,7 @@ use ts_rs::TS; pub enum EventData { AppConnect(AppConnectEvent), AppDisconnect(AppDisconnectEvent), - ClientConnectInit(ClientConnectInitEvent), + ClientConnect(ClientConnectEvent), ClientConnectResolve(ClientConnectResolveEvent), ClientDisconnect(ClientDisconnectEvent), SignMessage(SignMessageEvent), diff --git a/server/src/structs/cloud/device_metadata.rs b/server/src/structs/cloud/device_metadata.rs index 0e2765a5..a1b447da 100644 --- a/server/src/structs/cloud/device_metadata.rs +++ b/server/src/structs/cloud/device_metadata.rs @@ -27,3 +27,13 @@ pub struct WebMetadata { pub os: String, pub os_version: String, } + +impl DeviceMetadata { + pub fn to_string(&self) -> Result { + serde_json::to_string(self) + } + + pub fn from_string(s: &str) -> Result { + serde_json::from_str(s) + } +} diff --git a/server/src/structs/common.rs b/server/src/structs/common.rs index c8d47eac..0612eaa8 100644 --- a/server/src/structs/common.rs +++ b/server/src/structs/common.rs @@ -38,7 +38,7 @@ pub enum SessionStatus { Idle, // Both disconnected, but session is still alive for a while in case client reconnects } -#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize, TS)] +#[derive(Debug, Display, Clone, PartialEq, Eq, Hash, Serialize, Deserialize, TS)] #[ts(export)] pub enum Device { Apple,