diff --git a/src/arguments.rs b/src/arguments.rs index 57278dc..08ca67d 100644 --- a/src/arguments.rs +++ b/src/arguments.rs @@ -92,7 +92,7 @@ pub struct CliArgs { pub struct SeedEnvVars { pub seed: String, - #[allow(dead_code)] // TODO: Do we actually need this? + #[expect(dead_code)] // TODO: Do we actually need this? pub old_seeds: AHashMap, } diff --git a/src/chain.rs b/src/chain.rs index 7f866b3..9384c73 100644 --- a/src/chain.rs +++ b/src/chain.rs @@ -22,7 +22,7 @@ pub mod rpc; pub mod tracker; pub mod utils; -use crate::definitions::api_v2::{Health, RpcInfo, ServerHealth}; +use crate::definitions::api_v2::{Health, RpcInfo}; use definitions::{ChainRequest, ChainTrackerRequest, WatchAccount}; use tracker::start_chain_watch; @@ -67,12 +67,18 @@ impl ChainManager { // this MUST assert that there are no duplicates in requested assets if let Some(ref a) = c.native_token { - if let Some(_) = currency_map.insert(a.name.clone(), c.name.clone()) { + if currency_map + .insert(a.name.clone(), c.name.clone()) + .is_some() + { return Err(Error::DuplicateCurrency(a.name.clone())); } } for a in &c.asset { - if let Some(_) = currency_map.insert(a.name.clone(), c.name.clone()) { + if currency_map + .insert(a.name.clone(), c.name.clone()) + .is_some() + { return Err(Error::DuplicateCurrency(a.name.clone())); } } @@ -136,10 +142,8 @@ impl ChainManager { ChainRequest::Shutdown(res) => { for (name, chain) in watch_chain.drain() { let (tx, rx) = oneshot::channel(); - if chain.send(ChainTrackerRequest::Shutdown(tx)).await.is_ok() { - if timeout(SHUTDOWN_TIMEOUT, rx).await.is_err() { - tracing::error!("Chain monitor for {name} took too much time to wind down, probably it was frozen. Discarding it."); - }; + if chain.send(ChainTrackerRequest::Shutdown(tx)).await.is_ok() && timeout(SHUTDOWN_TIMEOUT, rx).await.is_err() { + tracing::error!("Chain monitor for {name} took too much time to wind down, probably it was frozen. Discarding it."); } } let _ = res.send(()); @@ -154,7 +158,7 @@ impl ChainManager { status: *status, } }).collect(); - let _ = res_tx.send(connected_rpcs); + let _unused = res_tx.send(connected_rpcs); } } } @@ -215,10 +219,10 @@ impl ChainManager { rx.await.map_err(|_| ChainError::MessageDropped)? } - pub async fn shutdown(&self) -> () { + pub async fn shutdown(&self) { let (tx, rx) = oneshot::channel(); let _unused = self.tx.send(ChainRequest::Shutdown(tx)).await; let _ = rx.await; - () + (); } } diff --git a/src/chain/definitions.rs b/src/chain/definitions.rs index 0258b63..321f27b 100644 --- a/src/chain/definitions.rs +++ b/src/chain/definitions.rs @@ -24,14 +24,14 @@ pub struct BlockHash(pub H256); impl BlockHash { /// Convert block hash to RPC-friendly format pub fn to_string(&self) -> String { - format!("0x{}", const_hex::encode(&self.0)) + format!("0x{}", const_hex::encode(self.0)) } /// Convert string returned by RPC to typesafe block /// /// TODO: integrate nicely with serde pub fn from_str(s: &str) -> Result { - let block_hash_raw = unhex(&s, NotHexError::BlockHash)?; + let block_hash_raw = unhex(s, NotHexError::BlockHash)?; Ok(BlockHash(H256( block_hash_raw .try_into() @@ -129,7 +129,7 @@ impl Invoice { if let Some(asset_id) = currency.asset_id { let balance = asset_balance_at_account( client, - &block, + block, &chain_watcher.metadata, &self.address, asset_id, @@ -138,7 +138,7 @@ impl Invoice { Ok(balance) } else { let balance = - system_balance_at_account(client, &block, &chain_watcher.metadata, &self.address) + system_balance_at_account(client, block, &chain_watcher.metadata, &self.address) .await?; Ok(balance) } diff --git a/src/chain/payout.rs b/src/chain/payout.rs index 141d22d..ea255c9 100644 --- a/src/chain/payout.rs +++ b/src/chain/payout.rs @@ -23,7 +23,7 @@ use crate::{ use frame_metadata::v15::RuntimeMetadataV15; use jsonrpsee::ws_client::WsClientBuilder; -use substrate_constructor::fill_prepare::{SpecialTypeToFill, TypeContentToFill}; +use substrate_constructor::fill_prepare::TypeContentToFill; /// Single function that should completely handle payout attmept. Just do not call anything else. /// diff --git a/src/chain/rpc.rs b/src/chain/rpc.rs index 9f5d6e6..59c0bbd 100644 --- a/src/chain/rpc.rs +++ b/src/chain/rpc.rs @@ -157,7 +157,7 @@ pub async fn genesis_hash(client: &WsClient) -> Result { .map_err(ChainError::Client)?; match genesis_hash_request { Value::String(x) => BlockHash::from_str(&x), - _ => return Err(ChainError::GenesisHashFormat), + _ => Err(ChainError::GenesisHashFormat), } } @@ -178,7 +178,7 @@ pub async fn block_hash( .map_err(ChainError::Client)?; match block_hash_request { Value::String(x) => BlockHash::from_str(&x), - _ => return Err(ChainError::BlockHashFormat), + _ => Err(ChainError::BlockHashFormat), } } @@ -206,21 +206,19 @@ pub async fn metadata( if let Some(meta_v15_bytes) = maybe_metadata_raw { if meta_v15_bytes.starts_with(b"meta") { match RuntimeMetadata::decode_all(&mut &meta_v15_bytes[4..]) { - Ok(RuntimeMetadata::V15(runtime_metadata_v15)) => { - return Ok(runtime_metadata_v15) - } - Ok(_) => return Err(ChainError::NoMetadataV15), - Err(_) => return Err(ChainError::MetadataNotDecodeable), + Ok(RuntimeMetadata::V15(runtime_metadata_v15)) => Ok(runtime_metadata_v15), + Ok(_) => Err(ChainError::NoMetadataV15), + Err(_) => Err(ChainError::MetadataNotDecodeable), } } else { - return Err(ChainError::NoMetaPrefix); + Err(ChainError::NoMetaPrefix) } } else { - return Err(ChainError::NoMetadataV15); + Err(ChainError::NoMetadataV15) } } - _ => return Err(ChainError::MetadataFormat), - }; + _ => Err(ChainError::MetadataFormat), + } } // fetch specs at known block @@ -233,8 +231,8 @@ pub async fn specs( .request("system_properties", rpc_params![block.to_string()]) .await?; match specs_request { - Value::Object(properties) => system_properties_to_short_specs(&properties, &metadata), - _ => return Err(ChainError::PropertiesFormat), + Value::Object(properties) => system_properties_to_short_specs(&properties, metadata), + _ => Err(ChainError::PropertiesFormat), } } @@ -250,7 +248,7 @@ pub async fn next_block( client: &WsClient, blocks: &mut Subscription, ) -> Result { - block_hash(&client, Some(next_block_number(blocks).await?)).await + block_hash(client, Some(next_block_number(blocks).await?)).await } #[derive(Deserialize, Debug)] @@ -278,10 +276,10 @@ pub async fn assets_set_at_block( let mut assets_asset_storage_metadata = None; let mut assets_metadata_storage_metadata = None; - for pallet in metadata_v15.pallets.iter() { + for pallet in &metadata_v15.pallets { if let Some(storage) = &pallet.storage { if storage.prefix == "Assets" { - for entry in storage.entries.iter() { + for entry in &storage.entries { if entry.name == "Asset" { assets_asset_storage_metadata = Some(entry); } @@ -307,7 +305,7 @@ pub async fn assets_set_at_block( get_keys_from_storage(client, "Assets", "Asset", block).await?; for available_keys_assets_asset in available_keys_assets_asset_vec { if let Value::Array(ref keys_array) = available_keys_assets_asset { - for key in keys_array.iter() { + for key in keys_array { if let Value::String(string_key) = key { let value_fetch = get_value_from_storage(client, string_key, block).await?; if let Value::String(ref string_value) = value_fetch { @@ -342,7 +340,7 @@ pub async fn assets_set_at_block( }?; let mut verified_sufficient = false; if let ParsedData::Composite(fields) = storage_entry.value.data { - for field_data in fields.iter() { + for field_data in &fields { if let Some(field_name) = &field_data.field_name { if field_name == "is_sufficient" { if let ParsedData::PrimitiveBool(is_it) = @@ -417,7 +415,7 @@ pub async fn assets_set_at_block( if let ParsedData::Composite(fields) = value.data { - for field_data in fields.iter() { + for field_data in &fields { if let Some(field_name) = &field_data.field_name { @@ -558,7 +556,7 @@ pub async fn asset_balance_at_account( &metadata_v15.types, )?; if let ParsedData::Composite(fields) = value.data { - for field in fields.iter() { + for field in &fields { if let ParsedData::PrimitiveU128 { value, specialty: SpecialtyUnsignedInteger::Balance, @@ -594,10 +592,10 @@ pub async fn system_balance_at_account( &metadata_v15.types, )?; if let ParsedData::Composite(fields) = value.data { - for field in fields.iter() { + for field in &fields { if field.field_name == Some("data".to_string()) { if let ParsedData::Composite(inner_fields) = &field.data.data { - for inner_field in inner_fields.iter() { + for inner_field in inner_fields { if inner_field.field_name == Some("free".to_string()) { if let ParsedData::PrimitiveU128 { value, @@ -622,10 +620,10 @@ pub async fn transfer_events( block: &BlockHash, metadata_v15: &RuntimeMetadataV15, ) -> Result, ChainError> { - let events_entry_metadata = events_entry_metadata(&metadata_v15)?; + let events_entry_metadata = events_entry_metadata(metadata_v15)?; events_at_block( - &client, + client, block, Some(EventFilter { pallet: BALANCES, @@ -651,8 +649,8 @@ async fn events_at_block( Value::Array(ref keys_array) => { for key in keys_array { if let Value::String(key) = key { - let data_from_storage = get_value_from_storage(client, &key, block).await?; - let key_bytes = unhex(&key, NotHexError::StorageValue)?; + let data_from_storage = get_value_from_storage(client, key, block).await?; + let key_bytes = unhex(key, NotHexError::StorageValue)?; let value_bytes = if let Value::String(data_from_storage) = data_from_storage { unhex(&data_from_storage, NotHexError::StorageValue)? @@ -707,7 +705,7 @@ async fn events_at_block( } } } - return Ok(out); + Ok(out) } pub async fn current_block_number( diff --git a/src/chain/tracker.rs b/src/chain/tracker.rs index b1607e4..3d483c2 100644 --- a/src/chain/tracker.rs +++ b/src/chain/tracker.rs @@ -29,7 +29,7 @@ use crate::{ utils::task_tracker::TaskTracker, }; -#[allow(clippy::too_many_lines)] +#[expect(clippy::too_many_lines)] pub fn start_chain_watch( chain: Chain, chain_tx: mpsc::Sender, @@ -53,14 +53,14 @@ pub fn start_chain_watch( break; } - let _ = rpc_update_tx.send(RpcInfo { + let _unused = rpc_update_tx.send(RpcInfo { chain_name: chain.name.clone(), rpc_url: endpoint.clone(), status: Health::Degraded, }).await; if let Ok(client) = WsClientBuilder::default().build(endpoint).await { - let _ = rpc_update_tx.send(RpcInfo { + let _unused = rpc_update_tx.send(RpcInfo { chain_name: chain.name.clone(), rpc_url: endpoint.clone(), status: Health::Ok, @@ -184,7 +184,7 @@ pub fn start_chain_watch( } } } else { - let _ = rpc_update_tx.send(RpcInfo { + let _unused = rpc_update_tx.send(RpcInfo { chain_name: chain.name.clone(), rpc_url: endpoint.clone(), status: Health::Critical, diff --git a/src/chain/utils.rs b/src/chain/utils.rs index f2d59ff..38f8cbd 100644 --- a/src/chain/utils.rs +++ b/src/chain/utils.rs @@ -92,7 +92,7 @@ pub fn construct_single_asset_transfer_call( index_transfer_in_methods, )?; - for field in method_selector.selected.fields_to_fill.iter_mut() { + for field in &mut method_selector.selected.fields_to_fill { if let Some(ref mut field_name) = field.field_name { match field_name.as_str() { "target" => { @@ -137,7 +137,7 @@ pub fn construct_single_asset_transfer_call( asset_transfer_constructor .to_account .to_owned(), - ) + ); } } } @@ -269,7 +269,7 @@ pub fn construct_batch_transaction( transaction_to_fill.call = construct_batch_call(metadata, call_set)?.0; // set era to mortal - for ext in transaction_to_fill.extensions.iter_mut() { + for ext in &mut transaction_to_fill.extensions { match ext.content { TypeContentToFill::Composite(ref mut fields) => { if fields.len() == 1 { @@ -301,7 +301,7 @@ pub fn construct_batch_transaction( transaction_to_fill.try_default_tip_assets_in_given_asset(&mut (), metadata, asset); } - for ext in transaction_to_fill.extensions.iter_mut() { + for ext in &mut transaction_to_fill.extensions { if ext.finalize().is_none() { println!("{ext:?}"); } @@ -374,10 +374,8 @@ pub fn construct_batch_call( .type_to_fill .content { - calls_sequence.content = call_set - .iter() - .map(|call| call.0.content.to_owned()) - .collect(); + calls_sequence.content = + call_set.iter().map(|call| call.0.content.clone()).collect(); } } } @@ -432,12 +430,12 @@ pub fn construct_single_balance_transfer_call( match variant_method.name.as_str() { "transfer_keep_alive" => { if !balance_transfer_constructor.is_clearing { - index_transfer_in_methods = Some(index_method) + index_transfer_in_methods = Some(index_method); } } "transfer_all" => { if balance_transfer_constructor.is_clearing { - index_transfer_in_methods = Some(index_method) + index_transfer_in_methods = Some(index_method); } } _ => {} @@ -455,7 +453,7 @@ pub fn construct_single_balance_transfer_call( index_transfer_in_methods, )?; - for field in method_selector.selected.fields_to_fill.iter_mut() { + for field in &mut method_selector.selected.fields_to_fill { if let Some(ref mut field_name) = field.field_name { match field_name.as_str() { "dest" => { @@ -500,7 +498,7 @@ pub fn construct_single_balance_transfer_call( balance_transfer_constructor .to_account .to_owned(), - ) + ); } } } @@ -647,7 +645,7 @@ pub fn was_balance_received_at_account( balance_transfer_event_fields: &[FieldData], ) -> bool { let mut found_receiver = None; - for field in balance_transfer_event_fields.iter() { + for field in balance_transfer_event_fields { if let Some(ref field_name) = field.field_name { if field_name == "to" { if let ParsedData::Id(ref account_id32) = field.data.data { @@ -683,9 +681,8 @@ pub fn asset_balance_query( .iter() .enumerate() { - match pallet.prefix.as_str() { - "Assets" => index_assets_in_pallet_selector = Some(index), - _ => {} + if pallet.prefix.as_str() == "Assets" { + index_assets_in_pallet_selector = Some(index); } if index_assets_in_pallet_selector.is_some() { break; @@ -784,9 +781,8 @@ pub fn system_balance_query( .iter() .enumerate() { - match pallet.prefix.as_str() { - "System" => index_system_in_pallet_selector = Some(index), - _ => {} + if pallet.prefix.as_str() == "System" { + index_system_in_pallet_selector = Some(index); } if index_system_in_pallet_selector.is_some() { break; @@ -833,7 +829,7 @@ pub fn system_balance_query( ref mut account_to_fill, )) = key_to_fill.content { - *account_to_fill = Some(*account_id) + *account_to_fill = Some(*account_id); } } } @@ -866,10 +862,10 @@ pub fn whole_key_u32_value( metadata_v15: &RuntimeMetadataV15, entered_data: u32, ) -> Result { - for pallet in metadata_v15.pallets.iter() { + for pallet in &metadata_v15.pallets { if let Some(storage) = &pallet.storage { if storage.prefix == prefix { - for entry in storage.entries.iter() { + for entry in &storage.entries { if entry.name == storage_name { match &entry.ty { StorageEntryType::Plain(_) => { @@ -1083,7 +1079,7 @@ pub fn pallet_index(metadata: &RuntimeMetadataV15, name: &str) -> Option { return Some(pallet.index); } } - return None; + None } pub fn storage_key(prefix: &str, storage_name: &str) -> String { diff --git a/src/database.rs b/src/database.rs index b10f935..514ee4f 100644 --- a/src/database.rs +++ b/src/database.rs @@ -13,11 +13,11 @@ use crate::{ }, Version, }, - error::{DbError, Error}, + error::DbError, utils::task_tracker::TaskTracker, }; use codec::{Decode, Encode}; -use names::{Generator, Name}; +use names::Generator; use std::time::SystemTime; use substrate_crypto_light::common::AccountId32; use tokio::sync::{mpsc, oneshot}; @@ -98,7 +98,7 @@ impl Database { DbRequest::ActiveOrderList(res) => { let _unused = res.send(Ok(orders .iter() - .filter_map(|a| a.ok()) + .filter_map(std::result::Result::ok) .filter_map(|(a, b)| { match (String::decode(&mut &a[..]), OrderInfo::decode(&mut &b[..])) { diff --git a/src/definitions.rs b/src/definitions.rs index 71793be..c7975ad 100644 --- a/src/definitions.rs +++ b/src/definitions.rs @@ -54,9 +54,8 @@ impl Sub for Balance { } impl Balance { - #[allow(dead_code)] // TODO: remove once populated pub fn format(&self, decimals: api_v2::Decimals) -> f64 { - #[allow(clippy::cast_precision_loss)] + #[expect(clippy::cast_precision_loss)] let float = **self as f64; float / decimal_exponent_product(decimals) @@ -65,7 +64,7 @@ impl Balance { pub fn parse(float: f64, decimals: api_v2::Decimals) -> Self { let parsed_float = (float * decimal_exponent_product(decimals)).round(); - #[allow(clippy::cast_possible_truncation, clippy::cast_sign_loss)] + #[expect(clippy::cast_possible_truncation, clippy::cast_sign_loss)] Self(parsed_float as _) } } diff --git a/src/error.rs b/src/error.rs index 077f035..514a2bb 100644 --- a/src/error.rs +++ b/src/error.rs @@ -1,6 +1,5 @@ use crate::{ arguments::{OLD_SEED, SEED}, - definitions::api_v2::OrderStatus, utils::task_tracker::TaskName, }; use codec::Error as ScaleError; @@ -114,7 +113,7 @@ pub enum SeedEnvError { pub enum TaskError {} #[derive(Debug, Error)] -#[allow(clippy::module_name_repetitions)] +#[expect(clippy::module_name_repetitions)] pub enum ChainError { // TODO: this should be prevented by typesafety #[error("asset ID is missing")] @@ -319,11 +318,8 @@ pub enum ChainError { } #[derive(Debug, Error)] -#[allow(clippy::module_name_repetitions)] +#[expect(clippy::module_name_repetitions)] pub enum DbError { - #[error("currency key isn't found")] - CurrencyKeyNotFound, - #[error("database engine isn't running")] DbEngineDown, @@ -359,7 +355,7 @@ pub enum DbError { } #[derive(Debug, Error)] -#[allow(clippy::module_name_repetitions)] +#[expect(clippy::module_name_repetitions)] pub enum OrderError { #[error("invoice amount is less than the existential deposit")] LessThanExistentialDeposit(f64), @@ -370,28 +366,19 @@ pub enum OrderError { #[error("order parameter is missing: {0:?}")] MissingParameter(String), - #[error("order parameter invalid: {0:?}")] - InvalidParameter(String), - #[error("internal error is occurred")] InternalError, } #[derive(Debug, Error)] -#[allow(clippy::module_name_repetitions)] +#[expect(clippy::module_name_repetitions)] pub enum ForceWithdrawalError { - #[error("order parameter is missing: {0:?}")] - MissingParameter(String), - #[error("order parameter is invalid: {0:?}")] InvalidParameter(String), - - #[error("withdrawal was failed: \"{0:?}\"")] - WithdrawalError(String), } #[derive(Debug, thiserror::Error)] -#[allow(clippy::module_name_repetitions)] +#[expect(clippy::module_name_repetitions)] pub enum ServerError { #[error("failed to bind the TCP listener to \"{0:?}\"")] TcpListenerBind(SocketAddr), @@ -401,18 +388,15 @@ pub enum ServerError { } #[derive(Debug, Error)] -#[allow(clippy::module_name_repetitions)] +#[expect(clippy::module_name_repetitions)] pub enum UtilError { #[error("...")] NotHex(NotHexError), } #[derive(Debug, Error)] -#[allow(clippy::module_name_repetitions)] +#[expect(clippy::module_name_repetitions)] pub enum SignerError { - #[error("failed to read {0:?}")] - Env(String), - #[error("signer is down")] SignerDown, diff --git a/src/handlers/order.rs b/src/handlers/order.rs index 2608d6e..31b0fcf 100644 --- a/src/handlers/order.rs +++ b/src/handlers/order.rs @@ -1,7 +1,5 @@ use crate::{ - definitions::api_v2::{ - InvalidParameter, OrderQuery, OrderResponse, OrderStatus, AMOUNT, CURRENCY, - }, + definitions::api_v2::{InvalidParameter, OrderQuery, OrderResponse, AMOUNT, CURRENCY}, error::{ForceWithdrawalError, OrderError}, state::State, }; @@ -58,10 +56,10 @@ pub async fn process_order( .await .map_err(|_| OrderError::InternalError) } else { - return state + state .order_status(&order_id) .await - .map_err(|_| OrderError::InternalError); + .map_err(|_| OrderError::InternalError) } } @@ -104,14 +102,6 @@ pub async fn order( }]), ) .into_response(), - OrderError::InvalidParameter(parameter) => ( - StatusCode::BAD_REQUEST, - Json([InvalidParameter { - parameter, - message: "parameter's format is invalid".into(), - }]), - ) - .into_response(), OrderError::InternalError => StatusCode::INTERNAL_SERVER_ERROR.into_response(), }, } @@ -134,17 +124,6 @@ pub async fn force_withdrawal( (StatusCode::CREATED, Json(order_status)).into_response() } Ok(OrderResponse::NotFound) => (StatusCode::NOT_FOUND, "Order not found").into_response(), - Err(ForceWithdrawalError::WithdrawalError(a)) => { - (StatusCode::BAD_REQUEST, Json(a)).into_response() - } - Err(ForceWithdrawalError::MissingParameter(parameter)) => ( - StatusCode::BAD_REQUEST, - Json([InvalidParameter { - parameter, - message: "parameter wasn't found".into(), - }]), - ) - .into_response(), Err(ForceWithdrawalError::InvalidParameter(parameter)) => ( StatusCode::BAD_REQUEST, Json([InvalidParameter { diff --git a/src/main.rs b/src/main.rs index a9333c6..e193b87 100644 --- a/src/main.rs +++ b/src/main.rs @@ -21,7 +21,6 @@ mod signer; mod state; mod utils; -use crate::error::ChainError; use arguments::{CliArgs, Config, SeedEnvVars, DATABASE_DEFAULT}; use chain::ChainManager; use database::ConfigWoChains; diff --git a/src/signer.rs b/src/signer.rs index ee6fb22..054d771 100644 --- a/src/signer.rs +++ b/src/signer.rs @@ -141,7 +141,7 @@ struct Sign { pub fn entropy_from_phrase(seed: &str) -> Result { let mut word_set = WordSet::new(); for word in seed.split(' ') { - word_set.add_word(&word, &InternalWordList)?; + word_set.add_word(word, &InternalWordList)?; } Ok(word_set.to_entropy()?) } diff --git a/src/state.rs b/src/state.rs index 3baf89c..db7107a 100644 --- a/src/state.rs +++ b/src/state.rs @@ -149,7 +149,7 @@ impl State { Err(e) => { tracing::error!( "Order was paid but this could not be recorded! {e:?}" - ) + ); } } } @@ -161,7 +161,7 @@ impl State { Err(e) => { tracing::error!( "Order was withdrawn but this could not be recorded! {e:?}" - ) + ); } } } @@ -169,9 +169,9 @@ impl State { match state.db.read_order(id.clone()).await { Ok(Some(order_info)) => { match state.chain_manager.reap(id.clone(), order_info.clone(), state.recipient).await { - Ok(_) => { + Ok(()) => { match state.db.mark_forced(id.clone()).await { - Ok(_) => { + Ok(()) => { tracing::info!("Order {id} successfully marked as force withdrawn"); } Err(e) => {