diff --git a/explorer/src/service/v1/staking.rs b/explorer/src/service/v1/staking.rs index 89965a2..650b20f 100644 --- a/explorer/src/service/v1/staking.rs +++ b/explorer/src/service/v1/staking.rs @@ -1,9 +1,8 @@ use crate::service::api::Api; use crate::service::util::{public_key_from_base64, public_key_from_bech32, public_key_to_base64}; use anyhow::Result; -use log::{debug, error}; -use module::schema::{ClaimOpt, DelegationOpt, TdValidator, UnDelegationOpt}; -use poem_openapi::param::{Path, Query}; +use module::schema::{ClaimOpt, DelegationOpt, UnDelegationOpt}; +use poem_openapi::param::Query; use poem_openapi::{payload::Json, ApiResponse, Object}; use serde::{Deserialize, Serialize}; use serde_json::Value; @@ -85,26 +84,26 @@ pub async fn get_tx_delegation( let val: Value = row.try_get("d")?; let opt: DelegationOpt = serde_json::from_value(val).unwrap(); - let validator_detail_url = api - .platform - .rpc - .join(format!("validator_detail/{}", opt.body.validator).as_str()) - .unwrap(); - let res = reqwest::get(validator_detail_url) - .await? - .json::() - .await; - if res.is_err() { - error!("failed to parse validator: {}", opt.body.validator); - continue; - } - let validator = res.unwrap(); + // let validator_detail_url = api + // .platform + // .rpc + // .join(format!("validator_detail/{}", opt.body.validator).as_str()) + // .unwrap(); + // let res = reqwest::get(validator_detail_url) + // .await? + // .json::() + // .await; + // if res.is_err() { + // error!("failed to parse validator: {}", opt.body.validator); + // continue; + // } + // let validator = res.unwrap(); items.push(DelegationItem { tx_hash, - node_address: validator.addr, - node_name: validator.memo.name, - node_logo: validator.memo.logo, + node_address: "".into(), + node_name: "".into(), + node_logo: "".into(), amount: opt.body.amount, timestamp, }); @@ -200,28 +199,28 @@ pub async fn get_tx_undelegation( if opt.body.pu.is_none() { continue; } - let validator_address = - hex::encode(opt.body.pu.as_ref().unwrap().target_validator).to_uppercase(); - let validator_detail_url = api - .platform - .rpc - .join(format!("validator_detail/{validator_address}").as_str()) - .unwrap(); - let res = reqwest::get(validator_detail_url) - .await? - .json::() - .await; - if res.is_err() { - error!("failed to parse validator: {}", validator_address); - continue; - } - let validator = res.unwrap(); + // let validator_address = + // hex::encode(opt.body.pu.as_ref().unwrap().target_validator).to_uppercase(); + // let validator_detail_url = api + // .platform + // .rpc + // .join(format!("validator_detail/{validator_address}").as_str()) + // .unwrap(); + // let res = reqwest::get(validator_detail_url) + // .await? + // .json::() + // .await; + // if res.is_err() { + // error!("failed to parse validator: {}", validator_address); + // continue; + // } + // let validator = res.unwrap(); items.push(UnDelegationItem { tx_hash, - node_address: validator.addr, - node_name: validator.memo.name, - node_logo: validator.memo.logo, + node_address: "".into(), + node_name: "".into(), + node_logo: "".into(), amount: opt.body.pu.unwrap().am, timestamp, expected_arrival_time: timestamp + 21 * 24 * 60 * 60, @@ -351,31 +350,31 @@ pub struct DelegationInfoResult { pub message: String, pub data: Option, } -#[allow(dead_code)] -pub async fn delegation(api: &Api, pubkey: Path) -> Result { - let delegation_info_url = api - .platform - .rpc - .join(format!("delegation_info/{}", pubkey.0).as_str()) - .unwrap(); - - debug!("delegation_info_url: {}", delegation_info_url); - - let res = api - .platform - .client - .get(delegation_info_url) - .send() - .await? - .json() - .await?; - - Ok(DelegationInfoResponse::Ok(Json(DelegationInfoResult { - code: 200, - message: "".to_string(), - data: Some(res), - }))) -} +// #[allow(dead_code)] +// pub async fn delegation(api: &Api, pubkey: Path) -> Result { +// let delegation_info_url = api +// .platform +// .rpc +// .join(format!("delegation_info/{}", pubkey.0).as_str()) +// .unwrap(); +// +// debug!("delegation_info_url: {}", delegation_info_url); +// +// let res = api +// .platform +// .client +// .get(delegation_info_url) +// .send() +// .await? +// .json() +// .await?; +// +// Ok(DelegationInfoResponse::Ok(Json(DelegationInfoResult { +// code: 200, +// message: "".to_string(), +// data: Some(res), +// }))) +// } #[derive(ApiResponse)] pub enum UndelegationResponse { diff --git a/explorer/src/service/v1/validator.rs b/explorer/src/service/v1/validator.rs index 2ca52db..962b643 100644 --- a/explorer/src/service/v1/validator.rs +++ b/explorer/src/service/v1/validator.rs @@ -108,21 +108,21 @@ pub struct ValidatorListData { pub validators: Vec, } -impl ValidatorListData { - fn wrap(self) -> WrapValidatorListData { - let mut wrap_validators: Vec = vec![]; - for v in self.validators { - wrap_validators.push(v.wrap()); - } - - WrapValidatorListData { - threshold: self.threshold, - validator_cnt: self.validator_cnt, - cur_height: self.cur_height, - validators: wrap_validators, - } - } -} +// impl ValidatorListData { +// fn wrap(self) -> WrapValidatorListData { +// let mut wrap_validators: Vec = vec![]; +// for v in self.validators { +// wrap_validators.push(v.wrap()); +// } +// +// WrapValidatorListData { +// threshold: self.threshold, +// validator_cnt: self.validator_cnt, +// cur_height: self.cur_height, +// validators: wrap_validators, +// } +// } +// } #[derive(Serialize, Deserialize, Debug, Default, Object)] pub struct Validator { @@ -134,19 +134,19 @@ pub struct Validator { pub extra: Memo, } -impl Validator { - fn wrap(self) -> WrapValidator { - WrapValidator { - addr: self.addr, - power: self.power, - commission_rate: self.commission_rate, - accept_delegation: self.accept_delegation, - online: false, - rank: self.rank, - extra: self.extra, - } - } -} +// impl Validator { +// fn wrap(self) -> WrapValidator { +// WrapValidator { +// addr: self.addr, +// power: self.power, +// commission_rate: self.commission_rate, +// accept_delegation: self.accept_delegation, +// online: false, +// rank: self.rank, +// extra: self.extra, +// } +// } +// } #[allow(dead_code)] pub async fn validator_delegation( @@ -176,77 +176,77 @@ pub async fn validator_delegation( ))) } -#[allow(dead_code)] -pub async fn validator_list(api: &Api) -> Result { - let mut conn = api.storage.lock().await.acquire().await?; - - let validator_list_url = api.platform.rpc.join("validator_list").unwrap(); - debug!("validator_list_url: {}", validator_list_url); - - let res = api - .platform - .client - .get(validator_list_url) - .send() - .await? - .json() - .await?; - - let validator_data: ValidatorListData = serde_json::from_value(res).unwrap(); - - let cur_height: i64 = validator_data.cur_height - 15; - let sql = format!( - "SELECT address FROM block_generation WHERE height={} AND signature is not null", - cur_height - ); - - let mut wrap_validator_data = validator_data.wrap(); - - 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")?; - signers.push(addr); - } - - for v in &mut wrap_validator_data.validators { - if signers.contains(&v.addr) { - v.online = true - } - } - - Ok(ValidatorListResponse::Ok(Json(ValidatorListResult { - code: 200, - message: "".to_string(), - data: Some(wrap_validator_data), - }))) -} - -#[allow(dead_code)] -pub async fn validator_detail(api: &Api, address: Path) -> Result { - let validator_detail_url = api - .platform - .rpc - .join(format!("validator_detail/{}", address.0).as_str()) - .unwrap(); - - debug!("validator_detail_url: {}", validator_detail_url); - - let res = api - .platform - .client - .get(validator_detail_url) - .send() - .await? - .json() - .await?; - - Ok(ValidatorDetailResponse::Ok(Json(ValidatorDetailResult { - code: 200, - message: "".to_string(), - data: Some(res), - }))) -} +// #[allow(dead_code)] +// pub async fn validator_list(api: &Api) -> Result { +// let mut conn = api.storage.lock().await.acquire().await?; +// +// let validator_list_url = api.platform.rpc.join("validator_list").unwrap(); +// debug!("validator_list_url: {}", validator_list_url); +// +// let res = api +// .platform +// .client +// .get(validator_list_url) +// .send() +// .await? +// .json() +// .await?; +// +// let validator_data: ValidatorListData = serde_json::from_value(res).unwrap(); +// +// let cur_height: i64 = validator_data.cur_height - 15; +// let sql = format!( +// "SELECT address FROM block_generation WHERE height={} AND signature is not null", +// cur_height +// ); +// +// let mut wrap_validator_data = validator_data.wrap(); +// +// 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")?; +// signers.push(addr); +// } +// +// for v in &mut wrap_validator_data.validators { +// if signers.contains(&v.addr) { +// v.online = true +// } +// } +// +// Ok(ValidatorListResponse::Ok(Json(ValidatorListResult { +// code: 200, +// message: "".to_string(), +// data: Some(wrap_validator_data), +// }))) +// } +// +// #[allow(dead_code)] +// pub async fn validator_detail(api: &Api, address: Path) -> Result { +// let validator_detail_url = api +// .platform +// .rpc +// .join(format!("validator_detail/{}", address.0).as_str()) +// .unwrap(); +// +// debug!("validator_detail_url: {}", validator_detail_url); +// +// let res = api +// .platform +// .client +// .get(validator_detail_url) +// .send() +// .await? +// .json() +// .await?; +// +// Ok(ValidatorDetailResponse::Ok(Json(ValidatorDetailResult { +// code: 200, +// message: "".to_string(), +// data: Some(res), +// }))) +// } #[allow(dead_code)] pub async fn delegator_list(api: &Api, address: Path) -> Result { diff --git a/scanner/src/rpc.rs b/scanner/src/rpc.rs index 40003ff..ec9db6e 100644 --- a/scanner/src/rpc.rs +++ b/scanner/src/rpc.rs @@ -333,7 +333,7 @@ impl RPCCaller { address: receiver.clone(), timestamp: timestamp.and_utc().timestamp(), }); - sender = signer.clone(); + sender.clone_from(&signer); ty_sub = FindoraTxType::NativeToEVM as i32; v2_convert_account_txs.push(V2ConvertAccountTx { tx_hash: tx_hash.clone(), @@ -365,7 +365,7 @@ impl RPCCaller { _ => (0, "".to_string(), "".to_string()), }; - sender = signer.clone(); + sender.clone_from(&signer); ty_sub = FindoraTxType::Undelegation as i32; v2_undelegation_txs.push(V2UndelegationTx { tx_hash: tx_hash.clone(), @@ -385,7 +385,7 @@ impl RPCCaller { let signer = pubkey_to_fra_address(&opt.delegation.pubkey).unwrap(); let new_validator = opt.delegation.body.new_validator.unwrap_or("".to_string()); - sender = signer.clone(); + sender.clone_from(&signer); ty_sub = FindoraTxType::Delegation as i32; v2_delegation_txs.push(V2DelegationTx { tx_hash: tx_hash.clone(), @@ -403,7 +403,7 @@ impl RPCCaller { let op_copy = op.clone(); let opt: ClaimOpt = serde_json::from_value(op).unwrap(); let signer = pubkey_to_fra_address(&opt.claim.pubkey).unwrap(); - sender = signer.clone(); + sender.clone_from(&signer); ty_sub = FindoraTxType::Claim as i32; v2_claim_txs.push(V2ClaimTx { tx_hash: tx_hash.clone(), @@ -422,7 +422,7 @@ impl RPCCaller { pubkey_to_fra_address(&opt.define_asset.pubkey.key).unwrap(); let asset = engine::general_purpose::URL_SAFE .encode(opt.define_asset.body.asset.code.val); - sender = issuer.clone(); + sender.clone_from(&issuer); ty_sub = FindoraTxType::DefineOrIssueAsset as i32; v2_asset_txs.push(V2AssetTx { asset, @@ -442,7 +442,7 @@ impl RPCCaller { pubkey_to_fra_address(&opt.issue_asset.pubkey.key).unwrap(); let asset = engine::general_purpose::URL_SAFE .encode(opt.issue_asset.body.code.val); - sender = issuer.clone(); + sender.clone_from(&issuer); ty_sub = FindoraTxType::DefineOrIssueAsset as i32; v2_asset_txs.push(V2AssetTx { asset,