diff --git a/explorer/Cargo.toml b/explorer/Cargo.toml index c7cab46..0e3508a 100644 --- a/explorer/Cargo.toml +++ b/explorer/Cargo.toml @@ -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" } diff --git a/explorer/src/service/util.rs b/explorer/src/service/util.rs index ccb6b2b..8391c05 100644 --- a/explorer/src/service/util.rs +++ b/explorer/src/service/util.rs @@ -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}, }; diff --git a/explorer/src/service/v1/address.rs b/explorer/src/service/v1/address.rs index 6a89eb2..a5766f7 100644 --- a/explorer/src/service/v1/address.rs +++ b/explorer/src/service/v1/address.rs @@ -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 = vec![]; for row in rows { let tx_hash: String = row.try_get("tx_hash")?; @@ -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 { diff --git a/explorer/src/service/v1/asset.rs b/explorer/src/service/v1/asset.rs index 5031cf0..26cd8e0 100644 --- a/explorer/src/service/v1/asset.rs +++ b/explorer/src/service/v1/asset.rs @@ -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; @@ -97,7 +96,9 @@ pub async fn get_asset(api: &Api, address: Path) -> Result = vec![]; for row in rows { @@ -109,10 +110,8 @@ pub async fn get_asset(api: &Api, address: Path) -> Result) -> Result() .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); @@ -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 = vec![]; for row in rows { @@ -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); @@ -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 = vec![]; for row in rows { let block: String = row.try_get("block_hash")?; @@ -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); @@ -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(); @@ -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); diff --git a/explorer/src/service/v1/block.rs b/explorer/src/service/v1/block.rs index 21dd112..f0b6c58 100644 --- a/explorer/src/service/v1/block.rs +++ b/explorer/src/service/v1/block.rs @@ -80,7 +80,7 @@ pub async fn get_full_block_by_height(api: &Api, height: Path) -> Result row, Err(e) => { @@ -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) => { @@ -173,24 +173,7 @@ pub async fn get_full_block_by_hash(api: &Api, hash: Path) -> Result 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(); @@ -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")?; @@ -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 = vec![]; for row in rows { @@ -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()?; diff --git a/explorer/src/service/v1/chain.rs b/explorer/src/service/v1/chain.rs index cce1434..6e947b1 100644 --- a/explorer/src/service/v1/chain.rs +++ b/explorer/src/service/v1/chain.rs @@ -68,36 +68,36 @@ pub async fn distribute(api: &Api) -> Result { // 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; @@ -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 = vec![]; @@ -176,7 +176,7 @@ pub async fn statistics(api: &Api, ty: Query>) -> Result>) -> Result { 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(); @@ -225,7 +225,7 @@ pub async fn statistics(api: &Api, ty: Query>) -> Result Result { 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")?, @@ -297,7 +299,9 @@ pub async fn delegation_address_num(api: &Api) -> Result Result { let mut conn = api.storage.lock().await.acquire().await?; let row = sqlx::query("SELECT price FROM prices") - .fetch_one(&mut conn) + .fetch_one(&mut *conn) .await?; let p: String = row.try_get("price")?; let fra_price = FraPrice { usd: p.parse()? }; @@ -70,7 +70,7 @@ pub async fn upsert_fra_price(api: &Api, price: &str) -> Result<()> { sqlx::query("INSERT INTO prices VALUES($1,$2) ON CONFLICT(name) DO UPDATE SET price=$2") .bind("fra") .bind(price) - .execute(&mut conn) + .execute(&mut *conn) .await?; Ok(()) @@ -79,7 +79,7 @@ pub async fn upsert_fra_price(api: &Api, price: &str) -> Result<()> { pub async fn get_fra_market(api: &Api) -> Result { let mut conn = api.storage.lock().await.acquire().await?; let row = sqlx::query("SELECT val FROM market") - .fetch_one(&mut conn) + .fetch_one(&mut *conn) .await?; let val: Value = row.try_get("val")?; let fmc: FraMarketChart = serde_json::from_value(val).unwrap(); @@ -92,7 +92,7 @@ pub async fn upsert_fra_market(api: &Api, val: Value) -> Result<()> { sqlx::query("INSERT INTO market VALUES($1,$2) ON CONFLICT(name) DO UPDATE SET val=$2") .bind("fra") .bind(val) - .execute(&mut conn) + .execute(&mut *conn) .await?; Ok(()) diff --git a/explorer/src/service/v1/staking.rs b/explorer/src/service/v1/staking.rs index e428dc3..6d91abf 100644 --- a/explorer/src/service/v1/staking.rs +++ b/explorer/src/service/v1/staking.rs @@ -72,9 +72,13 @@ pub async fn get_tx_delegation( let sql_query = format!("SELECT tx_hash,timestamp,jsonb_path_query(value,'$.body.operations[*].Delegation') AS d FROM transaction WHERE value @? '$.body.operations[*].Delegation.pubkey ? (@==\"{}\")' ORDER BY timestamp DESC LIMIT {} OFFSET {}", base64_address, page_size, (page-1)*page_size); let mut items: Vec = vec![]; - let row_cnt = sqlx::query(sql_count.as_str()).fetch_one(&mut conn).await?; + let row_cnt = sqlx::query(sql_count.as_str()) + .fetch_one(&mut *conn) + .await?; let total: i64 = row_cnt.try_get("cnt")?; - 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 timestamp: i64 = row.try_get("timestamp")?; let tx_hash: String = row.try_get("tx_hash")?; @@ -181,9 +185,13 @@ pub async fn get_tx_undelegation( let sql_query = format!("SELECT tx_hash,timestamp,jsonb_path_query(value,'$.body.operations[*].UnDelegation') AS ud FROM transaction WHERE value @? '$.body.operations[*].UnDelegation.pubkey ? (@==\"{}\")' ORDER BY timestamp DESC LIMIT {} OFFSET {}", base64_address, page_size, (page-1)*page_size); let mut items: Vec = vec![]; - let row_cnt = sqlx::query(sql_count.as_str()).fetch_one(&mut conn).await?; + let row_cnt = sqlx::query(sql_count.as_str()) + .fetch_one(&mut *conn) + .await?; let total: i64 = row_cnt.try_get("cnt")?; - 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 timestamp: i64 = row.try_get("timestamp")?; let tx_hash: String = row.try_get("tx_hash")?; @@ -296,9 +304,13 @@ pub async fn get_claim( let sql_query =format!("SELECT tx_hash,timestamp,jsonb_path_query(value,'$.body.operations[*].Claim') AS claim FROM transaction WHERE value @? '$.body.operations[*].Claim.pubkey ? (@==\"{}\")' ORDER BY timestamp DESC LIMIT {} OFFSET {}", base64_address, page_size, (page-1)*page_size); let mut items: Vec = vec![]; - let row_cnt = sqlx::query(sql_count.as_str()).fetch_one(&mut conn).await?; + let row_cnt = sqlx::query(sql_count.as_str()) + .fetch_one(&mut *conn) + .await?; let total: i64 = row_cnt.try_get("cnt")?; - 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 timestamp: i64 = row.try_get("timestamp")?; let tx_hash: String = row.try_get("tx_hash")?; @@ -441,10 +453,14 @@ pub async fn get_undelegation_info( query_sql = query_sql.add(format!(" LIMIT {} OFFSET {}", page_size, (page - 1) * page_size).as_str()); - let rows_count = sqlx::query(count_sql.as_str()).fetch_one(&mut conn).await?; + let rows_count = sqlx::query(count_sql.as_str()) + .fetch_one(&mut *conn) + .await?; let total: i64 = rows_count.try_get("cnt")?; - let rows = sqlx::query(query_sql.as_str()).fetch_all(&mut conn).await?; + let rows = sqlx::query(query_sql.as_str()) + .fetch_all(&mut *conn) + .await?; let mut undelegations: Vec = vec![]; for r in rows { let tx_hash: String = r.try_get("tx_hash")?; @@ -556,10 +572,14 @@ pub async fn get_delegation_info( query_sql = query_sql.add(format!(" LIMIT {} OFFSET {}", page_size, (page - 1) * page_size).as_str()); - let rows_count = sqlx::query(count_sql.as_str()).fetch_one(&mut conn).await?; + let rows_count = sqlx::query(count_sql.as_str()) + .fetch_one(&mut *conn) + .await?; let total: i64 = rows_count.try_get("cnt")?; - let rows = sqlx::query(query_sql.as_str()).fetch_all(&mut conn).await?; + let rows = sqlx::query(query_sql.as_str()) + .fetch_all(&mut *conn) + .await?; let mut delegations: Vec = vec![]; for r in rows { let tx_hash: String = r.try_get("tx_hash")?; @@ -636,7 +656,9 @@ pub async fn get_delegation_amount( query_sql = query_sql.add(" WHERE ").add(params.join(" AND ").as_str()); } - let rows = sqlx::query(query_sql.as_str()).fetch_all(&mut conn).await?; + let rows = sqlx::query(query_sql.as_str()) + .fetch_all(&mut *conn) + .await?; let mut amount: u64 = 0; for r in rows { let val: Value = r.try_get("d")?; @@ -697,7 +719,9 @@ pub async fn get_undelegation_amount( query_sql = query_sql.add(" WHERE ").add(params.join(" AND ").as_str()); } - let rows = sqlx::query(query_sql.as_str()).fetch_all(&mut conn).await?; + let rows = sqlx::query(query_sql.as_str()) + .fetch_all(&mut *conn) + .await?; let mut amount: u64 = 0; for r in rows { let val: Value = r.try_get("ud")?; diff --git a/explorer/src/service/v1/transaction.rs b/explorer/src/service/v1/transaction.rs index b3b29d9..ca0a559 100644 --- a/explorer/src/service/v1/transaction.rs +++ b/explorer/src/service/v1/transaction.rs @@ -12,7 +12,7 @@ use poem_openapi::{param::Path, payload::Json, ApiResponse, Object}; use serde::{Deserialize, Serialize}; use serde_json::Value; use sha3::{Digest, Keccak256}; -use sqlx::{Error, Row}; +use sqlx::Row; use std::ops::Add; pub const FRA_ASSET: &str = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA="; @@ -210,12 +210,14 @@ pub async fn get_prism_received( address.0 ); let row_counts = sqlx::query(sql_counts.as_str()) - .fetch_one(&mut conn) + .fetch_one(&mut *conn) .await?; let total: i64 = row_counts.try_get("cnt")?; let sql_query = format!("SELECT tx_hash,block_hash,sender,receiver,asset,amount,decimal,height,timestamp,value FROM e2n WHERE receiver='{}' ORDER BY timestamp DESC LIMIT {} OFFSET {}", address.0, 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?; for row in rows { let tx_hash: String = row.try_get("tx_hash")?; let block_hash: String = row.try_get("block_hash")?; @@ -317,13 +319,15 @@ pub async fn get_prism_records_send( let sql_counts = format!( "SELECT count(*) AS cnt FROM transaction WHERE value @? '$.body.operations[*].ConvertAccount.signer ? (@==\"{}\")'", base64_addr); let row_counts = sqlx::query(sql_counts.as_str()) - .fetch_one(&mut conn) + .fetch_one(&mut *conn) .await?; let total: i64 = row_counts.try_get("cnt")?; let sql_query = format!("SELECT tx_hash,block_hash,height,timestamp,jsonb_path_query(value,'$.body.operations[*].ConvertAccount') AS ca FROM transaction WHERE value @? '$.body.operations[*].ConvertAccount.signer ? (@==\"{}\")' ORDER BY timestamp DESC LIMIT {} OFFSET {}", base64_addr, 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?; for row in rows { let tx_hash: String = row.try_get("tx_hash")?; let block_hash: String = row.try_get("block_hash")?; @@ -374,7 +378,7 @@ pub async fn get_evm_tx(api: &Api, tx_hash: Path) -> Result let mut conn = api.storage.lock().await.acquire().await?; let sql_query = "SELECT * FROM transaction WHERE value @? '$.function.Ethereum'"; - let rows = sqlx::query(sql_query).fetch_all(&mut conn).await?; + let rows = sqlx::query(sql_query).fetch_all(&mut *conn).await?; for row in rows { let value: Value = row.try_get("value")?; let evm_tx: EvmTx = serde_json::from_value(value.clone()).unwrap(); @@ -428,24 +432,7 @@ pub async fn get_tx(api: &Api, tx_hash: Path) -> Result { tx_hash.0.to_lowercase() ); - let row_result = sqlx::query(str.as_str()).fetch_one(&mut conn).await; - let row = match row_result { - Err(e) => { - return match e { - Error::RowNotFound => Ok(TxResponse::NotFound(Json(TxRes { - code: 404, - message: "tx not found".to_string(), - data: None, - }))), - _ => Ok(TxResponse::InternalError(Json(TxRes { - code: 500, - message: "internal error".to_string(), - data: None, - }))), - } - } - Ok(row) => row, - }; + let row = sqlx::query(str.as_str()).fetch_one(&mut *conn).await?; let tx_hash: String = row.try_get("tx_hash")?; let block_hash: String = row.try_get("block_hash")?; @@ -503,11 +490,15 @@ pub async fn get_txs_receive_from( let pk = public_key_to_base64(&pk_res.unwrap()); let sql_total = format!("SELECT count(*) AS cnt FROM transaction WHERE value @? '$.body.operations[*].TransferAsset.body.transfer.inputs[*].public_key ? (@==\"{pk}\")'"); - let row = sqlx::query(sql_total.as_str()).fetch_one(&mut conn).await?; + let row = sqlx::query(sql_total.as_str()) + .fetch_one(&mut *conn) + .await?; let total = row.try_get("cnt")?; let sql_query = format!("SELECT * FROM transaction WHERE value @? '$.body.operations[*].TransferAsset.body.transfer.inputs[*].public_key ? (@==\"{}\")' ORDER BY timestamp DESC LIMIT {} OFFSET {}", pk, 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 txs: Vec = vec![]; for row in rows { let tx_hash: String = row.try_get("tx_hash")?; @@ -571,11 +562,15 @@ pub async fn get_txs_send_to( let pk = public_key_to_base64(&pk_res.unwrap()); let sql_total = format!("SELECT count(*) AS cnt FROM transaction WHERE value @? '$.body.operations[*].TransferAsset.body.transfer.outputs[*].public_key ? (@==\"{pk}\")'"); - let row = sqlx::query(sql_total.as_str()).fetch_one(&mut conn).await?; + let row = sqlx::query(sql_total.as_str()) + .fetch_one(&mut *conn) + .await?; let total = row.try_get("cnt")?; let sql_query = format!("SELECT * FROM transaction WHERE value @? '$.body.operations[*].TransferAsset.body.transfer.outputs[*].public_key ? (@==\"{}\")' ORDER BY timestamp DESC LIMIT {} OFFSET {}", pk, 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 txs: Vec = vec![]; for row in rows { @@ -698,7 +693,7 @@ pub async fn get_txs( .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 txs: Vec = vec![]; for row in rows { @@ -731,7 +726,9 @@ pub async fn get_txs( } // total items - let row = sqlx::query(sql_total.as_str()).fetch_one(&mut conn).await?; + let row = sqlx::query(sql_total.as_str()) + .fetch_one(&mut *conn) + .await?; let total: i64 = row.try_get("total")?; Ok(TxsResponse::Ok(Json(TxsRes { @@ -841,7 +838,7 @@ pub async fn get_txs_raw( .as_str(), ); - let res = sqlx::query(sql_str.as_str()).fetch_all(&mut conn).await; + let res = sqlx::query(sql_str.as_str()).fetch_all(&mut *conn).await; let mut txs: Vec = vec![]; let rows = match res { Ok(rows) => rows, @@ -883,7 +880,9 @@ pub async fn get_txs_raw( } // total items - let row = sqlx::query(sql_total.as_str()).fetch_one(&mut conn).await?; + let row = sqlx::query(sql_total.as_str()) + .fetch_one(&mut *conn) + .await?; let total: i64 = row.try_get("total")?; Ok(TxsResponse::Ok(Json(TxsRes { @@ -961,7 +960,7 @@ pub async fn get_triple_masking_txs( ) .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 txs: Vec = vec![]; for row in rows { @@ -994,7 +993,9 @@ pub async fn get_triple_masking_txs( } // total items - let row = sqlx::query(sql_total.as_str()).fetch_one(&mut conn).await?; + let row = sqlx::query(sql_total.as_str()) + .fetch_one(&mut *conn) + .await?; let total: i64 = row.try_get("total")?; Ok(TxsResponse::Ok(Json(TxsRes { @@ -1054,7 +1055,7 @@ pub async fn get_claim_txs( ) .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 txs: Vec = vec![]; for row in rows { @@ -1087,7 +1088,7 @@ pub async fn get_claim_txs( } // total items - let res = sqlx::query(sql_total.as_str()).fetch_all(&mut conn).await; + let res = sqlx::query(sql_total.as_str()).fetch_all(&mut *conn).await; let total: i64 = res.unwrap()[0].try_get("total")?; Ok(TxsResponse::Ok(Json(TxsRes { @@ -1136,7 +1137,9 @@ pub async fn get_claims_amount(api: &Api, address: Path) -> Result = vec![]; for row in rows { @@ -1216,7 +1219,9 @@ pub async fn get_prism_tx( } // total items - let row = sqlx::query(sql_total.as_str()).fetch_one(&mut conn).await?; + let row = sqlx::query(sql_total.as_str()) + .fetch_one(&mut *conn) + .await?; let total: i64 = row.try_get("total")?; Ok(PmtxsResponse::Ok(Json(PmtxsRes { diff --git a/explorer/src/service/v1/validator.rs b/explorer/src/service/v1/validator.rs index 1b3208d..aa12ab9 100644 --- a/explorer/src/service/v1/validator.rs +++ b/explorer/src/service/v1/validator.rs @@ -202,7 +202,7 @@ pub async fn validator_list(api: &Api) -> Result { let mut wrap_validator_data = validator_data.wrap(); - let rows = sqlx::query(sql.as_str()).fetch_all(&mut conn).await?; + let rows = sqlx::query(sql.as_str()).fetch_all(&mut *conn).await?; let mut signers: Vec = vec![]; for r in rows { let addr: String = r.try_get("address")?; @@ -350,7 +350,7 @@ pub async fn validator_history( let mut tmp_items: Vec = vec![]; let delegation_rows = sqlx::query(sql_delegation.as_str()) - .fetch_all(&mut conn) + .fetch_all(&mut *conn) .await?; for row in delegation_rows { let timestamp: i64 = row.try_get("timestamp")?; @@ -368,7 +368,7 @@ pub async fn validator_history( }) } - let undelegation_rows = sqlx::query(sql_undelegation).fetch_all(&mut conn).await?; + let undelegation_rows = sqlx::query(sql_undelegation).fetch_all(&mut *conn).await?; for row in undelegation_rows { let timestamp: i64 = row.try_get("timestamp")?; let tx_hash: String = row.try_get("tx_hash")?; @@ -486,13 +486,13 @@ pub async fn validator_signed_count( "SELECT count(*) as cnt FROM block WHERE time>='{start_time}' AND time<'{end_time}'" ); let row_blk_cnt = sqlx::query(sql_block_cnt.as_str()) - .fetch_one(&mut conn) + .fetch_one(&mut *conn) .await?; let blk_cnt: i64 = row_blk_cnt.try_get("cnt")?; let sql_signed_cnt = format!("SELECT count(*) as cnt FROM block_generation WHERE address='{}' AND time>='{}' AND time<'{}' AND signature is not null", address.0.to_uppercase(), start_time, end_time); let row_signed_cnt = sqlx::query(sql_signed_cnt.as_str()) - .fetch_one(&mut conn) + .fetch_one(&mut *conn) .await?; let signed_cnt: i64 = row_signed_cnt.try_get("cnt")?; diff --git a/explorer/src/service/v2/asset.rs b/explorer/src/service/v2/asset.rs index 6e59b45..5998bde 100644 --- a/explorer/src/service/v2/asset.rs +++ b/explorer/src/service/v2/asset.rs @@ -58,7 +58,9 @@ pub async fn v2_get_asset( "SELECT count(*) as cnt from assets WHERE asset='{}'", address.0 ); - let row_count = sqlx::query(sql_total.as_str()).fetch_one(&mut conn).await?; + let row_count = sqlx::query(sql_total.as_str()) + .fetch_one(&mut *conn) + .await?; let total: i64 = row_count.try_get("cnt")?; let sql_query = format!( "SELECT asset,tx,block,issuer,height,timestamp,ty,content from assets WHERE asset='{}' order by height desc limit {} offset {}", @@ -67,7 +69,9 @@ pub async fn v2_get_asset( (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?; for row in rows { let asset: String = row.try_get("asset")?; let tx: String = row.try_get("tx")?; @@ -112,7 +116,9 @@ pub async fn v2_get_asset_list( let page_size = page_size.0.unwrap_or(10); let sql_total = "SELECT count(*) AS cnt FROM assets".to_string(); - let row_count = sqlx::query(sql_total.as_str()).fetch_one(&mut conn).await?; + let row_count = sqlx::query(sql_total.as_str()) + .fetch_one(&mut *conn) + .await?; let total: i64 = row_count.try_get("cnt")?; let sql_query = format!( @@ -120,7 +126,9 @@ pub async fn v2_get_asset_list( 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?; for row in rows { let asset: String = row.try_get("asset")?; let tx: String = row.try_get("tx")?; diff --git a/explorer/src/service/v2/claim.rs b/explorer/src/service/v2/claim.rs index cbe695b..53e777b 100644 --- a/explorer/src/service/v2/claim.rs +++ b/explorer/src/service/v2/claim.rs @@ -42,7 +42,9 @@ pub async fn v2_get_claim(api: &Api, tx_hash: Path) -> Result = vec![]; - 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 tx: String = row.try_get("tx")?; let block: String = row.try_get("block")?; diff --git a/explorer/src/service/v2/delegation.rs b/explorer/src/service/v2/delegation.rs index 3d72efd..dfee787 100644 --- a/explorer/src/service/v2/delegation.rs +++ b/explorer/src/service/v2/delegation.rs @@ -44,7 +44,9 @@ pub async fn v2_get_delegation(api: &Api, tx_hash: Path) -> Result = vec![]; - 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 tx: String = row.try_get("tx")?; let block: String = row.try_get("block")?; diff --git a/explorer/src/service/v2/evm_to_native.rs b/explorer/src/service/v2/evm_to_native.rs index b7e66b9..9011d4c 100644 --- a/explorer/src/service/v2/evm_to_native.rs +++ b/explorer/src/service/v2/evm_to_native.rs @@ -55,12 +55,14 @@ pub async fn v2_get_e2n_txs( let page_size = page_size.0.unwrap_or(10); let sql_total = "SELECT count(*) FROM e2n"; - 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("count")?; let sql_query = format!("SELECT tx_hash,block_hash,sender,receiver,asset,amount,decimal,height,timestamp,value FROM e2n ORDER BY timestamp DESC LIMIT {} OFFSET {}", page_size, (page-1)*page_size); let mut res: Vec = vec![]; - 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 tx_hash: String = row.try_get("tx_hash")?; let block_hash: String = row.try_get("block_hash")?; diff --git a/explorer/src/service/v2/native_to_evm.rs b/explorer/src/service/v2/native_to_evm.rs index fe5dd8b..a1be8cd 100644 --- a/explorer/src/service/v2/native_to_evm.rs +++ b/explorer/src/service/v2/native_to_evm.rs @@ -45,12 +45,14 @@ pub async fn v2_get_n2e_txs( let page_size = page_size.0.unwrap_or(10); let sql_total = "SELECT count(*) FROM n2e"; - 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("count")?; let sql_query = format!("SELECT tx,block,sender,receiver,asset,amount,height,timestamp,content FROM n2e ORDER BY timestamp DESC LIMIT {} OFFSET {}", page_size, (page-1)*page_size); let mut res: Vec = vec![]; - 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 tx: String = row.try_get("tx")?; let block: String = row.try_get("block")?; @@ -120,7 +122,9 @@ pub async fn v2_get_n2e_tx(api: &Api, tx_hash: Path) -> Result>) -> Result>) -> Result>) -> Result>) -> Result Result { let mut conn = api.storage.lock().await.acquire().await?; let sql_native = "select count(*) as cnt from transaction where ty=0"; - let row_native = sqlx::query(sql_native).fetch_one(&mut conn).await?; + let row_native = sqlx::query(sql_native).fetch_one(&mut *conn).await?; let native_count: i64 = row_native.try_get("cnt")?; let sql_privacy = "select count(*) as cnt from transaction where ty_sub=2 or ty_sub=3 or ty_sub=4"; - let row_privacy = sqlx::query(sql_privacy).fetch_one(&mut conn).await?; + let row_privacy = sqlx::query(sql_privacy).fetch_one(&mut *conn).await?; let privacy: i64 = row_privacy.try_get("cnt")?; let sql_evm = "SELECT count(*) as cnt FROM transaction where ty=1"; - let row_evm = sqlx::query(sql_evm).fetch_one(&mut conn).await?; + let row_evm = sqlx::query(sql_evm).fetch_one(&mut *conn).await?; let evm_count: i64 = row_evm.try_get("cnt")?; let sql_prism_n2e = "select count(*) as cnt from n2e"; - let row_n2e = sqlx::query(sql_prism_n2e).fetch_one(&mut conn).await?; + let row_n2e = sqlx::query(sql_prism_n2e).fetch_one(&mut *conn).await?; let n2e_count: i64 = row_n2e.try_get("cnt")?; let sql_prism_e2n = "select count(*) as cnt from e2n"; - let row_e2n = sqlx::query(sql_prism_e2n).fetch_one(&mut conn).await?; + let row_e2n = sqlx::query(sql_prism_e2n).fetch_one(&mut *conn).await?; let e2n_count: i64 = row_e2n.try_get("cnt")?; Ok(V2DistributeResponse::Ok(Json(V2DistributeResult { @@ -213,11 +213,11 @@ pub async fn v2_address_count( } let row_native = sqlx::query(sql_native.as_str()) - .fetch_one(&mut conn) + .fetch_one(&mut *conn) .await?; let native_count: i64 = row_native.try_get("cnt")?; - let row_evm = sqlx::query(sql_evm.as_str()).fetch_one(&mut conn).await?; + let row_evm = sqlx::query(sql_evm.as_str()).fetch_one(&mut *conn).await?; let evm_count: i64 = row_evm.try_get("cnt")?; Ok(AddressCountResponse::Ok(Json(AddressCountResult { diff --git a/explorer/src/service/v2/transaction.rs b/explorer/src/service/v2/transaction.rs index 5ae913f..53cbb43 100644 --- a/explorer/src/service/v2/transaction.rs +++ b/explorer/src/service/v2/transaction.rs @@ -67,7 +67,7 @@ pub async fn v2_get_txs( .as_str(), ); debug!("{}", sql_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 txs: Vec = vec![]; for row in rows { @@ -100,7 +100,9 @@ pub async fn v2_get_txs( } // total items - let row_cnt = sqlx::query(sql_total.as_str()).fetch_one(&mut conn).await?; + let row_cnt = sqlx::query(sql_total.as_str()) + .fetch_one(&mut *conn) + .await?; let total: i64 = row_cnt.try_get("cnt")?; Ok(TxsResponse::Ok(Json(TxsRes { diff --git a/explorer/src/service/v2/undelegation.rs b/explorer/src/service/v2/undelegation.rs index 1b00774..5a52164 100644 --- a/explorer/src/service/v2/undelegation.rs +++ b/explorer/src/service/v2/undelegation.rs @@ -47,7 +47,9 @@ pub async fn v2_get_undelegation( tx_hash.0.to_lowercase() ); - 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 tx: String = row.try_get("tx")?; let block: String = row.try_get("block")?; @@ -132,10 +134,14 @@ pub async fn v2_get_undelegations( ) }; - let row_cnt = sqlx::query(sql_count.as_str()).fetch_one(&mut conn).await?; + let row_cnt = sqlx::query(sql_count.as_str()) + .fetch_one(&mut *conn) + .await?; let total: i64 = row_cnt.try_get("cnt")?; let mut res: Vec = vec![]; - 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 tx: String = row.try_get("tx")?; let block: String = row.try_get("block")?;