Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dev: Updated NaiveDateTime to DateTime<Utc> #21

Merged
merged 2 commits into from
Jun 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ pub struct Config {
/// inspired from here - https://github.com/matklad/once_cell/issues/127
pub static CONFIG: OnceCell<ArcSwap<Config>> = OnceCell::const_new();

#[allow(dead_code)]
impl Config {
pub async fn new(config_input: ConfigInput) -> Self {
let indexer_url =
Expand Down Expand Up @@ -166,6 +167,7 @@ pub struct ConfigInput {
pub future_pairs: Vec<String>,
}

#[allow(dead_code)]
pub async fn get_config(config_input: Option<ConfigInput>) -> Guard<Arc<Config>> {
let cfg = CONFIG
.get_or_init(|| async {
Expand All @@ -181,6 +183,7 @@ pub async fn get_config(config_input: Option<ConfigInput>) -> Guard<Arc<Config>>
/// This function is used to periodically update the configuration settings
/// from the environment variables. This is useful when we want to update the
/// configuration settings without restarting the service.
#[allow(dead_code)]
pub async fn periodic_config_update() {
let interval = Duration::from_secs(CONFIG_UPDATE_INTERVAL); // Set the update interval as needed (3 hours in this example)

Expand All @@ -206,6 +209,7 @@ pub async fn periodic_config_update() {
/// set it up again for reuse in new tests. By calling `config_force_init` we replace the already
/// stored config inside `ArcSwap` with the new configuration and pool settings.
#[cfg(test)]
#[allow(dead_code)]
pub async fn config_force_init(config_input: ConfigInput) {
match CONFIG.get() {
Some(arc) => arc.store(Arc::new(Config::new(config_input).await)),
Expand Down
3 changes: 3 additions & 0 deletions src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use lazy_static::lazy_static;
use phf::phf_map;
use prometheus::{opts, register_gauge_vec, register_int_gauge_vec, GaugeVec, IntGaugeVec};

#[allow(dead_code)]
pub(crate) static COINGECKO_IDS: phf::Map<&'static str, &'static str> = phf_map! {
"BTC/USD" => "bitcoin",
"ETH/USD" => "ethereum",
Expand Down Expand Up @@ -117,7 +118,9 @@ lazy_static! {
.unwrap();
}

#[allow(dead_code)]
pub const FEE_TOKEN_DECIMALS: i32 = 18;
#[allow(dead_code)]
pub const FEE_TOKEN_ADDRESS: &str =
"0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7";

Expand Down
20 changes: 10 additions & 10 deletions src/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#![allow(clippy::all)]

use bigdecimal::BigDecimal;
use chrono::NaiveDateTime;
use chrono::{DateTime, Utc};
use diesel::{Queryable, QueryableByName, Selectable};
use num_bigint::BigInt;
use std::ops::Bound;
Expand All @@ -18,10 +18,10 @@ pub struct SpotEntry {
pub data_id: String,
pub block_hash: String,
pub block_number: i64,
pub block_timestamp: NaiveDateTime,
pub block_timestamp: DateTime<Utc>,
pub transaction_hash: String,
pub price: BigDecimal,
pub timestamp: chrono::NaiveDateTime,
pub timestamp: DateTime<Utc>,
pub publisher: String,
pub source: String,
pub volume: BigDecimal,
Expand All @@ -37,14 +37,14 @@ pub struct FutureEntry {
pub data_id: String,
pub block_hash: String,
pub block_number: i64,
pub block_timestamp: NaiveDateTime,
pub block_timestamp: DateTime<Utc>,
pub transaction_hash: String,
pub price: BigDecimal,
pub timestamp: chrono::NaiveDateTime,
pub timestamp: DateTime<Utc>,
pub publisher: String,
pub source: String,
pub volume: BigDecimal,
pub expiration_timestamp: Option<chrono::NaiveDateTime>,
pub expiration_timestamp: Option<DateTime<Utc>>,
pub _cursor: i64,
}

Expand All @@ -58,13 +58,13 @@ pub struct SpotCheckpoint {
pub data_id: String,
pub block_hash: String,
pub block_number: i64,
pub block_timestamp: NaiveDateTime,
pub block_timestamp: DateTime<Utc>,
pub transaction_hash: String,
pub price: BigDecimal,
pub sender_address: String,
pub aggregation_mode: BigDecimal,
pub _cursor: i64,
pub timestamp: NaiveDateTime,
pub timestamp: DateTime<Utc>,
pub nb_sources_aggregated: BigDecimal,
}

Expand All @@ -76,13 +76,13 @@ pub struct VrfRequest {
pub network: String,
pub request_id: BigDecimal,
pub seed: BigDecimal,
pub created_at: NaiveDateTime,
pub created_at: DateTime<Utc>,
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: DateTime<Utc>,
pub updated_at_tx: String,
pub status: BigDecimal,
pub minimum_block_number: BigDecimal,
Expand Down
2 changes: 1 addition & 1 deletion src/monitoring/time_since_last_update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::time::SystemTime;

/// Calculate the time since the last update in seconds.
pub fn time_since_last_update<T: Entry>(query: &T) -> u64 {
let datetime: DateTime<Utc> = TimeZone::from_utc_datetime(&Utc, &query.timestamp());
let datetime: DateTime<Utc> = query.timestamp();
let timestamp = datetime.timestamp();
let now = SystemTime::now().duration_since(SystemTime::UNIX_EPOCH);

Expand Down
32 changes: 16 additions & 16 deletions src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ diesel::table! {
#[max_length = 255]
block_hash -> Varchar,
block_number -> Int8,
block_timestamp -> Timestamp,
block_timestamp -> Timestamptz,
#[max_length = 255]
transaction_hash -> Varchar,
price -> Numeric,
timestamp -> Timestamp,
timestamp -> Timestamptz,
#[max_length = 255]
publisher -> Varchar,
#[max_length = 255]
source -> Varchar,
volume -> Numeric,
expiration_timestamp -> Nullable<Timestamp>,
expiration_timestamp -> Nullable<Timestamptz>,
_cursor -> Int8,
}
}
Expand All @@ -37,17 +37,17 @@ diesel::table! {
#[max_length = 255]
block_hash -> Varchar,
block_number -> Int8,
block_timestamp -> Timestamp,
block_timestamp -> Timestamptz,
#[max_length = 255]
transaction_hash -> Varchar,
price -> Numeric,
timestamp -> Timestamp,
timestamp -> Timestamptz,
#[max_length = 255]
publisher -> Varchar,
#[max_length = 255]
source -> Varchar,
volume -> Numeric,
expiration_timestamp -> Nullable<Timestamp>,
expiration_timestamp -> Nullable<Timestamptz>,
_cursor -> Int8,
}
}
Expand All @@ -63,11 +63,11 @@ diesel::table! {
#[max_length = 255]
block_hash -> Varchar,
block_number -> Int8,
block_timestamp -> Timestamp,
block_timestamp -> Timestamptz,
#[max_length = 255]
transaction_hash -> Varchar,
price -> Numeric,
timestamp -> Timestamp,
timestamp -> Timestamptz,
#[max_length = 255]
publisher -> Varchar,
#[max_length = 255]
Expand All @@ -88,11 +88,11 @@ diesel::table! {
#[max_length = 255]
block_hash -> Varchar,
block_number -> Int8,
block_timestamp -> Timestamp,
block_timestamp -> Timestamptz,
#[max_length = 255]
transaction_hash -> Varchar,
price -> Numeric,
timestamp -> Timestamp,
timestamp -> Timestamptz,
#[max_length = 255]
publisher -> Varchar,
#[max_length = 255]
Expand All @@ -113,15 +113,15 @@ diesel::table! {
#[max_length = 255]
block_hash -> Varchar,
block_number -> Int8,
block_timestamp -> Timestamp,
block_timestamp -> Timestamptz,
#[max_length = 255]
transaction_hash -> Varchar,
price -> Numeric,
#[max_length = 255]
sender_address -> Varchar,
aggregation_mode -> Numeric,
_cursor -> Int8,
timestamp -> Timestamp,
timestamp -> Timestamptz,
nb_sources_aggregated -> Numeric,
}
}
Expand All @@ -137,15 +137,15 @@ diesel::table! {
#[max_length = 255]
block_hash -> Varchar,
block_number -> Int8,
block_timestamp -> Timestamp,
block_timestamp -> Timestamptz,
#[max_length = 255]
transaction_hash -> Varchar,
price -> Numeric,
#[max_length = 255]
sender_address -> Varchar,
aggregation_mode -> Numeric,
_cursor -> Int8,
timestamp -> Timestamp,
timestamp -> Timestamptz,
nb_sources_aggregated -> Numeric,
}
}
Expand All @@ -156,14 +156,14 @@ diesel::table! {
network -> Varchar,
request_id -> Numeric,
seed -> Numeric,
created_at -> Timestamp,
created_at -> Timestamptz,
created_at_tx -> Varchar,
#[max_length = 255]
callback_address -> Varchar,
callback_fee_limit -> Numeric,
num_words -> Numeric,
requestor_address -> Varchar,
updated_at -> Timestamp,
updated_at -> Timestamptz,
updated_at_tx -> Varchar,
status -> Numeric,
minimum_block_number -> Numeric,
Expand Down
15 changes: 8 additions & 7 deletions src/types.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
use bigdecimal::BigDecimal;
use chrono::NaiveDateTime;
use chrono::{DateTime, Utc};

use crate::{
config::DataType,
models::{FutureEntry, SpotEntry},
};

#[allow(dead_code)]
pub trait Entry {
fn pair_id(&self) -> &str;
fn source(&self) -> &str;
fn timestamp(&self) -> NaiveDateTime;
fn timestamp(&self) -> DateTime<Utc>;
fn block_number(&self) -> i64;
fn price(&self) -> BigDecimal;
fn expiration_timestamp(&self) -> Option<NaiveDateTime>;
fn expiration_timestamp(&self) -> Option<DateTime<Utc>>;
fn data_type(&self) -> DataType;
}

Expand All @@ -25,7 +26,7 @@ impl Entry for SpotEntry {
&self.source
}

fn timestamp(&self) -> NaiveDateTime {
fn timestamp(&self) -> DateTime<Utc> {
self.timestamp
}

Expand All @@ -37,7 +38,7 @@ impl Entry for SpotEntry {
self.price.clone()
}

fn expiration_timestamp(&self) -> Option<NaiveDateTime> {
fn expiration_timestamp(&self) -> Option<DateTime<Utc>> {
None
}

Expand All @@ -55,7 +56,7 @@ impl Entry for FutureEntry {
&self.source
}

fn timestamp(&self) -> NaiveDateTime {
fn timestamp(&self) -> DateTime<Utc> {
self.timestamp
}

Expand All @@ -67,7 +68,7 @@ impl Entry for FutureEntry {
self.price.clone()
}

fn expiration_timestamp(&self) -> Option<NaiveDateTime> {
fn expiration_timestamp(&self) -> Option<DateTime<Utc>> {
self.expiration_timestamp
}

Expand Down
Loading