Skip to content

Commit

Permalink
fix.
Browse files Browse the repository at this point in the history
  • Loading branch information
ssuchichan committed Mar 11, 2024
1 parent 6cad2f4 commit 858d5ab
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 10 deletions.
6 changes: 3 additions & 3 deletions explorer/src/service/v1/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use poem_openapi::param::Query;
use poem_openapi::{param::Path, payload::Json, ApiResponse, Object};
use serde::{Deserialize, Serialize};
use serde_json::Value;
use sqlx::types::chrono::NaiveDateTime;
use sqlx::types::chrono::DateTime;
use sqlx::{Error, Row};
use std::ops::Add;

Expand Down Expand Up @@ -285,13 +285,13 @@ pub async fn get_blocks(
if let Some(start_time) = start_time.0 {
params.push(format!(
" time >= '{}' ",
NaiveDateTime::from_timestamp_opt(start_time, 0).unwrap()
DateTime::from_timestamp(start_time, 0).unwrap()
));
}
if let Some(end_time) = end_time.0 {
params.push(format!(
" time <= '{}' ",
NaiveDateTime::from_timestamp_opt(end_time, 0).unwrap()
DateTime::from_timestamp(end_time, 0).unwrap()
));
}
let page = page.0.unwrap_or(1);
Expand Down
4 changes: 2 additions & 2 deletions explorer/src/service/v1/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,12 +217,12 @@ pub async fn statistics(api: &Api, ty: Query<Option<i32>>) -> Result<ChainStatis
format!(
"SELECT COUNT(*) as cnt FROM transaction WHERE ty={} AND timestamp>={}",
ty,
start_time.timestamp()
start_time.and_utc().timestamp()
)
} else {
format!(
"SELECT COUNT(*) as cnt FROM transaction WHERE timestamp>={}",
start_time.timestamp()
start_time.and_utc().timestamp()
)
};
let row = sqlx::query(sql_str.as_str()).fetch_one(&mut conn).await?;
Expand Down
7 changes: 4 additions & 3 deletions explorer/src/service/v1/validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use poem_openapi::param::{Path, Query};
use poem_openapi::{payload::Json, ApiResponse, Object};
use serde::{Deserialize, Serialize};
use serde_json::Value;
use sqlx::types::chrono::{Local, NaiveDateTime};
use sqlx::types::chrono::{DateTime, Local};
use sqlx::Row;

#[derive(ApiResponse)]
Expand Down Expand Up @@ -465,15 +465,16 @@ pub async fn validator_signed_count(
.date_naive()
.and_hms_opt(0, 0, 0)
.unwrap()
.and_utc()
.timestamp()
- (page - 1) * page_size * day_secs;

let mut v: Vec<SignedCountItem> = vec![];
for i in 0..page_size {
let start_secs = nt - i * day_secs;
let end_secs = nt - i * day_secs + day_secs;
let start_time = NaiveDateTime::from_timestamp_opt(start_secs, 0).unwrap();
let end_time = NaiveDateTime::from_timestamp_opt(end_secs, 0).unwrap();
let start_time = DateTime::from_timestamp(start_secs, 0).unwrap();
let end_time = DateTime::from_timestamp(end_secs, 0).unwrap();

let sql_block_cnt = format!(
"SELECT count(*) as cnt FROM block WHERE time>='{start_time}' AND time<'{end_time}'"
Expand Down
4 changes: 2 additions & 2 deletions explorer/src/service/v2/other.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,15 @@ pub async fn v2_statistics(api: &Api, ty: Query<Option<i32>>) -> Result<V2ChainS
"select count(distinct address) as cnt from native_addrs".to_string();
sql_daily_txs = format!(
"select count(*) as cnt from transaction where ty=0 and timestamp>={}",
start_time.timestamp()
start_time.and_utc().timestamp()
);
}
_ => {
sql_addrs_count =
"select count(distinct address) as cnt from evm_addrs".to_string();
sql_daily_txs = format!(
"select count(*) as cnt from transaction where ty=1 and timestamp>={}",
start_time.timestamp()
start_time.and_utc().timestamp()
);
}
}
Expand Down

0 comments on commit 858d5ab

Please sign in to comment.