Skip to content

Commit c070177

Browse files
authored
fix: invalid timestamp (#58)
* fix: now in seconds * fix: switch to seconds * fix: remove comment
1 parent 67a5c66 commit c070177

File tree

4 files changed

+5
-6
lines changed

4 files changed

+5
-6
lines changed

pragma-entities/src/dto/entry.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ impl From<crate::Entry> for Entry {
2727
pair_id: entry.pair_id,
2828
publisher: entry.publisher,
2929
source: entry.source,
30-
timestamp: entry.timestamp.and_utc().timestamp_millis() as u64,
30+
timestamp: entry.timestamp.and_utc().timestamp() as u64,
3131
price: entry.price.to_u128().unwrap_or(0), // change default value ?
3232
}
3333
}

pragma-node/src/handlers/entries/get_entry.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ pub async fn get_entry(
3434
// Construct pair id
3535
let pair_id = currency_pair_to_pair_id(&pair.0, &pair.1);
3636

37-
let now = chrono::Utc::now().timestamp_millis() as u64;
37+
let now = chrono::Utc::now().timestamp() as u64;
3838

3939
let timestamp = if let Some(timestamp) = params.timestamp {
4040
timestamp
@@ -56,7 +56,6 @@ pub async fn get_entry(
5656

5757
let is_routing = params.routing.unwrap_or(false);
5858

59-
// Validate given timestamp
6059
if timestamp > now {
6160
return Err(EntryError::InvalidTimestamp);
6261
}
@@ -84,7 +83,7 @@ fn adapt_entry_to_entry_response(
8483
) -> GetEntryResponse {
8584
GetEntryResponse {
8685
pair_id,
87-
timestamp: entry.time.and_utc().timestamp_millis() as u64,
86+
timestamp: entry.time.and_utc().timestamp() as u64,
8887
num_sources_aggregated: entry.num_sources as usize,
8988
price: format!(
9089
"0x{}",

pragma-node/src/handlers/entries/get_ohlc.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ pub async fn get_ohlc(
3131
// Construct pair id
3232
let pair_id = currency_pair_to_pair_id(&pair.0, &pair.1);
3333

34-
let now = chrono::Utc::now().timestamp_millis() as u64;
34+
let now = chrono::Utc::now().timestamp() as u64;
3535

3636
let timestamp = if let Some(timestamp) = params.timestamp {
3737
timestamp

pragma-node/src/handlers/entries/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ pub struct GetEntryParams {
143143
impl Default for GetEntryParams {
144144
fn default() -> Self {
145145
Self {
146-
timestamp: Some(chrono::Utc::now().timestamp_millis() as u64),
146+
timestamp: Some(chrono::Utc::now().timestamp() as u64),
147147
interval: Some(Interval::default()),
148148
routing: Some(false),
149149
aggregation: Some(AggregationMode::default()),

0 commit comments

Comments
 (0)