-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #137 from nightly-labs/more-work-on-events
add rust types for new events tables
- Loading branch information
Showing
50 changed files
with
1,105 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 type EventType = "AppConnect" | "AppDisconnect" | "ClientConnectInit" | "ClientConnectResolve" | "ClientDisconnect" | "SignMessage" | "SignTransaction" | "SignAndSendTransaction" | "ChangeWallet" | "ChangeNetwork"; | ||
export type EventType = "AppConnect" | "AppDisconnect" | "ClientConnect" | "ClientDisconnect" | "SignMessage" | "SignTransaction" | "SignAndSendTransaction" | "ChangeWallet" | "ChangeNetwork"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
pub mod table_struct; | ||
pub mod update; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
use crate::structs::request_status::RequestStatus; | ||
use sqlx::{postgres::PgRow, FromRow, Row}; | ||
|
||
pub const EVENT_CHANGE_NETWORK_TABLE_NAME: &str = "event_change_network"; | ||
pub const EVENT_CHANGE_NETWORK_KEYS: &str = | ||
"event_id, session_id, request_id, request_status, old_network, new_network"; | ||
|
||
#[derive(Clone, Debug, Eq, PartialEq)] | ||
pub struct ChangeNetworkEvent { | ||
pub event_id: i64, | ||
pub session_id: String, | ||
pub request_id: String, | ||
pub request_status: RequestStatus, | ||
pub old_network: String, | ||
pub new_network: Option<String>, | ||
} | ||
|
||
impl FromRow<'_, PgRow> for ChangeNetworkEvent { | ||
fn from_row(row: &sqlx::postgres::PgRow) -> std::result::Result<Self, sqlx::Error> { | ||
Ok(ChangeNetworkEvent { | ||
event_id: row.get("event_id"), | ||
session_id: row.get("session_id"), | ||
request_id: row.get("request_id"), | ||
request_status: row.get("request_status"), | ||
old_network: row.get("old_network"), | ||
new_network: row.get("new_network"), | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
use crate::structs::request_status::RequestStatus; | ||
use crate::{ | ||
db::Db, | ||
structs::db_error::DbError, | ||
tables::events::change_network::table_struct::{ | ||
EVENT_CHANGE_NETWORK_KEYS, EVENT_CHANGE_NETWORK_TABLE_NAME, | ||
}, | ||
}; | ||
use sqlx::{query, Postgres, Transaction}; | ||
|
||
impl Db { | ||
pub async fn create_new_event_change_network( | ||
&self, | ||
tx: &mut Transaction<'_, Postgres>, | ||
event_id: i64, | ||
session_id: &String, | ||
request_id: &String, | ||
old_network: &String, | ||
) -> Result<(), DbError> { | ||
let query_body = format!( | ||
"INSERT INTO {EVENT_CHANGE_NETWORK_TABLE_NAME} ({EVENT_CHANGE_NETWORK_KEYS}) VALUES ($1, $2, $3, $4, $5, NULL)" | ||
); | ||
|
||
let query_result = query(&query_body) | ||
.bind(event_id) | ||
.bind(session_id) | ||
.bind(request_id) | ||
.bind(RequestStatus::Pending) | ||
.bind(old_network) | ||
.execute(&mut **tx) | ||
.await; | ||
|
||
match query_result { | ||
Ok(_) => Ok(()), | ||
Err(e) => Err(e).map_err(|e| e.into()), | ||
} | ||
} | ||
|
||
pub async fn update_event_change_network( | ||
&self, | ||
tx: &mut Transaction<'_, Postgres>, | ||
request_id: &String, | ||
request_status: RequestStatus, | ||
new_network: Option<String>, | ||
) -> Result<(), DbError> { | ||
let query_body = format!( | ||
"UPDATE {EVENT_CHANGE_NETWORK_TABLE_NAME} SET request_status = $1, new_network = $2 WHERE request_id = $3", | ||
); | ||
|
||
let query_result = query(&query_body) | ||
.bind(request_status) | ||
.bind(new_network) | ||
.bind(request_id) | ||
.execute(&mut **tx) | ||
.await; | ||
|
||
match query_result { | ||
Ok(_) => Ok(()), | ||
Err(e) => Err(e).map_err(|e| e.into()), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
pub mod table_struct; | ||
pub mod update; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
use crate::structs::request_status::RequestStatus; | ||
use sqlx::{postgres::PgRow, FromRow, Row}; | ||
|
||
pub const EVENT_CHANGE_WALLET_TABLE_NAME: &str = "event_change_wallet"; | ||
pub const EVENT_CHANGE_WALLET_KEYS: &str = | ||
"event_id, session_id, request_id, request_status, network, wallet_name, wallet_type, old_wallet_address, new_wallet_address"; | ||
|
||
#[derive(Clone, Debug, Eq, PartialEq)] | ||
pub struct ChangeWalletEvent { | ||
pub event_id: i64, | ||
pub session_id: String, | ||
pub request_id: String, | ||
pub request_status: RequestStatus, | ||
pub network: String, | ||
pub wallet_name: String, | ||
pub wallet_type: String, | ||
pub old_wallet_address: String, | ||
pub new_wallet_address: Option<String>, | ||
} | ||
|
||
impl FromRow<'_, PgRow> for ChangeWalletEvent { | ||
fn from_row(row: &sqlx::postgres::PgRow) -> std::result::Result<Self, sqlx::Error> { | ||
Ok(ChangeWalletEvent { | ||
event_id: row.get("event_id"), | ||
session_id: row.get("session_id"), | ||
request_id: row.get("request_id"), | ||
request_status: row.get("request_status"), | ||
network: row.get("network"), | ||
wallet_name: row.get("wallet_name"), | ||
wallet_type: row.get("wallet_type"), | ||
old_wallet_address: row.get("old_wallet_address"), | ||
new_wallet_address: row.get("new_wallet_address"), | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
use crate::structs::request_status::RequestStatus; | ||
use crate::{ | ||
db::Db, | ||
structs::db_error::DbError, | ||
tables::events::change_wallet::table_struct::{ | ||
EVENT_CHANGE_WALLET_KEYS, EVENT_CHANGE_WALLET_TABLE_NAME, | ||
}, | ||
}; | ||
use sqlx::{query, Postgres, Transaction}; | ||
|
||
impl Db { | ||
pub async fn create_new_event_change_wallet( | ||
&self, | ||
tx: &mut Transaction<'_, Postgres>, | ||
event_id: &i64, | ||
session_id: &String, | ||
request_id: &String, | ||
network_id: &String, | ||
wallet_name: &String, | ||
wallet_type: &String, | ||
old_wallet_address: &String, | ||
) -> Result<(), DbError> { | ||
let query_body = format!( | ||
"INSERT INTO {EVENT_CHANGE_WALLET_TABLE_NAME} ({EVENT_CHANGE_WALLET_KEYS}) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, NULL)" | ||
); | ||
|
||
let query_result = query(&query_body) | ||
.bind(event_id) | ||
.bind(session_id) | ||
.bind(request_id) | ||
.bind(RequestStatus::Pending) | ||
.bind(network_id) | ||
.bind(wallet_name) | ||
.bind(wallet_type) | ||
.bind(old_wallet_address) | ||
.execute(&mut **tx) | ||
.await; | ||
|
||
match query_result { | ||
Ok(_) => Ok(()), | ||
Err(e) => Err(e).map_err(|e| e.into()), | ||
} | ||
} | ||
|
||
pub async fn update_event_change_wallet( | ||
&self, | ||
tx: &mut Transaction<'_, Postgres>, | ||
request_id: &String, | ||
request_status: RequestStatus, | ||
new_wallet_address: Option<String>, | ||
) -> Result<(), DbError> { | ||
let query_body = format!( | ||
"UPDATE {EVENT_CHANGE_WALLET_TABLE_NAME} SET request_status = $1, new_wallet_address = $2 WHERE request_id = $3", | ||
); | ||
|
||
let query_result = query(&query_body) | ||
.bind(request_status) | ||
.bind(new_wallet_address) | ||
.bind(request_id) | ||
.execute(&mut **tx) | ||
.await; | ||
|
||
match query_result { | ||
Ok(_) => Ok(()), | ||
Err(e) => Err(e).map_err(|e| e.into()), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
pub mod table_struct; | ||
pub mod update; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
use sqlx::{postgres::PgRow, FromRow, Row}; | ||
|
||
pub const EVENT_CLIENT_CONNECT_TABLE_NAME: &str = "event_client_connect"; | ||
pub const EVENT_CLIENT_CONNECT_KEYS: &str = | ||
"event_id, client_id, session_id, addresses, wallet_name, wallet_type, session_type, success"; | ||
|
||
#[derive(Clone, Debug, Eq, PartialEq)] | ||
pub struct ClientConnectEvent { | ||
pub event_id: String, | ||
pub client_id: String, | ||
pub session_id: String, | ||
pub addresses: Vec<String>, | ||
pub wallet_name: String, | ||
pub wallet_type: String, | ||
pub session_type: String, | ||
pub success: bool, | ||
} | ||
|
||
impl FromRow<'_, PgRow> for ClientConnectEvent { | ||
fn from_row(row: &sqlx::postgres::PgRow) -> std::result::Result<Self, sqlx::Error> { | ||
Ok(ClientConnectEvent { | ||
event_id: row.get("event_id"), | ||
client_id: row.get("client_id"), | ||
session_id: row.get("session_id"), | ||
addresses: row.get("addresses"), | ||
wallet_name: row.get("wallet_name"), | ||
wallet_type: row.get("wallet_type"), | ||
session_type: row.get("session_type"), | ||
success: row.get("success"), | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
use crate::{ | ||
db::Db, | ||
structs::{db_error::DbError, session_type::SessionType}, | ||
tables::events::client_connect::table_struct::{ | ||
EVENT_CLIENT_CONNECT_KEYS, EVENT_CLIENT_CONNECT_TABLE_NAME, | ||
}, | ||
}; | ||
use sqlx::{query, Postgres, Transaction}; | ||
|
||
impl Db { | ||
pub async fn create_new_event_client_connect( | ||
&self, | ||
tx: &mut Transaction<'_, Postgres>, | ||
event_id: i64, | ||
client_id: &String, | ||
session_id: &String, | ||
wallet_name: &String, | ||
wallet_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)" | ||
); | ||
|
||
let query_result = query(&query_body) | ||
.bind(event_id) | ||
.bind(client_id) | ||
.bind(session_id) | ||
.bind(wallet_name) | ||
.bind(wallet_type) | ||
.bind(session_type) | ||
.execute(&mut **tx) | ||
.await; | ||
|
||
match query_result { | ||
Ok(_) => Ok(()), | ||
Err(e) => Err(e).map_err(|e| e.into()), | ||
} | ||
} | ||
|
||
pub async fn update_event_client_connect( | ||
&self, | ||
tx: &mut Transaction<'_, Postgres>, | ||
client_id: &String, | ||
session_id: &String, | ||
success: bool, | ||
new_addresses: &Vec<String>, | ||
) -> 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" | ||
); | ||
|
||
let query_result = query(&query_body) | ||
.bind(success) | ||
.bind(&new_addresses) | ||
.bind(client_id) | ||
.bind(session_id) | ||
.execute(&mut **tx) | ||
.await; | ||
|
||
match query_result { | ||
Ok(_) => Ok(()), | ||
Err(e) => Err(e).map_err(|e| e.into()), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
pub mod table_struct; | ||
pub mod update; |
Oops, something went wrong.