Skip to content

Commit

Permalink
fix log. (#236)
Browse files Browse the repository at this point in the history
* fix log.
  • Loading branch information
ssuchichan authored Mar 11, 2024
1 parent 6d0a29b commit 2e881e7
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 33 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
13 changes: 4 additions & 9 deletions explorer/src/service/v1/price.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use crate::service::api::Api;
use anyhow::Result;
use log::error;
use poem_openapi::param::{Path, Query};
use poem_openapi::types::Type;
use poem_openapi::{payload::Json, ApiResponse, Object};
Expand Down Expand Up @@ -114,8 +113,7 @@ pub async fn simple_price(
ids.0, vs_currencies.0
);
let resp1 = reqwest::get(url).await;
if let Err(e) = resp1 {
error!("Get FRA price: {}", e.to_string());
if resp1.is_err() {
let fra_price = get_fra_price(api).await?;
return Ok(SimplePriceResponse::Ok(Json(SimplePriceResult {
code: 200,
Expand All @@ -125,8 +123,7 @@ pub async fn simple_price(
}

let resp2 = resp1?.json::<SimplePrice>().await;
if let Err(e) = resp2 {
error!("Parse FRA price: {}", e.to_string());
if resp2.is_err() {
let fra_price = get_fra_price(api).await?;
return Ok(SimplePriceResponse::Ok(Json(SimplePriceResult {
code: 200,
Expand Down Expand Up @@ -172,8 +169,7 @@ pub async fn market_chart(
url = format!("https://api.coingecko.com/api/v3/coins/{}/market_chart?vs_currency={}&days={}&interval={}", id.0, vs_currency.0, days.0, itv);
}
let resp1 = reqwest::get(url).await;
if let Err(e) = resp1 {
error!("Get FRA market error: {:?}", e);
if resp1.is_err() {
let fmc = get_fra_market(api).await?;
return Ok(MarketChartResponse::Ok(Json(MarketChartResult {
code: 200,
Expand All @@ -182,8 +178,7 @@ pub async fn market_chart(
})));
}
let resp2 = resp1?.json::<FraMarketChart>().await;
if let Err(e) = resp2 {
error!("Parse FRA market cap error: {:?}", e);
if resp2.is_err() {
let fmc = get_fra_market(api).await?;
return Ok(MarketChartResponse::Ok(Json(MarketChartResult {
code: 200,
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
6 changes: 3 additions & 3 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 Expand Up @@ -110,7 +110,7 @@ pub async fn v2_statistics(api: &Api, ty: Query<Option<i32>>) -> Result<V2ChainS

let sql_daily_txs = format!(
"select count(*) as cnt from transaction where timestamp>={}",
start_time.timestamp()
start_time.and_utc().timestamp()
);
let row_daily = sqlx::query(sql_daily_txs.as_str())
.fetch_one(&mut conn)
Expand Down
2 changes: 1 addition & 1 deletion prismer/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ impl RPCCaller {
amount: amount.to_string(),
decimal: decimal as i64,
height,
timestamp: timestamp.timestamp(),
timestamp: timestamp.and_utc().timestamp(),
value: result.clone(),
});

Expand Down
24 changes: 12 additions & 12 deletions scanner/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ impl RPCCaller {
native_addrs.push(Address {
tx: tx_hash.clone(),
address: to,
timestamp: timestamp.timestamp(),
timestamp: timestamp.and_utc().timestamp(),
});
}
sender = "".to_string();
Expand Down Expand Up @@ -279,7 +279,7 @@ impl RPCCaller {
tx_hash: tx_hash.clone(),
block_hash: block_hash.clone(),
height,
timestamp: timestamp.timestamp(),
timestamp: timestamp.and_utc().timestamp(),
code: tx.tx_result.code,
ty: FindoraTxType::Evm as i32,
ty_sub,
Expand All @@ -300,7 +300,7 @@ impl RPCCaller {
evm_addrs.push(Address {
tx: tx_hash.clone(),
address: a,
timestamp: timestamp.timestamp(),
timestamp: timestamp.and_utc().timestamp(),
});
}
}
Expand Down Expand Up @@ -331,7 +331,7 @@ impl RPCCaller {
evm_addrs.push(Address {
tx: tx_hash.clone(),
address: receiver.clone(),
timestamp: timestamp.timestamp(),
timestamp: timestamp.and_utc().timestamp(),
});
sender = signer.clone();
ty_sub = FindoraTxType::NativeToEVM as i32;
Expand All @@ -343,7 +343,7 @@ impl RPCCaller {
asset,
amount: opt.convert_account.value,
height,
timestamp: timestamp.timestamp(),
timestamp: timestamp.and_utc().timestamp(),
content: op_copy,
});
} else if op_str.contains("UnDelegation") {
Expand Down Expand Up @@ -375,7 +375,7 @@ impl RPCCaller {
target_validator,
new_delegator,
height,
timestamp: timestamp.timestamp(),
timestamp: timestamp.and_utc().timestamp(),
content: op_copy,
});
} else if op_str.contains("Delegation") {
Expand All @@ -395,7 +395,7 @@ impl RPCCaller {
validator: opt.delegation.body.validator,
new_validator,
height,
timestamp: timestamp.timestamp(),
timestamp: timestamp.and_utc().timestamp(),
content: op_copy,
});
} else if op_str.contains("Claim") {
Expand All @@ -411,7 +411,7 @@ impl RPCCaller {
sender: signer,
amount: opt.claim.body.amount.unwrap_or(0),
height,
timestamp: timestamp.timestamp(),
timestamp: timestamp.and_utc().timestamp(),
content: op_copy,
});
} else if op_str.contains("DefineAsset") {
Expand All @@ -432,7 +432,7 @@ impl RPCCaller {
block_hash: block_hash.clone(),
issuer,
height,
timestamp: timestamp.timestamp(),
timestamp: timestamp.and_utc().timestamp(),
issued: 0,
content: op_copy,
});
Expand All @@ -452,7 +452,7 @@ impl RPCCaller {
block_hash: block_hash.clone(),
issuer,
height,
timestamp: timestamp.timestamp(),
timestamp: timestamp.and_utc().timestamp(),
issued: 1,
content: op_copy,
});
Expand Down Expand Up @@ -541,7 +541,7 @@ impl RPCCaller {
tx_hash: tx_hash.clone(),
block_hash: block_hash.clone(),
height,
timestamp: timestamp.timestamp(),
timestamp: timestamp.and_utc().timestamp(),
code: tx.tx_result.code,
ty: FindoraTxType::Native as i32,
ty_sub,
Expand All @@ -562,7 +562,7 @@ impl RPCCaller {
native_addrs.push(Address {
tx: tx_hash.clone(),
address: a,
timestamp: timestamp.timestamp(),
timestamp: timestamp.and_utc().timestamp(),
});
}
}
Expand Down

0 comments on commit 2e881e7

Please sign in to comment.