From f15eb3c3351acf9d47c1df6e2274ab37a4b67323 Mon Sep 17 00:00:00 2001 From: dineshpinto Date: Thu, 28 Mar 2024 18:00:16 +0530 Subject: [PATCH] Improve naming scheme for limits --- src/limits.rs | 14 +++++++------- src/validation.rs | 28 ++++++++++++++-------------- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/limits.rs b/src/limits.rs index 21752dd..feabf77 100644 --- a/src/limits.rs +++ b/src/limits.rs @@ -1,11 +1,11 @@ pub const MAX_PAGE: i32 = 10; pub const MAX_ADDRESSES: usize = 30; - -pub const TIMEFRAMES: [&str; 3] = ["day", "hour", "minute"]; -pub const DAY_AGGREGATES: [i32; 1] = [1]; -pub const HOUR_AGGREGATES: [i32; 3] = [1, 4, 12]; -pub const MINUTE_AGGREGATES: [i32; 3] = [1, 5, 15]; pub const OHLCV_LIMIT: i32 = 1000; -pub const CURRENCIES: [&str; 2] = ["usd", "token"]; -pub const TOKENS: [&str; 2] = ["base", "quote"]; +pub const VALID_TIMEFRAMES: [&str; 3] = ["day", "hour", "minute"]; +pub const VALID_DAY_AGGREGATES: [i32; 1] = [1]; +pub const VALID_HOUR_AGGREGATES: [i32; 3] = [1, 4, 12]; +pub const VALID_MINUTE_AGGREGATES: [i32; 3] = [1, 5, 15]; + +pub const VALID_CURRENCIES: [&str; 2] = ["usd", "token"]; +pub const VALID_TOKENS: [&str; 2] = ["base", "quote"]; diff --git a/src/validation.rs b/src/validation.rs index 18edf54..1414f87 100644 --- a/src/validation.rs +++ b/src/validation.rs @@ -1,6 +1,6 @@ use crate::limits::{ - CURRENCIES, DAY_AGGREGATES, HOUR_AGGREGATES, MAX_ADDRESSES, MAX_PAGE, MINUTE_AGGREGATES, - OHLCV_LIMIT, TIMEFRAMES, TOKENS, + MAX_ADDRESSES, MAX_PAGE, OHLCV_LIMIT, VALID_CURRENCIES, VALID_DAY_AGGREGATES, + VALID_HOUR_AGGREGATES, VALID_MINUTE_AGGREGATES, VALID_TIMEFRAMES, VALID_TOKENS, }; pub fn check_page(page: &i32) { @@ -16,26 +16,26 @@ pub fn check_addresses(addresses: &[&str]) { } pub fn check_timeframe(timeframe: &str) { - if !TIMEFRAMES.contains(&timeframe) { - log::warn!("timeframe not in {:?}", TIMEFRAMES); + if !VALID_TIMEFRAMES.contains(&timeframe) { + log::warn!("timeframe not in {:?}", VALID_TIMEFRAMES); } } pub fn check_aggregate(aggregate: &i32, timeframe: &str) { match timeframe { "day" => { - if !DAY_AGGREGATES.contains(aggregate) { - log::warn!("aggregate not in {:?}", DAY_AGGREGATES); + if !VALID_DAY_AGGREGATES.contains(aggregate) { + log::warn!("aggregate not in {:?}", VALID_DAY_AGGREGATES); } } "hour" => { - if !HOUR_AGGREGATES.contains(aggregate) { - log::warn!("aggregate not in {:?}", HOUR_AGGREGATES); + if !VALID_HOUR_AGGREGATES.contains(aggregate) { + log::warn!("aggregate not in {:?}", VALID_HOUR_AGGREGATES); } } "minute" => { - if !MINUTE_AGGREGATES.contains(aggregate) { - log::warn!("aggregate not in {:?}", MINUTE_AGGREGATES); + if !VALID_MINUTE_AGGREGATES.contains(aggregate) { + log::warn!("aggregate not in {:?}", VALID_MINUTE_AGGREGATES); } } _ => log::error!("invalid timeframe {}", timeframe), @@ -49,14 +49,14 @@ pub fn check_ohlcv_limit(limit: &i32) { } pub fn check_currency(currency: &str) { - if !CURRENCIES.contains(¤cy) { - log::warn!("currency not in {:?}", CURRENCIES); + if !VALID_CURRENCIES.contains(¤cy) { + log::warn!("currency not in {:?}", VALID_CURRENCIES); } } pub fn check_token(token: &str) { - if !TOKENS.contains(&token) { - log::warn!("token not in {:?}", TOKENS); + if !VALID_TOKENS.contains(&token) { + log::warn!("token not in {:?}", VALID_TOKENS); } }