From 5536301ccac1f5aca23ed86471cf3518388a72c1 Mon Sep 17 00:00:00 2001 From: akhercha Date: Thu, 23 May 2024 16:46:54 +0200 Subject: [PATCH] feat: exportable members (#20) * feat(exportable_members): Exported schema * feat(exportable_members): updated package name * feat(exportable_members): added models to lib * feat(exportable_members): added types * feat: checkpoint model --------- Co-authored-by: 0xevolve --- Cargo.lock | 66 +++++++++++++++++++++++++-------------------------- Cargo.toml | 2 +- src/lib.rs | 5 ++++ src/models.rs | 50 ++++++++++++++++++++++++++++++++++++-- src/schema.rs | 52 +++++++++++++++++++++++++++++++++++++++- 5 files changed, 138 insertions(+), 37 deletions(-) create mode 100644 src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index 31cc8d0..fa4cca2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1323,39 +1323,6 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "monitoring" -version = "0.1.0" -dependencies = [ - "arc-swap", - "axum", - "axum-macros", - "bigdecimal 0.4.2", - "chrono", - "deadpool", - "diesel", - "diesel-async", - "diesel_derives 1.4.1", - "diesel_migrations", - "dotenv", - "env_logger", - "futures", - "hyper", - "lazy_static", - "log", - "num-bigint", - "phf", - "prometheus", - "reqwest", - "rstest", - "serde", - "starknet", - "strum", - "tokio", - "url", - "uuid 1.6.1", -] - [[package]] name = "multer" version = "2.1.0" @@ -1691,6 +1658,39 @@ dependencies = [ "vcpkg", ] +[[package]] +name = "pragma-monitoring" +version = "0.1.0" +dependencies = [ + "arc-swap", + "axum", + "axum-macros", + "bigdecimal 0.4.2", + "chrono", + "deadpool", + "diesel", + "diesel-async", + "diesel_derives 1.4.1", + "diesel_migrations", + "dotenv", + "env_logger", + "futures", + "hyper", + "lazy_static", + "log", + "num-bigint", + "phf", + "prometheus", + "reqwest", + "rstest", + "serde", + "starknet", + "strum", + "tokio", + "url", + "uuid 1.6.1", +] + [[package]] name = "primitive-types" version = "0.12.2" diff --git a/Cargo.toml b/Cargo.toml index 7daf3c5..a1f5c62 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "monitoring" +name = "pragma-monitoring" version = "0.1.0" edition = "2021" diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..c3310c3 --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,5 @@ +pub(crate) mod config; +pub(crate) mod constants; +pub mod models; +pub mod schema; +pub mod types; diff --git a/src/models.rs b/src/models.rs index 8b47bc9..f7c9254 100644 --- a/src/models.rs +++ b/src/models.rs @@ -1,9 +1,13 @@ -extern crate bigdecimal; -extern crate chrono; +// Generated by diesel_ext + +#![allow(unused)] +#![allow(clippy::all)] use bigdecimal::BigDecimal; use chrono::NaiveDateTime; use diesel::{Queryable, QueryableByName, Selectable}; +use num_bigint::BigInt; +use std::ops::Bound; #[derive(Debug, Queryable, Selectable, QueryableByName)] #[diesel(table_name = crate::schema::spot_entry)] @@ -43,3 +47,45 @@ pub struct FutureEntry { pub expiration_timestamp: Option, pub _cursor: i64, } + +#[derive(Queryable, Debug, QueryableByName, Selectable)] +#[diesel(primary_key(data_id))] +#[diesel(check_for_backend(diesel::pg::Pg))] +#[diesel(table_name = crate::schema::spot_checkpoints)] +pub struct SpotCheckpoint { + pub network: String, + pub pair_id: String, + pub data_id: String, + pub block_hash: String, + pub block_number: i64, + pub block_timestamp: NaiveDateTime, + pub transaction_hash: String, + pub price: BigDecimal, + pub sender_address: String, + pub aggregation_mode: BigDecimal, + pub _cursor: i64, + pub timestamp: NaiveDateTime, + pub nb_sources_aggregated: BigDecimal, +} + +#[derive(Queryable, Debug, QueryableByName, Selectable)] +#[diesel(primary_key(data_id))] +#[diesel(check_for_backend(diesel::pg::Pg))] +#[diesel(table_name = crate::schema::vrf_requests)] +pub struct VrfRequest { + pub network: String, + pub request_id: BigDecimal, + pub seed: BigDecimal, + pub created_at: NaiveDateTime, + pub created_at_tx: String, + pub callback_address: String, + pub callback_fee_limit: BigDecimal, + pub num_words: BigDecimal, + pub requestor_address: String, + pub updated_at: NaiveDateTime, + pub updated_at_tx: String, + pub status: BigDecimal, + pub minimum_block_number: BigDecimal, + pub _cursor: (Bound, Bound), + pub data_id: String, +} diff --git a/src/schema.rs b/src/schema.rs index 3003b96..3f8633d 100644 --- a/src/schema.rs +++ b/src/schema.rs @@ -78,7 +78,7 @@ diesel::table! { } diesel::table! { - spot_entry (timestamp) { + spot_entry (data_id) { #[max_length = 255] network -> Varchar, #[max_length = 255] @@ -102,6 +102,54 @@ diesel::table! { } } +diesel::table! { + mainnet_spot_checkpoints (pair_id) { + #[max_length = 255] + network -> Varchar, + #[max_length = 255] + pair_id -> Varchar, + #[max_length = 255] + data_id -> Varchar, + #[max_length = 255] + block_hash -> Varchar, + block_number -> Int8, + block_timestamp -> Timestamp, + #[max_length = 255] + transaction_hash -> Varchar, + price -> Numeric, + #[max_length = 255] + sender_address -> Varchar, + aggregation_mode -> Numeric, + _cursor -> Int8, + timestamp -> Timestamp, + nb_sources_aggregated -> Numeric, + } +} + +diesel::table! { + spot_checkpoints (data_id) { + #[max_length = 255] + network -> Varchar, + #[max_length = 255] + pair_id -> Varchar, + #[max_length = 255] + data_id -> Varchar, + #[max_length = 255] + block_hash -> Varchar, + block_number -> Int8, + block_timestamp -> Timestamp, + #[max_length = 255] + transaction_hash -> Varchar, + price -> Numeric, + #[max_length = 255] + sender_address -> Varchar, + aggregation_mode -> Numeric, + _cursor -> Int8, + timestamp -> Timestamp, + nb_sources_aggregated -> Numeric, + } +} + diesel::table! { vrf_requests (data_id) { #[max_length = 255] @@ -127,7 +175,9 @@ diesel::table! { diesel::allow_tables_to_appear_in_same_query!( future_entry, mainnet_future_entry, + mainnet_spot_checkpoints, mainnet_spot_entry, + spot_checkpoints, spot_entry, vrf_requests, );