From 9c7fcc1760ac7801d08231ce368dacbf986f18bd Mon Sep 17 00:00:00 2001 From: ssuchichan Date: Sat, 6 Apr 2024 15:49:13 +0800 Subject: [PATCH 1/2] Update dependencies. --- explorer/Cargo.toml | 2 +- explorer/src/service/util.rs | 13 +++--- explorer/src/service/v1/asset.rs | 39 ++++++++++------- explorer/src/service/v1/transaction.rs | 53 ++++++++++++++++++------ explorer/src/service/v2/native_to_evm.rs | 3 +- module/Cargo.toml | 7 ++-- module/src/utils/crypto.rs | 3 +- prismer/Cargo.toml | 16 +++---- prismer/src/commands.rs | 6 --- prismer/src/rpc.rs | 7 ++-- prismer/src/utils.rs | 6 ++- scanner/Cargo.toml | 17 ++++---- scanner/src/commands.rs | 17 +++----- scanner/src/rpc.rs | 16 ++++--- scanner/src/util.rs | 6 ++- temp-server/Cargo.toml | 6 +-- 16 files changed, 124 insertions(+), 93 deletions(-) diff --git a/explorer/Cargo.toml b/explorer/Cargo.toml index 0e3508a..0c077f6 100644 --- a/explorer/Cargo.toml +++ b/explorer/Cargo.toml @@ -16,7 +16,7 @@ serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" env_logger = "0.11.3" log = "0.4.14" -base64 = "0.10" +base64 = "0.22.0" bech32 = "0.7.2" ruc = "1.0" reqwest = { version = "0.12.3", features = ["json"] } diff --git a/explorer/src/service/util.rs b/explorer/src/service/util.rs index 8391c05..a239bbb 100644 --- a/explorer/src/service/util.rs +++ b/explorer/src/service/util.rs @@ -1,4 +1,5 @@ use anyhow::Error; +use base64::{engine, Engine}; use poem::http::StatusCode; use ruc::{d, Result, RucResult}; use { @@ -9,13 +10,14 @@ use { #[allow(unused)] #[inline(always)] pub fn public_key_to_base64(key: &XfrPublicKey) -> String { - base64::encode_config(&ZeiFromToBytes::zei_to_bytes(key), base64::URL_SAFE) + engine::general_purpose::URL_SAFE.encode(&ZeiFromToBytes::zei_to_bytes(key)) } #[allow(unused)] #[inline(always)] pub fn public_key_from_base64(pk: &str) -> Result { - base64::decode_config(pk, base64::URL_SAFE) + engine::general_purpose::URL_SAFE + .decode(pk) .c(d!()) .and_then(|bytes| XfrPublicKey::zei_from_bytes(&bytes).c(d!())) } @@ -65,7 +67,6 @@ pub fn handle_fetch_one_err(err: Error) -> poem::Error { #[cfg(test)] mod tests { use super::*; - use base64::URL_SAFE; #[tokio::test] async fn test_public_key_to_bech32() -> Result<()> { @@ -89,10 +90,12 @@ mod tests { async fn test_asset_code() -> Result<()> { let asset_addr = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA="; let asset_raw: Vec = vec![0u8; 32]; - let res_code = base64::decode_config(asset_addr, URL_SAFE).unwrap(); + let res_code = engine::general_purpose::URL_SAFE + .decode(asset_addr) + .unwrap(); assert_eq!(asset_raw, res_code); - let res_addr = base64::encode_config(&asset_raw, URL_SAFE); + let res_addr = engine::general_purpose::URL_SAFE.encode(&asset_raw); assert_eq!(asset_addr, res_addr); Ok(()) } diff --git a/explorer/src/service/v1/asset.rs b/explorer/src/service/v1/asset.rs index 26cd8e0..bb69a4a 100644 --- a/explorer/src/service/v1/asset.rs +++ b/explorer/src/service/v1/asset.rs @@ -1,5 +1,6 @@ use crate::service::api::Api; use anyhow::Result; +use base64::{engine, Engine}; use module::utils::crypto::bech32enc; use poem_openapi::{param::Path, param::Query, payload::Json, ApiResponse, Object}; use serde::{Deserialize, Serialize}; @@ -83,7 +84,7 @@ pub struct AssetRPCResult { pub async fn get_asset(api: &Api, address: Path) -> Result { let mut conn = api.storage.lock().await.acquire().await?; - let code_res = base64::decode_config(&address.0, base64::URL_SAFE); + let code_res = engine::general_purpose::URL_SAFE.decode(&address.0); let code = match code_res { Ok(code) => code, _ => { @@ -95,7 +96,9 @@ pub async fn get_asset(api: &Api, address: Path) -> Result) -> Result) -> Result() .await?; - let pk_vec = base64::decode_config(&resp.properties.issuer.key, base64::URL_SAFE)?; + let pk_vec = engine::general_purpose::URL_SAFE.decode(&resp.properties.issuer.key)?; 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); + let asset_code = engine::general_purpose::URL_SAFE.encode(&resp.properties.code.val); assets.push(AssetDisplay { issuer: issuer_addr, @@ -217,7 +220,8 @@ pub async fn get_asset_list( 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 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?; @@ -230,10 +234,10 @@ 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_vec = base64::decode_config(&a.issuer.key, base64::URL_SAFE)?; + let pk_vec = engine::general_purpose::URL_SAFE.decode(&a.issuer.key)?; 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); + let asset_code = engine::general_purpose::URL_SAFE.encode(&a.code.val); assets.push(AssetDisplay { issuer: issuer_addr, @@ -333,7 +337,8 @@ pub async fn get_issued_asset_list( 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 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?; @@ -345,10 +350,10 @@ 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_vec = base64::decode_config(&a.pubkey.key, base64::URL_SAFE)?; + let pk_vec = engine::general_purpose::URL_SAFE.decode(&a.pubkey.key)?; 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); + let asset_code = engine::general_purpose::URL_SAFE.encode(&a.body.code.val); assets.push(IssueAssetData { issuer, @@ -397,7 +402,7 @@ pub async fn get_issued_asset( ) -> Result { let mut conn = api.storage.lock().await.acquire().await?; - let code_res = base64::decode_config(&address.0, base64::URL_SAFE); + let code_res = engine::general_purpose::URL_SAFE.decode(&address.0); let code = match code_res { Ok(code) => code, _ => { @@ -411,7 +416,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 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?; @@ -423,10 +430,10 @@ 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_vec = base64::decode_config(&a.pubkey.key, base64::URL_SAFE)?; + let pk_vec = engine::general_purpose::URL_SAFE.decode(&a.pubkey.key)?; 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); + let asset_code = engine::general_purpose::URL_SAFE.encode(&a.body.code.val); return Ok(SingleIssueAssetResponse::Ok(Json(SingleIssueAssetResult { code: 200, diff --git a/explorer/src/service/v1/transaction.rs b/explorer/src/service/v1/transaction.rs index ca0a559..7ac0b0a 100644 --- a/explorer/src/service/v1/transaction.rs +++ b/explorer/src/service/v1/transaction.rs @@ -1,6 +1,7 @@ use crate::service::util::{public_key_from_bech32, public_key_to_base64}; use crate::Api; use anyhow::Result; +use base64::{engine, Engine}; use ethereum_types::H256; use module::schema::{ EvmTx, PrismTransaction, TransactionResponse, UnDelegationValue, ABAR_TO_ABAR, ABAR_TO_BAR, @@ -214,7 +215,13 @@ pub async fn get_prism_received( .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 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?; @@ -247,7 +254,7 @@ pub async fn get_prism_received( decimal: decimal as i64, height, timestamp, - data: base64::encode(&result_bin), + data: engine::general_purpose::STANDARD.encode(&result_bin), }); } @@ -323,7 +330,9 @@ pub async fn get_prism_records_send( .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 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) @@ -338,7 +347,7 @@ pub async fn get_prism_records_send( let ca: ConvertAccount = serde_json::from_value(ca_val)?; let asset: String; if let Some(asset_bin) = &ca.asset_type { - asset = base64::encode_config(asset_bin, base64::URL_SAFE); + asset = engine::general_purpose::URL_SAFE.encode(asset_bin); } else { asset = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=".to_string(); } @@ -358,7 +367,7 @@ pub async fn get_prism_records_send( decimal: 6, height, timestamp, - data: base64::encode(&ca_bin), + data: engine::general_purpose::STANDARD.encode(&ca_bin), }); } @@ -489,13 +498,16 @@ 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 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 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 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?; @@ -561,13 +573,16 @@ 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 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 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 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?; @@ -780,7 +795,8 @@ pub async fn get_txs_raw( let pk = pk.unwrap(); let native_addr = public_key_to_base64(&pk); params.push(format!( - "((value @? '$.body.operations[*].TransferAsset.body.transfer.inputs[*].public_key ? (@==\"{native_addr}\")') OR (value @? '$.body.operations[*].TransferAsset.body.transfer.outputs[*].public_key ? (@==\"{native_addr}\")')) " + "((value @? '$.body.operations[*].TransferAsset.body.transfer.inputs[*].public_key ? (@==\"{native_addr}\")') \ + OR (value @? '$.body.operations[*].TransferAsset.body.transfer.outputs[*].public_key ? (@==\"{native_addr}\")')) " )); } @@ -930,7 +946,8 @@ pub async fn get_triple_masking_txs( } } } else if let Some(pk) = pub_key.0 { - params.push(format!("(value @? '$.body.operations[*].AbarToBar.note.body.output.public_key ? (@==\"{pk}\")') OR (value @? '$.body.operations[*].BarToAbar.note.body.output.commitment ? (@==\"{pk}\")') ")); + params.push(format!("(value @? '$.body.operations[*].AbarToBar.note.body.output.public_key ? (@==\"{pk}\")') \ + OR (value @? '$.body.operations[*].BarToAbar.note.body.output.commitment ? (@==\"{pk}\")') ")); } if let Some(start_time) = start_time.0 { @@ -1136,7 +1153,8 @@ pub async fn get_claims_amount(api: &Api, address: Path) -> Result>, ) -> Result { let mut conn = api.storage.lock().await.acquire().await?; - let mut sql = String::from("SELECT tx_hash,block_hash,ty,timestamp,CASE WHEN fnuc_code = '248,251,204,194' THEN '_consumeMint' WHEN fnuc_code = '242,38,15,112' THEN '_withdrawFRA' WHEN fnuc_code = '116,64,166,22' THEN '_withdrawFRC20' WHEN fnuc_code = '250,190,177,88' THEN 'adminSetAsset' WHEN fnuc_code = '185,50,44,225' THEN 'adminSetLedger' WHEN fnuc_code = '5,5,220,224' THEN 'asset_contract' WHEN fnuc_code = '82,79,49,152' THEN 'consumeMint' WHEN fnuc_code = '222,147,129,28' THEN 'depositFRA' WHEN fnuc_code = '230,242,112,109' THEN 'depositFRC20' WHEN fnuc_code = '4,78,219,111' THEN 'ledger_contract' WHEN fnuc_code = '253,253,93,76' THEN 'ops' WHEN fnuc_code = '141,165,203,91' THEN 'owner' WHEN fnuc_code = '216,78,128,56' THEN 'proxy_contract' WHEN fnuc_code = '113,80,24,166' THEN 'renounceOwnership' WHEN fnuc_code = '242,253,227,139' THEN 'transferOwnership' WHEN fnuc_code = '24,188,157,230' THEN 'withdrawFRA' WHEN fnuc_code = '82,119,153,176' THEN 'withdrawFRC20' ELSE 'unknown' END AS fnuc_name,value,code,log FROM(SELECT tx_hash,block_hash,ty,timestamp,concat(value -> 'function' -> 'Ethereum' -> 'Transact' -> 'input'->0, NULL, ',', value -> 'function' -> 'Ethereum' -> 'Transact' -> 'input'->1, NULL, ',', value -> 'function' -> 'Ethereum' -> 'Transact' -> 'input'->2, NULL, ',', value -> 'function' -> 'Ethereum' -> 'Transact' -> 'input'->3) AS fnuc_code,value,code,log FROM transaction WHERE ty = 1"); + let mut sql = String::from("SELECT tx_hash,block_hash,ty,timestamp,CASE WHEN fnuc_code = '248,251,204,194' \ + THEN '_consumeMint' WHEN fnuc_code = '242,38,15,112' THEN '_withdrawFRA' WHEN fnuc_code = '116,64,166,22' THEN '_withdrawFRC20' \ + WHEN fnuc_code = '250,190,177,88' THEN 'adminSetAsset' WHEN fnuc_code = '185,50,44,225' THEN 'adminSetLedger' \ + WHEN fnuc_code = '5,5,220,224' THEN 'asset_contract' WHEN fnuc_code = '82,79,49,152' THEN 'consumeMint' \ + WHEN fnuc_code = '222,147,129,28' THEN 'depositFRA' WHEN fnuc_code = '230,242,112,109' THEN 'depositFRC20' \ + WHEN fnuc_code = '4,78,219,111' THEN 'ledger_contract' WHEN fnuc_code = '253,253,93,76' THEN 'ops' \ + WHEN fnuc_code = '141,165,203,91' THEN 'owner' WHEN fnuc_code = '216,78,128,56' THEN 'proxy_contract' \ + WHEN fnuc_code = '113,80,24,166' THEN 'renounceOwnership' WHEN fnuc_code = '242,253,227,139' \ + THEN 'transferOwnership' WHEN fnuc_code = '24,188,157,230' THEN 'withdrawFRA' \ + WHEN fnuc_code = '82,119,153,176' THEN 'withdrawFRC20' ELSE 'unknown' END AS fnuc_name,value,code,log FROM(SELECT tx_hash,block_hash,ty,timestamp,concat(value -> 'function' -> 'Ethereum' -> 'Transact' -> 'input'->0, NULL, ',', value -> 'function' -> 'Ethereum' -> 'Transact' -> 'input'->1, NULL, ',', value -> 'function' -> 'Ethereum' -> 'Transact' -> 'input'->2, NULL, ',', value -> 'function' -> 'Ethereum' -> 'Transact' -> 'input'->3) AS fnuc_code,value,code,log FROM transaction WHERE ty = 1"); let mut sql_total = String::from("SELECT count(*) as total FROM transaction WHERE ty = 1"); let mut params: Vec = vec![]; params.push(format!( diff --git a/explorer/src/service/v2/native_to_evm.rs b/explorer/src/service/v2/native_to_evm.rs index a1be8cd..a1bc507 100644 --- a/explorer/src/service/v2/native_to_evm.rs +++ b/explorer/src/service/v2/native_to_evm.rs @@ -3,6 +3,7 @@ use crate::service::v1::transaction::{ ConvertAccount, V2PrismItem, V2PrismRecord, V2PrismRecordResponse, V2PrismRecordResult, }; use anyhow::Result; +use base64::{engine, Engine}; use poem_openapi::param::Query; use poem_openapi::{param::Path, payload::Json, ApiResponse, Object}; use reqwest::StatusCode; @@ -228,7 +229,7 @@ pub async fn v2_get_prism_records_send( decimal: 6, height, timestamp, - data: base64::encode(&ca_bin), + data: engine::general_purpose::STANDARD.encode(&ca_bin), }); } diff --git a/module/Cargo.toml b/module/Cargo.toml index af8a485..315c21a 100644 --- a/module/Cargo.toml +++ b/module/Cargo.toml @@ -7,14 +7,13 @@ edition = "2021" [dependencies] chrono = { version = "0.4.19", features = ["serde"] } anyhow = "1.0.52" -toml = "0.5.8" +toml = "0.8.12" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" poem-openapi = {version = "1.2.30"} - rlp = { version = "0.5", default-features = false } -ethereum-types = "0.12" -ethereum = { version = "0.9.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.8", default-features = false } hex = "0.4.3" libsecp256k1 = { version = "0.5", features = ["static-context", "hmac"] } diff --git a/module/src/utils/crypto.rs b/module/src/utils/crypto.rs index 04ba477..ade772b 100644 --- a/module/src/utils/crypto.rs +++ b/module/src/utils/crypto.rs @@ -1,5 +1,6 @@ use bech32::ToBase32; -use ethereum::{LegacyTransaction, LegacyTransactionMessage}; +use ethereum::LegacyTransaction; +use ethereum::LegacyTransactionMessage; use ethereum_types::{H160, H256}; use ruc::eg; use sha3::{Digest, Keccak256}; diff --git a/prismer/Cargo.toml b/prismer/Cargo.toml index 501caba..00dbf05 100644 --- a/prismer/Cargo.toml +++ b/prismer/Cargo.toml @@ -8,15 +8,14 @@ edition = "2021" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" sqlx = { version = "0.6.0", features = ["runtime-tokio-rustls", "postgres", "chrono", "json"] } -reqwest = { version = "0.11", default-features = false, features = ["json", "rustls-tls"] } +reqwest = { version = "0.12.3", default-features = false, features = ["json", "rustls-tls"] } ruc = "1.0" -base64 = "0.13.0" +base64 = "0.22.0" bech32 = "0.7.2" crossbeam = "0.8" chrono = "0.4.19" -clap = { version = "3.0.5", features = ["derive"] } -dotenv = "0.15" -env_logger = "0.9.0" +clap = { version = "4.5.4", features = ["derive"] } +env_logger = "0.11.3" sha2 = "0.10" hex = "0.4" module = { path = "../module" } @@ -26,10 +25,11 @@ tokio = { version = "1", features = ["full"] } # x86_64-unknown-linux-musl using the "vendored" feature below openssl-sys = { version = "*", features = ["vendored"] } rlp = { version = "0.5", default-features = false } -ethereum-types = "0.13.1" -ethereum = { version = "0.9.0", default-features = false, features = ["with-serde"] } +ethereum-types = "0.14.1" +ethereum = { version = "0.15.0", default-features = false, features = ["with-serde"] } ethabi = "18.0.0" zei = { git = "https://github.com/FindoraNetwork/zei", branch = "stable-main" } +dotenv = "0.15.0" [features] default = [] -static-check =[] \ No newline at end of file +static-check =[] diff --git a/prismer/src/commands.rs b/prismer/src/commands.rs index ca5175b..1889248 100644 --- a/prismer/src/commands.rs +++ b/prismer/src/commands.rs @@ -34,9 +34,6 @@ pub struct Load { ///Times to retry to pull a block. #[clap(long)] retries: Option, - ///whether to load staking. - #[clap(long, parse(from_flag))] - staking: bool, } impl Load { @@ -135,9 +132,6 @@ pub struct Subscribe { ///How many concurrency would be used when scanning, default is 8. #[clap(long)] concurrency: Option, - ///Load staking while subscribing. - #[clap(long, parse(from_flag))] - staking: bool, } impl Subscribe { diff --git a/prismer/src/rpc.rs b/prismer/src/rpc.rs index 4b3223b..f4dadd6 100644 --- a/prismer/src/rpc.rs +++ b/prismer/src/rpc.rs @@ -1,6 +1,7 @@ use crate::utils::bech32_encode; use crate::{db, tx}; use crate::{Error, Result}; +use base64::{engine, Engine}; use chrono::NaiveDateTime; use ethabi::{Event as EthEvent, EventParam, Hash, ParamType, RawLog}; use ethereum::LegacyTransaction; @@ -187,13 +188,13 @@ impl RPCCaller { let mut res: Vec = vec![]; for tx in block.block.data.txs.unwrap_or_default() { - let bytes = base64::decode(&tx)?; + let bytes = engine::general_purpose::STANDARD.decode(&tx)?; let hasher = sha2::Sha256::digest(&bytes); let txid = hex::encode(hasher); let tx = self.rpc.load_transaction(&txid).await?; let result_data = tx.tx_result.data.clone(); if let Value::String(s) = result_data { - let bin_data = base64::decode(s)?; + let bin_data = engine::general_purpose::STANDARD.decode(s)?; let result_data: TxResultData = serde_json::from_slice(&bin_data)?; let result: Value = serde_json::to_value(&result_data)?; if let tx::TxCatalog::EvmTx = tx::try_tx_catalog(&bytes) { @@ -250,7 +251,7 @@ impl RPCCaller { let asset_bytes = log_res.params[0].value.clone().into_fixed_bytes().unwrap(); let asset = - base64::encode_config(&asset_bytes, base64::URL_SAFE); + engine::general_purpose::URL_SAFE.encode(&asset_bytes); // receiver address let receiver_bytes = diff --git a/prismer/src/utils.rs b/prismer/src/utils.rs index 43c078e..2c16163 100644 --- a/prismer/src/utils.rs +++ b/prismer/src/utils.rs @@ -1,3 +1,4 @@ +use base64::{engine, Engine}; use { bech32::{self, FromBase32, ToBase32}, ruc::*, @@ -7,13 +8,14 @@ use { #[allow(unused)] #[inline(always)] pub fn public_key_to_base64(key: &XfrPublicKey) -> String { - base64::encode_config(ZeiFromToBytes::zei_to_bytes(key), base64::URL_SAFE) + engine::general_purpose::URL_SAFE.encode(ZeiFromToBytes::zei_to_bytes(key)) } #[allow(unused)] #[inline(always)] pub fn public_key_from_base64(pk: &str) -> Result { - base64::decode_config(pk, base64::URL_SAFE) + engine::general_purpose::URL_SAFE + .decode(pk) .c(d!()) .and_then(|bytes| XfrPublicKey::zei_from_bytes(&bytes).c(d!())) } diff --git a/scanner/Cargo.toml b/scanner/Cargo.toml index c4e65ee..9ff9962 100644 --- a/scanner/Cargo.toml +++ b/scanner/Cargo.toml @@ -11,20 +11,20 @@ path = "src/bin/scanner.rs" [dependencies] serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" -sqlx = { version = "0.6.0", features = ["runtime-tokio-rustls", "postgres", "chrono", "json"]} -reqwest = { version = "0.11", default-features = false, features = ["json", "rustls-tls"] } -ethereum-types = "0.12" -ethereum = { version = "0.9.0", default-features = false, features = ["with-serde"] } +sqlx = { version = "0.6.0", features = ["runtime-tokio-rustls", "postgres", "chrono", "json"] } +reqwest = { version = "0.12.3", default-features = false, features = ["json", "rustls-tls"] } +ethereum-types = "0.14.1" +ethereum = { version = "0.15.0", default-features = false, features = ["with-serde"] } sha3 = { version = "0.10.4", default-features = false } rlp = { version = "0.5", default-features = false } futures = "0.3.28" -base64 = "0.13.0" +base64 = "0.22.0" bech32 = "0.7.2" crossbeam = "0.8" chrono = "0.4.19" -clap = { version = "3.0.5", features = ["derive"] } -dotenv = "0.15" -env_logger = "0.9.0" +clap = { version = "4.5.4", features = ["derive"] } +dotenv = "0.15.0" +env_logger = "0.11.3" sha2 = "0.10" hex = "0.4" module = { path = "../module" } @@ -35,6 +35,7 @@ tokio = { version = "1", features = ["full"] } # x86_64-unknown-linux-musl using the "vendored" feature below openssl-sys = { version = "*", features = ["vendored"] } zei = { git = "https://github.com/FindoraNetwork/zei", branch = "stable-main" } + [features] default = [] static-check =[] diff --git a/scanner/src/commands.rs b/scanner/src/commands.rs index ae74603..702a775 100644 --- a/scanner/src/commands.rs +++ b/scanner/src/commands.rs @@ -9,7 +9,7 @@ use crate::types::{ use crate::util::pubkey_to_fra_address; use crate::{db, rpc::RPCCaller, scanner::RangeScanner}; use crate::{Error, Result}; -use base64::URL_SAFE; +use base64::{engine, Engine}; use clap::Parser; use ethereum::TransactionAction; use ethereum_types::H256; @@ -53,9 +53,6 @@ pub struct Load { ///Times to retry to pull a block. #[clap(long)] retries: Option, - ///whether to load staking. - #[clap(long, parse(from_flag))] - staking: bool, } impl Load { @@ -154,9 +151,6 @@ pub struct Subscribe { ///How many concurrency would be used when scanning, default is 8. #[clap(long)] concurrency: Option, - ///Load staking while subscribing. - #[clap(long, parse(from_flag))] - staking: bool, } impl Subscribe { @@ -287,7 +281,7 @@ impl Migrate { let opt: ConvertAccountOpt = serde_json::from_value(op).unwrap(); let asset: String; if let Some(asset_bin) = &opt.convert_account.asset_type { - asset = base64::encode_config(asset_bin, base64::URL_SAFE); + asset = engine::general_purpose::URL_SAFE.encode(asset_bin); } else { asset = FRA_ASSET.to_string(); } @@ -382,8 +376,8 @@ impl Migrate { let op_copy = op.clone(); let opt: DefineAssetOpt = serde_json::from_value(op).unwrap(); let issuer = pubkey_to_fra_address(&opt.define_asset.pubkey.key).unwrap(); - let asset = - base64::encode_config(opt.define_asset.body.asset.code.val, URL_SAFE); + let asset = engine::general_purpose::URL_SAFE + .encode(opt.define_asset.body.asset.code.val); save_asset_tx( &asset, &tx.to_lowercase(), @@ -402,7 +396,8 @@ impl Migrate { let op_copy = op.clone(); let opt: IssueAssetOpt = serde_json::from_value(op).unwrap(); let issuer = pubkey_to_fra_address(&opt.issue_asset.pubkey.key).unwrap(); - let asset = base64::encode_config(opt.issue_asset.body.code.val, URL_SAFE); + let asset = + engine::general_purpose::URL_SAFE.encode(opt.issue_asset.body.code.val); save_asset_tx( &asset, &tx.to_lowercase(), diff --git a/scanner/src/rpc.rs b/scanner/src/rpc.rs index 1a421d1..40003ff 100644 --- a/scanner/src/rpc.rs +++ b/scanner/src/rpc.rs @@ -8,7 +8,7 @@ use crate::types::{ use crate::util::pubkey_to_fra_address; use crate::{db, tx}; use crate::{Error, Result}; -use base64::URL_SAFE; +use base64::{engine, Engine}; use chrono::NaiveDateTime; use ethereum::TransactionAction; use module::rpc::block::BlockSizeRPC; @@ -200,7 +200,7 @@ impl RPCCaller { let mut native_addrs: Vec
= vec![]; for tx_string in block.block.data.txs.unwrap_or_default() { - let bytes = base64::decode(&tx_string)?; + let bytes = engine::general_purpose::STANDARD.decode(&tx_string)?; let origin = tx_string; let hasher = sha2::Sha256::digest(&bytes); let tx_hash = hex::encode(hasher); @@ -321,7 +321,7 @@ impl RPCCaller { let opt: ConvertAccountOpt = serde_json::from_value(op).unwrap(); let asset: String; if let Some(asset_bin) = &opt.convert_account.asset_type { - asset = base64::encode_config(asset_bin, base64::URL_SAFE); + asset = engine::general_purpose::URL_SAFE.encode(asset_bin); } else { asset = FRA_ASSET.to_string(); } @@ -420,10 +420,8 @@ impl RPCCaller { let opt: DefineAssetOpt = serde_json::from_value(op).unwrap(); let issuer = pubkey_to_fra_address(&opt.define_asset.pubkey.key).unwrap(); - let asset = base64::encode_config( - opt.define_asset.body.asset.code.val, - URL_SAFE, - ); + let asset = engine::general_purpose::URL_SAFE + .encode(opt.define_asset.body.asset.code.val); sender = issuer.clone(); ty_sub = FindoraTxType::DefineOrIssueAsset as i32; v2_asset_txs.push(V2AssetTx { @@ -442,8 +440,8 @@ impl RPCCaller { let opt: IssueAssetOpt = serde_json::from_value(op).unwrap(); let issuer = pubkey_to_fra_address(&opt.issue_asset.pubkey.key).unwrap(); - let asset = - base64::encode_config(opt.issue_asset.body.code.val, URL_SAFE); + let asset = engine::general_purpose::URL_SAFE + .encode(opt.issue_asset.body.code.val); sender = issuer.clone(); ty_sub = FindoraTxType::DefineOrIssueAsset as i32; v2_asset_txs.push(V2AssetTx { diff --git a/scanner/src/util.rs b/scanner/src/util.rs index b753320..84f2fb6 100644 --- a/scanner/src/util.rs +++ b/scanner/src/util.rs @@ -1,3 +1,4 @@ +use base64::{engine, Engine}; use { bech32::{self, FromBase32, ToBase32}, ruc::*, @@ -7,13 +8,14 @@ use { #[allow(unused)] #[inline(always)] pub fn public_key_to_base64(key: &XfrPublicKey) -> String { - base64::encode_config(ZeiFromToBytes::zei_to_bytes(key), base64::URL_SAFE) + engine::general_purpose::URL_SAFE.encode(ZeiFromToBytes::zei_to_bytes(key)) } #[allow(unused)] #[inline(always)] pub fn public_key_from_base64(pk: &str) -> Result { - base64::decode_config(pk, base64::URL_SAFE) + engine::general_purpose::URL_SAFE + .decode(pk) .c(d!()) .and_then(|bytes| XfrPublicKey::zei_from_bytes(&bytes).c(d!())) } diff --git a/temp-server/Cargo.toml b/temp-server/Cargo.toml index 5c87941..024618b 100644 --- a/temp-server/Cargo.toml +++ b/temp-server/Cargo.toml @@ -11,6 +11,6 @@ tokio = { version = "1.0", features = ["full"] } anyhow = "1.0.52" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" -env_logger = "0.9.0" -reqwest = { version = "0.11", features = ["json"] } -toml = "0.5.8" +env_logger = "0.11.3" +reqwest = { version = "0.12.3", features = ["json"] } +toml = "0.8.12" From 6500f42d883e5227b3874c996e02d21c1997f557 Mon Sep 17 00:00:00 2001 From: ssuchichan Date: Sat, 6 Apr 2024 16:01:08 +0800 Subject: [PATCH 2/2] Fix: lint. --- explorer/src/service/util.rs | 2 +- module/src/utils/crypto.rs | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/explorer/src/service/util.rs b/explorer/src/service/util.rs index a239bbb..f515ad6 100644 --- a/explorer/src/service/util.rs +++ b/explorer/src/service/util.rs @@ -10,7 +10,7 @@ use { #[allow(unused)] #[inline(always)] pub fn public_key_to_base64(key: &XfrPublicKey) -> String { - engine::general_purpose::URL_SAFE.encode(&ZeiFromToBytes::zei_to_bytes(key)) + engine::general_purpose::URL_SAFE.encode(ZeiFromToBytes::zei_to_bytes(key)) } #[allow(unused)] diff --git a/module/src/utils/crypto.rs b/module/src/utils/crypto.rs index ade772b..04ba477 100644 --- a/module/src/utils/crypto.rs +++ b/module/src/utils/crypto.rs @@ -1,6 +1,5 @@ use bech32::ToBase32; -use ethereum::LegacyTransaction; -use ethereum::LegacyTransactionMessage; +use ethereum::{LegacyTransaction, LegacyTransactionMessage}; use ethereum_types::{H160, H256}; use ruc::eg; use sha3::{Digest, Keccak256};