Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: clippy auto fix #128

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/arguments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, String>,
}

Expand Down
24 changes: 14 additions & 10 deletions src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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()));
}
}
Expand Down Expand Up @@ -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(());
Expand All @@ -154,7 +158,7 @@ impl ChainManager {
status: *status,
}
}).collect();
let _ = res_tx.send(connected_rpcs);
let _unused = res_tx.send(connected_rpcs);
}
}
}
Expand Down Expand Up @@ -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;
()
();
}
}
8 changes: 4 additions & 4 deletions src/chain/definitions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Self, crate::error::ChainError> {
let block_hash_raw = unhex(&s, NotHexError::BlockHash)?;
let block_hash_raw = unhex(s, NotHexError::BlockHash)?;
Ok(BlockHash(H256(
block_hash_raw
.try_into()
Expand Down Expand Up @@ -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,
Expand All @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion src/chain/payout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
Expand Down
52 changes: 25 additions & 27 deletions src/chain/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ pub async fn genesis_hash(client: &WsClient) -> Result<BlockHash, ChainError> {
.map_err(ChainError::Client)?;
match genesis_hash_request {
Value::String(x) => BlockHash::from_str(&x),
_ => return Err(ChainError::GenesisHashFormat),
_ => Err(ChainError::GenesisHashFormat),
}
}

Expand All @@ -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),
}
}

Expand Down Expand Up @@ -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
Expand All @@ -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),
}
}

Expand All @@ -250,7 +248,7 @@ pub async fn next_block(
client: &WsClient,
blocks: &mut Subscription<BlockHead>,
) -> Result<BlockHash, ChainError> {
block_hash(&client, Some(next_block_number(blocks).await?)).await
block_hash(client, Some(next_block_number(blocks).await?)).await
}

#[derive(Deserialize, Debug)]
Expand Down Expand Up @@ -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);
}
Expand All @@ -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 {
Expand Down Expand Up @@ -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) =
Expand Down Expand Up @@ -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
{
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -622,10 +620,10 @@ pub async fn transfer_events(
block: &BlockHash,
metadata_v15: &RuntimeMetadataV15,
) -> Result<Vec<Event>, 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,
Expand All @@ -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)?
Expand Down Expand Up @@ -707,7 +705,7 @@ async fn events_at_block(
}
}
}
return Ok(out);
Ok(out)
}

pub async fn current_block_number(
Expand Down
8 changes: 4 additions & 4 deletions src/chain/tracker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ChainTrackerRequest>,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
Loading
Loading