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

Update dependencies. #244

Merged
merged 1 commit into from
Apr 6, 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
15 changes: 7 additions & 8 deletions explorer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,24 @@ edition = "2021"

[dependencies]
poem = "1.3.36"
poem-openapi = {version = "1.3.30", features = ["swagger-ui"]}
poem-openapi = { version = "1.3.30", features = ["swagger-ui"] }
module = { path = "../module" }
tokio = { version = "1.0", features = ["full"] }
toml = "0.5.8"
toml = "0.8.12"
anyhow = "1.0.52"
sqlx = { version = "0.6.0", features = [ "runtime-tokio-rustls" , "postgres" ,"chrono" ] }
sqlx = { version = "0.7.4", features = [ "runtime-tokio-rustls" , "postgres" ,"chrono" ] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
env_logger = "0.9.0"
env_logger = "0.11.3"
log = "0.4.14"
base64 = "0.10"
bech32 = "0.7.2"
ruc = "1.0"
reqwest = { version = "0.11", features = ["json"] }
reqwest = { version = "0.12.3", features = ["json"] }
rlp = { version = "0.5", default-features = false }
ethereum-types = "0.13.1"
ethereum = { version = "0.12.0", default-features = false, features = ["with-serde"] }
ethereum-types = "0.14.1"
ethereum = { version = "0.15.0", default-features = false, features = ["with-serde"] }
sha3 = { version = "0.10.4", default-features = false }
redis = { version = "0.21.6", features = ["async-std-comp"] }
hex = "0.4.3"

zei = { git = "https://github.com/FindoraNetwork/zei", branch = "stable-main" }
Expand Down
2 changes: 1 addition & 1 deletion explorer/src/service/util.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use anyhow::Error;
use poem::http::StatusCode;
use ruc::{d, Result, RucResult};
use {
bech32::{self, FromBase32, ToBase32},
ruc::*,
zei::{serialization::ZeiFromToBytes, xfr::sig::XfrPublicKey},
};

Expand Down
4 changes: 2 additions & 2 deletions explorer/src/service/v1/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ pub async fn get_address(
or (value @? '$.body.operations[*].TransferAsset.body.transfer.inputs[*].public_key ? (@ == \"{}\")') \
ORDER BY timestamp DESC LIMIT {} OFFSET {}", pk_b64, pk_b64, page_size, (page - 1) * page_size);

let rows = sqlx::query(sql_str.as_str()).fetch_all(&mut conn).await?;
let rows = sqlx::query(sql_str.as_str()).fetch_all(&mut *conn).await?;
let mut txs: Vec<Transaction> = vec![];
for row in rows {
let tx_hash: String = row.try_get("tx_hash")?;
Expand Down Expand Up @@ -108,7 +108,7 @@ pub async fn get_address(
"SELECT count(*) as total FROM transaction WHERE \
(value @? '$.body.operations[*].TransferAsset.body.transfer.outputs[*].public_key ? (@ == \"{pk_b64}\")') \
or (value @? '$.body.operations[*].TransferAsset.body.transfer.inputs[*].public_key ? (@ == \"{pk_b64}\")')");
let res = sqlx::query(sql_total.as_str()).fetch_one(&mut conn).await;
let res = sqlx::query(sql_total.as_str()).fetch_one(&mut *conn).await;
let total: i64 = res.unwrap().try_get("total")?;

Ok(AddressResponse::Ok(Json(AddressResult {
Expand Down
52 changes: 24 additions & 28 deletions explorer/src/service/v1/asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use crate::service::api::Api;
use anyhow::Result;
use module::utils::crypto::bech32enc;
use poem_openapi::{param::Path, param::Query, payload::Json, ApiResponse, Object};
use ruc::{d, RucResult};
use serde::{Deserialize, Serialize};
use serde_json::Value;
use sqlx::Row;
Expand Down Expand Up @@ -97,7 +96,9 @@ pub async fn get_asset(api: &Api, address: Path<String>) -> Result<AssetResponse
};

let sql_query = "SELECT jsonb_path_query(value,'$.body.operations[*].DefineAsset.body.asset') AS asset,tx_hash,block_hash,height FROM transaction ORDER BY height DESC".to_string();
let rows = sqlx::query(sql_query.as_str()).fetch_all(&mut conn).await?;
let rows = sqlx::query(sql_query.as_str())
.fetch_all(&mut *conn)
.await?;

let mut assets: Vec<AssetDisplay> = vec![];
for row in rows {
Expand All @@ -109,10 +110,8 @@ pub async fn get_asset(api: &Api, address: Path<String>) -> Result<AssetResponse
let block: String = row.try_get("block_hash")?;
let tx: String = row.try_get("tx_hash")?;

let pk = base64::decode_config(&a.issuer.key, base64::URL_SAFE)
.c(d!())
.and_then(|bytes| XfrPublicKey::zei_from_bytes(&bytes).c(d!()))
.unwrap();
let pk_vec = base64::decode_config(&a.issuer.key, base64::URL_SAFE)?;
let pk = XfrPublicKey::zei_from_bytes(&pk_vec).unwrap_or_default();
let issuer_addr = bech32enc(&XfrPublicKey::zei_to_bytes(&pk));
let asset_code = base64::encode_config(&a.code.val, base64::URL_SAFE);

Expand Down Expand Up @@ -145,10 +144,8 @@ pub async fn get_asset(api: &Api, address: Path<String>) -> Result<AssetResponse
.json::<AssetRPCResult>()
.await?;

let pk = base64::decode_config(&resp.properties.issuer.key, base64::URL_SAFE)
.c(d!())
.and_then(|bytes| XfrPublicKey::zei_from_bytes(&bytes).c(d!()))
.unwrap();
let pk_vec = base64::decode_config(&resp.properties.issuer.key, base64::URL_SAFE)?;
let pk = XfrPublicKey::zei_from_bytes(&pk_vec).unwrap_or_default();
let issuer_addr = bech32enc(&XfrPublicKey::zei_to_bytes(&pk));
let asset_code = base64::encode_config(&resp.properties.code.val, base64::URL_SAFE);

Expand Down Expand Up @@ -217,11 +214,13 @@ pub async fn get_asset_list(

let sql_total =
"SELECT count(*) as cnt FROM transaction WHERE value @? '$.body.operations[*].DefineAsset'";
let row = sqlx::query(sql_total).fetch_one(&mut conn).await?;
let row = sqlx::query(sql_total).fetch_one(&mut *conn).await?;
let total: i64 = row.try_get("cnt")?;

let sql_query = format!("SELECT jsonb_path_query(value,'$.body.operations[*].DefineAsset.body.asset') AS asset,tx_hash,block_hash,height FROM transaction ORDER BY height DESC LIMIT {} OFFSET {}", page_size, page_size*(page-1));
let rows = sqlx::query(sql_query.as_str()).fetch_all(&mut conn).await?;
let rows = sqlx::query(sql_query.as_str())
.fetch_all(&mut *conn)
.await?;

let mut assets: Vec<AssetDisplay> = vec![];
for row in rows {
Expand All @@ -231,10 +230,8 @@ pub async fn get_asset_list(

let v: Value = row.try_get("asset").unwrap();
let a: Asset = serde_json::from_value(v).unwrap();
let pk = base64::decode_config(&a.issuer.key, base64::URL_SAFE)
.c(d!())
.and_then(|bytes| XfrPublicKey::zei_from_bytes(&bytes).c(d!()))
.unwrap();
let pk_vec = base64::decode_config(&a.issuer.key, base64::URL_SAFE)?;
let pk = XfrPublicKey::zei_from_bytes(&pk_vec).unwrap_or_default();
let issuer_addr = bech32enc(&XfrPublicKey::zei_to_bytes(&pk));
let asset_code = base64::encode_config(&a.code.val, base64::URL_SAFE);

Expand Down Expand Up @@ -333,11 +330,13 @@ pub async fn get_issued_asset_list(

let sql_total =
"SELECT count(*) as cnt FROM transaction WHERE value @? '$.body.operations[*].IssueAsset'";
let row = sqlx::query(sql_total).fetch_one(&mut conn).await?;
let row = sqlx::query(sql_total).fetch_one(&mut *conn).await?;
let total: i64 = row.try_get("cnt")?;

let sql_query = format!("SELECT jsonb_path_query(value,'$.body.operations[*].IssueAsset') AS asset,block_hash,tx_hash,height FROM transaction ORDER BY height DESC LIMIT {} OFFSET {}", page_size, (page-1)*page_size);
let rows = sqlx::query(sql_query.as_str()).fetch_all(&mut conn).await?;
let rows = sqlx::query(sql_query.as_str())
.fetch_all(&mut *conn)
.await?;
let mut assets: Vec<IssueAssetData> = vec![];
for row in rows {
let block: String = row.try_get("block_hash")?;
Expand All @@ -346,10 +345,8 @@ pub async fn get_issued_asset_list(

let v: Value = row.try_get("asset").unwrap();
let a: IssueAsset = serde_json::from_value(v).unwrap();
let pk = base64::decode_config(&a.pubkey.key, base64::URL_SAFE)
.c(d!())
.and_then(|bytes| XfrPublicKey::zei_from_bytes(&bytes).c(d!()))
.unwrap();
let pk_vec = base64::decode_config(&a.pubkey.key, base64::URL_SAFE)?;
let pk = XfrPublicKey::zei_from_bytes(&pk_vec).unwrap_or_default();
let issuer = bech32enc(&XfrPublicKey::zei_to_bytes(&pk));
let asset_code = base64::encode_config(&a.body.code.val, base64::URL_SAFE);

Expand Down Expand Up @@ -415,7 +412,9 @@ pub async fn get_issued_asset(
};

let sql_query = "SELECT jsonb_path_query(value,'$.body.operations[*].IssueAsset') AS asset,block_hash,tx_hash,height FROM transaction ORDER BY height DESC".to_string();
let rows = sqlx::query(sql_query.as_str()).fetch_all(&mut conn).await?;
let rows = sqlx::query(sql_query.as_str())
.fetch_all(&mut *conn)
.await?;
for row in rows {
let v: Value = row.try_get("asset").unwrap();
let a: IssueAsset = serde_json::from_value(v).unwrap();
Expand All @@ -424,11 +423,8 @@ pub async fn get_issued_asset(
let block: String = row.try_get("block_hash")?;
let tx: String = row.try_get("tx_hash")?;
let height: i64 = row.try_get("height")?;

let pk = base64::decode_config(&a.pubkey.key, base64::URL_SAFE)
.c(d!())
.and_then(|bytes| XfrPublicKey::zei_from_bytes(&bytes).c(d!()))
.unwrap();
let pk_vec = base64::decode_config(&a.pubkey.key, base64::URL_SAFE)?;
let pk = XfrPublicKey::zei_from_bytes(&pk_vec).unwrap_or_default();
let issuer = bech32enc(&XfrPublicKey::zei_to_bytes(&pk));
let asset_code = base64::encode_config(&a.body.code.val, base64::URL_SAFE);

Expand Down
46 changes: 6 additions & 40 deletions explorer/src/service/v1/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ pub async fn get_full_block_by_height(api: &Api, height: Path<i64>) -> Result<Fu
let mut conn = api.storage.lock().await.acquire().await?;

let str = format!("SELECT * FROM block WHERE height = {}", height.0);
let row_result = sqlx::query(str.as_str()).fetch_one(&mut conn).await;
let row_result = sqlx::query(str.as_str()).fetch_one(&mut *conn).await;
let row = match row_result {
Ok(row) => row,
Err(e) => {
Expand Down Expand Up @@ -121,7 +121,7 @@ pub async fn get_simple_block_by_height(
let mut conn = api.storage.lock().await.acquire().await?;

let str = format!("SELECT * FROM block WHERE height = {}", height.0);
let row_result = sqlx::query(str.as_str()).fetch_one(&mut conn).await;
let row_result = sqlx::query(str.as_str()).fetch_one(&mut *conn).await;
let row = match row_result {
Ok(row) => row,
Err(e) => {
Expand Down Expand Up @@ -173,24 +173,7 @@ pub async fn get_full_block_by_hash(api: &Api, hash: Path<String>) -> Result<Ful
"SELECT * FROM block WHERE block_hash = '{}'",
hash.0.to_uppercase()
);
let row_result = sqlx::query(str.as_str()).fetch_one(&mut conn).await;
let row = match row_result {
Ok(row) => row,
Err(e) => {
return match e {
Error::RowNotFound => Ok(FullBlockResponse::NotFound(Json(FullBlock {
code: 404,
message: "block not found".to_string(),
data: None,
}))),
_ => Ok(FullBlockResponse::NotFound(Json(FullBlock {
code: 500,
message: "internal error".to_string(),
data: None,
}))),
}
}
};
let row = sqlx::query(str.as_str()).fetch_one(&mut *conn).await?;

let block_data = row.try_get("block_data")?;
let block_rpc: BlockRPC = serde_json::from_value(block_data).unwrap();
Expand Down Expand Up @@ -218,24 +201,7 @@ pub async fn get_simple_block_by_hash(
hash.0.to_uppercase()
);

let row_result = sqlx::query(str.as_str()).fetch_one(&mut conn).await;
let row = match row_result {
Ok(row) => row,
Err(e) => {
return match e {
Error::RowNotFound => Ok(SimpleBlockResponse::NotFound(Json(SimpleBlock {
code: 404,
message: "block not found".to_string(),
data: None,
}))),
_ => Ok(SimpleBlockResponse::InternalError(Json(SimpleBlock {
code: 500,
message: "internal error".to_string(),
data: None,
}))),
}
}
};
let row = sqlx::query(str.as_str()).fetch_one(&mut *conn).await?;

let block_hash: String = row.try_get("block_hash")?;
let app_hash: String = row.try_get("app_hash")?;
Expand Down Expand Up @@ -309,7 +275,7 @@ pub async fn get_blocks(
.as_str(),
);

let rows = sqlx::query(sql_str.as_str()).fetch_all(&mut conn).await?;
let rows = sqlx::query(sql_str.as_str()).fetch_all(&mut *conn).await?;

let mut blocks: Vec<DisplayBlock> = vec![];
for row in rows {
Expand All @@ -335,7 +301,7 @@ pub async fn get_blocks(
// total items
let total: i64;
if blocks.is_empty() {
let res = sqlx::query(sql_total.as_str()).fetch_one(&mut conn).await;
let res = sqlx::query(sql_total.as_str()).fetch_one(&mut *conn).await;
total = res.unwrap().try_get("total")?;
} else {
total = blocks[0].block_header.height.parse()?;
Expand Down
36 changes: 20 additions & 16 deletions explorer/src/service/v1/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,36 +68,36 @@ pub async fn distribute(api: &Api) -> Result<DistributeResponse> {
// xhub
let xhub: i64 =
sqlx::query("SELECT count(*) as cnt FROM transaction WHERE value @? '$.function.XHub'")
.fetch_one(&mut conn)
.fetch_one(&mut *conn)
.await?
.try_get("cnt")?;

// evm
let evm: i64 = sqlx::query("SELECT count(*) as cnt FROM transaction WHERE ty=1")
.fetch_one(&mut conn)
.fetch_one(&mut *conn)
.await?
.try_get("cnt")?;

// not evm
let not_evm: i64 = sqlx::query("SELECT count(*) as cnt FROM transaction WHERE ty=0")
.fetch_one(&mut conn)
.fetch_one(&mut *conn)
.await?
.try_get("cnt")?;

let convert_account: i64 = sqlx::query(convert_account_sql)
.fetch_one(&mut conn)
.fetch_one(&mut *conn)
.await?
.try_get("cnt")?;
let bar: i64 = sqlx::query(bar_sql)
.fetch_one(&mut conn)
.fetch_one(&mut *conn)
.await?
.try_get("cnt")?;
let hide_type_or_amount: i64 = sqlx::query(hide_amount_or_type_sql)
.fetch_one(&mut conn)
.fetch_one(&mut *conn)
.await?
.try_get("cnt")?;
let hide_amount_and_type: i64 = sqlx::query(hide_amount_and_type_sql)
.fetch_one(&mut conn)
.fetch_one(&mut *conn)
.await?
.try_get("cnt")?;
let hide = hide_type_or_amount - hide_amount_and_type;
Expand Down Expand Up @@ -144,7 +144,7 @@ pub async fn address_count(
as addr FROM transaction WHERE timestamp >= {} AND timestamp <= {}", start_time.0, end_time.0);

let rows = sqlx::query(address_count_sql.as_str())
.fetch_all(&mut conn)
.fetch_all(&mut *conn)
.await?;

let mut addrs: Vec<String> = vec![];
Expand Down Expand Up @@ -176,7 +176,7 @@ pub async fn statistics(api: &Api, ty: Query<Option<i32>>) -> Result<ChainStatis
} else {
"SELECT COUNT(*) as cnt FROM transaction".to_string()
};
let row = sqlx::query(sql_str.as_str()).fetch_one(&mut conn).await?;
let row = sqlx::query(sql_str.as_str()).fetch_one(&mut *conn).await?;
let total_txs = row.try_get("cnt")?;

// total address
Expand All @@ -188,22 +188,22 @@ pub async fn statistics(api: &Api, ty: Query<Option<i32>>) -> Result<ChainStatis
match ty.0 {
Some(0) => {
let native_counts_rows = sqlx::query(native_addr_cnt_sql.as_str())
.fetch_all(&mut conn)
.fetch_all(&mut *conn)
.await?;
addr_counts = native_counts_rows.len() as i64;
}
Some(1) => {
let evm_counts_row = sqlx::query(evm_addr_cnt_sql.as_str())
.fetch_one(&mut conn)
.fetch_one(&mut *conn)
.await?;
addr_counts = evm_counts_row.try_get("cnt")?;
}
_ => {
let evm_counts_row = sqlx::query(evm_addr_cnt_sql.as_str())
.fetch_one(&mut conn)
.fetch_one(&mut *conn)
.await?;
let native_counts_rows = sqlx::query(native_addr_cnt_sql.as_str())
.fetch_all(&mut conn)
.fetch_all(&mut *conn)
.await?;
let evm_counts: i64 = evm_counts_row.try_get("cnt")?;
let native_counts = native_counts_rows.len();
Expand All @@ -225,7 +225,7 @@ pub async fn statistics(api: &Api, ty: Query<Option<i32>>) -> Result<ChainStatis
start_time.and_utc().timestamp()
)
};
let row = sqlx::query(sql_str.as_str()).fetch_one(&mut conn).await?;
let row = sqlx::query(sql_str.as_str()).fetch_one(&mut *conn).await?;
let daily_txs = row.try_get("cnt")?;

res_data.active_addresses = addr_counts;
Expand Down Expand Up @@ -261,7 +261,9 @@ pub async fn prism_sync_info(api: &Api) -> Result<PrismSyncResponse> {
let mut conn = api.storage.lock().await.acquire().await?;

let sql_query = "SELECT height FROM e2n_last_height".to_string();
let row = sqlx::query(sql_query.as_str()).fetch_one(&mut conn).await?;
let row = sqlx::query(sql_query.as_str())
.fetch_one(&mut *conn)
.await?;

let prism_info = PrismInfo {
height: row.try_get("height")?,
Expand Down Expand Up @@ -297,7 +299,9 @@ pub async fn delegation_address_num(api: &Api) -> Result<DelegateAddressNumRespo
let mut conn = api.storage.lock().await.acquire().await?;

let sql_query = "select jsonb_path_query(value,'$.body.operations[*].Delegation.pubkey') as pk from transaction".to_string();
let row = sqlx::query(sql_query.as_str()).fetch_all(&mut conn).await?;
let row = sqlx::query(sql_query.as_str())
.fetch_all(&mut *conn)
.await?;

let res = DelegateAddressNumResult {
code: 200,
Expand Down
Loading
Loading