Fix clippy bits

This commit is contained in:
James Wilson
2025-12-16 16:06:02 +00:00
parent e9bb756605
commit c1d30da488
14 changed files with 47 additions and 29 deletions
+1 -1
View File
@@ -394,7 +394,7 @@ impl<T: RpcConfig> ChainHeadRpcMethods<T> {
.map(|item| ArchiveStorageQuery { .map(|item| ArchiveStorageQuery {
key: to_hex(item.key), key: to_hex(item.key),
query_type: item.query_type, query_type: item.query_type,
pagination_start_key: item.pagination_start_key.map(|k| to_hex(k)), pagination_start_key: item.pagination_start_key.map(to_hex),
}) })
.collect(); .collect();
+3 -3
View File
@@ -50,7 +50,7 @@ impl<T: Config> Backend<T> for ArchiveBackend<T> {
let queries = keys let queries = keys
.into_iter() .into_iter()
.map(|key| ArchiveStorageQuery { .map(|key| ArchiveStorageQuery {
key: key, key,
query_type: StorageQueryType::Value, query_type: StorageQueryType::Value,
pagination_start_key: None, pagination_start_key: None,
}) })
@@ -77,7 +77,7 @@ impl<T: Config> Backend<T> for ArchiveBackend<T> {
at: HashFor<T>, at: HashFor<T>,
) -> Result<StreamOfResults<Vec<u8>>, BackendError> { ) -> Result<StreamOfResults<Vec<u8>>, BackendError> {
let queries = std::iter::once(ArchiveStorageQuery { let queries = std::iter::once(ArchiveStorageQuery {
key: key, key,
// Just ask for the hash and then ignore it and return keys // Just ask for the hash and then ignore it and return keys
query_type: StorageQueryType::DescendantsHashes, query_type: StorageQueryType::DescendantsHashes,
pagination_start_key: None, pagination_start_key: None,
@@ -99,7 +99,7 @@ impl<T: Config> Backend<T> for ArchiveBackend<T> {
at: HashFor<T>, at: HashFor<T>,
) -> Result<StreamOfResults<StorageResponse>, BackendError> { ) -> Result<StreamOfResults<StorageResponse>, BackendError> {
let queries = std::iter::once(ArchiveStorageQuery { let queries = std::iter::once(ArchiveStorageQuery {
key: key, key,
query_type: StorageQueryType::DescendantsValues, query_type: StorageQueryType::DescendantsValues,
pagination_start_key: None, pagination_start_key: None,
}) })
+7 -1
View File
@@ -31,6 +31,12 @@ enum BackendChoice<V> {
UseDefault, UseDefault,
} }
impl<T: Config> Default for CombinedBackendBuilder<T> {
fn default() -> Self {
Self::new()
}
}
impl<T: Config> CombinedBackendBuilder<T> { impl<T: Config> CombinedBackendBuilder<T> {
/// Create a new [`CombinedBackendBuilder`]. /// Create a new [`CombinedBackendBuilder`].
pub fn new() -> Self { pub fn new() -> Self {
@@ -438,7 +444,7 @@ where
"None of the configured backends are capable of handling this request"; "None of the configured backends are capable of handling this request";
let mut err = BackendError::other(NO_AVAILABLE_BACKEND); let mut err = BackendError::other(NO_AVAILABLE_BACKEND);
for backend in backends.into_iter().filter_map(|b| *b) { for backend in backends.iter().filter_map(|b| *b) {
match f(backend).await { match f(backend).await {
Ok(res) => return Ok(res), Ok(res) => return Ok(res),
Err(e) => err = e, Err(e) => err = e,
+2 -2
View File
@@ -286,7 +286,7 @@ impl<T: Config> Backend<T> for LegacyBackend<T> {
let last_finalized_block_num = this let last_finalized_block_num = this
.block_header(last_finalized_block_ref.hash()) .block_header(last_finalized_block_ref.hash())
.await? .await?
.map(|h| h.number().into()); .map(|h| h.number());
// Fill in any missing blocks, because the backend may not emit every finalized block; just the latest ones which // Fill in any missing blocks, because the backend may not emit every finalized block; just the latest ones which
// are finalized each time. // are finalized each time.
@@ -408,7 +408,7 @@ where
}; };
// We want all previous details up to, but not including this current block num. // We want all previous details up to, but not including this current block num.
let end_block_num = header.number().into(); let end_block_num = header.number();
// This is one after the last block we returned details for last time. // This is one after the last block we returned details for last time.
let start_block_num = last_block_num.map(|n| n + 1).unwrap_or(end_block_num); let start_block_num = last_block_num.map(|n| n + 1).unwrap_or(end_block_num);
+1 -1
View File
@@ -120,7 +120,7 @@ impl<T: Config> OnlineClient<T> {
inner: Arc::new(OnlineClientInner { inner: Arc::new(OnlineClientInner {
config, config,
genesis_hash, genesis_hash,
backend: backend.into(), backend,
}), }),
}) })
} }
+6
View File
@@ -81,6 +81,12 @@ impl PolkadotConfigBuilder {
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct PolkadotConfig(SubstrateConfig); pub struct PolkadotConfig(SubstrateConfig);
impl Default for PolkadotConfig {
fn default() -> Self {
Self::new()
}
}
impl PolkadotConfig { impl PolkadotConfig {
/// Create a new, default, [`PolkadotConfig`]. /// Create a new, default, [`PolkadotConfig`].
pub fn new() -> Self { pub fn new() -> Self {
+7 -1
View File
@@ -135,6 +135,12 @@ struct SubstrateConfigInner {
metadata_for_spec_version: Mutex<HashMap<u32, ArcMetadata>>, metadata_for_spec_version: Mutex<HashMap<u32, ArcMetadata>>,
} }
impl Default for SubstrateConfig {
fn default() -> Self {
Self::new()
}
}
impl SubstrateConfig { impl SubstrateConfig {
/// Create a new, default, [`SubstrateConfig`]. This does not /// Create a new, default, [`SubstrateConfig`]. This does not
/// support working with historic (pre-V14) types. If you want this, /// support working with historic (pre-V14) types. If you want this,
@@ -297,7 +303,7 @@ where
SubstrateHeader<H>: Encode + Decode, SubstrateHeader<H>: Encode + Decode,
{ {
fn number(&self) -> u64 { fn number(&self) -> u64 {
self.number.into() self.number
} }
} }
+3 -3
View File
@@ -134,7 +134,7 @@ impl<'atblock, T: Config, C: OfflineClientAtBlockT<T>> Extrinsics<'atblock, T, C
} }
Ok(Extrinsic { Ok(Extrinsic {
client: client, client,
index: extrinsic_index, index: extrinsic_index,
info: Arc::new(info), info: Arc::new(info),
extrinsics: Arc::clone(&all_extrinsic_bytes), extrinsics: Arc::clone(&all_extrinsic_bytes),
@@ -306,7 +306,7 @@ where
self.metadata.types(), self.metadata.types(),
) )
.map_err(|e| ExtrinsicError::CannotDecodeIntoRootExtrinsic { .map_err(|e| ExtrinsicError::CannotDecodeIntoRootExtrinsic {
extrinsic_index: self.index as usize, extrinsic_index: self.index,
error: e, error: e,
})?; })?;
@@ -347,7 +347,7 @@ where
let decoded = let decoded =
E::decode_as_fields(bytes, &mut fields, self.metadata.types()).map_err(|e| { E::decode_as_fields(bytes, &mut fields, self.metadata.types()).map_err(|e| {
ExtrinsicError::CannotDecodeFields { ExtrinsicError::CannotDecodeFields {
extrinsic_index: self.index as usize, extrinsic_index: self.index,
error: e, error: e,
} }
})?; })?;
+1 -1
View File
@@ -211,7 +211,7 @@ where
pub fn entry( pub fn entry(
&self, &self,
) -> Result<StorageEntry<'atblock, T, Client, address::DynamicAddress>, StorageError> { ) -> Result<StorageEntry<'atblock, T, Client, address::DynamicAddress>, StorageError> {
let addr = address::dynamic(self.pallet_name.to_owned(), self.entry_name.to_owned()); let addr = address::dynamic(&*self.pallet_name, &*self.entry_name);
StorageEntry::new(self.client, addr) StorageEntry::new(self.client, addr)
} }
} }
+1 -1
View File
@@ -587,7 +587,7 @@ impl<'atblock, T: Config, Client: OfflineClientAtBlockT<T>>
// "is general" + transaction protocol version (5) // "is general" + transaction protocol version (5)
(0b01000000 + 5u8).encode_to(&mut encoded_inner); (0b01000000 + 5u8).encode_to(&mut encoded_inner);
// Encode versions for the transaction extensions // Encode versions for the transaction extensions
(tx_extensions_version as u8).encode_to(&mut encoded_inner); tx_extensions_version.encode_to(&mut encoded_inner);
// Encode the actual transaction extensions values // Encode the actual transaction extensions values
self.additional_and_extra_params self.additional_and_extra_params
.encode_value_to(&mut encoded_inner); .encode_value_to(&mut encoded_inner);
+1 -1
View File
@@ -206,7 +206,7 @@ pub fn dynamic<CallData>(
call_name: impl Into<String>, call_name: impl Into<String>,
call_data: CallData, call_data: CallData,
) -> DynamicPayload<CallData> { ) -> DynamicPayload<CallData> {
StaticPayload::new(pallet_name, call_name, call_data.into()) StaticPayload::new(pallet_name, call_name, call_data)
} }
#[cfg(test)] #[cfg(test)]
@@ -323,7 +323,7 @@ impl<'atblock, T: Config, C: OnlineClientAtBlockT<T>> TransactionInBlock<'atbloc
.iter() .iter()
.position(|ext| { .position(|ext| {
use crate::config::Hasher; use crate::config::Hasher;
let hash = hasher.hash(&ext); let hash = hasher.hash(ext);
hash == self.ext_hash hash == self.ext_hash
}) })
// If we successfully obtain the block hash we think contains our // If we successfully obtain the block hash we think contains our
+2 -2
View File
@@ -103,9 +103,9 @@ where
{ {
/// Execute a raw View function API call. This returns the raw bytes representing the result /// Execute a raw View function API call. This returns the raw bytes representing the result
/// of this call. The caller is responsible for decoding the result. /// of this call. The caller is responsible for decoding the result.
pub async fn call_raw<'a>( pub async fn call_raw(
&self, &self,
call_parameters: Option<&'a [u8]>, call_parameters: Option<&[u8]>,
) -> Result<Vec<u8>, ViewFunctionError> { ) -> Result<Vec<u8>, ViewFunctionError> {
let client = &self.client; let client = &self.client;
let block_hash = client.block_hash(); let block_hash = client.block_hash();
+11 -11
View File
@@ -58,7 +58,7 @@ impl From<[u8; 32]> for AccountId32 {
impl AccountId32 { impl AccountId32 {
// Return the ss58-check string for this key. Adapted from `sp_core::crypto`. We need this to // Return the ss58-check string for this key. Adapted from `sp_core::crypto`. We need this to
// serialize our account appropriately but otherwise don't care. // serialize our account appropriately but otherwise don't care.
fn to_ss58check(&self) -> String { fn ss58(&self) -> String {
// For serializing to a string to obtain the account nonce, we use the default substrate // For serializing to a string to obtain the account nonce, we use the default substrate
// prefix (since we have no way to otherwise pick one). It doesn't really matter, since when // prefix (since we have no way to otherwise pick one). It doesn't really matter, since when
// it's deserialized back in system_accountNextIndex, we ignore this (so long as it's valid). // it's deserialized back in system_accountNextIndex, we ignore this (so long as it's valid).
@@ -78,7 +78,7 @@ impl AccountId32 {
// This isn't strictly needed, but to give our AccountId32 a little more usefulness, we also // This isn't strictly needed, but to give our AccountId32 a little more usefulness, we also
// implement the logic needed to decode an AccountId32 from an SS58 encoded string. This is exposed // implement the logic needed to decode an AccountId32 from an SS58 encoded string. This is exposed
// via a `FromStr` impl. // via a `FromStr` impl.
fn from_ss58check(s: &str) -> Result<Self, FromSs58Error> { fn from_ss58(s: &str) -> Result<Self, FromSs58Error> {
const CHECKSUM_LEN: usize = 2; const CHECKSUM_LEN: usize = 2;
let body_len = 32; let body_len = 32;
@@ -123,7 +123,7 @@ pub enum FromSs58Error {
InvalidPrefix, InvalidPrefix,
} }
// We do this just to get a checksum to help verify the validity of the address in to_ss58check // We do this just to get a checksum to help verify the validity of the address in ss58
fn ss58hash(data: &[u8]) -> Vec<u8> { fn ss58hash(data: &[u8]) -> Vec<u8> {
use blake2::{Blake2b512, Digest}; use blake2::{Blake2b512, Digest};
const PREFIX: &[u8] = b"SS58PRE"; const PREFIX: &[u8] = b"SS58PRE";
@@ -138,7 +138,7 @@ impl Serialize for AccountId32 {
where where
S: serde::Serializer, S: serde::Serializer,
{ {
serializer.serialize_str(&self.to_ss58check()) serializer.serialize_str(&self.ss58())
} }
} }
@@ -147,21 +147,21 @@ impl<'de> Deserialize<'de> for AccountId32 {
where where
D: serde::Deserializer<'de>, D: serde::Deserializer<'de>,
{ {
AccountId32::from_ss58check(&String::deserialize(deserializer)?) AccountId32::from_ss58(&String::deserialize(deserializer)?)
.map_err(|e| serde::de::Error::custom(format!("{e:?}"))) .map_err(|e| serde::de::Error::custom(format!("{e:?}")))
} }
} }
impl core::fmt::Display for AccountId32 { impl core::fmt::Display for AccountId32 {
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
write!(f, "{}", self.to_ss58check()) write!(f, "{}", self.ss58())
} }
} }
impl core::str::FromStr for AccountId32 { impl core::str::FromStr for AccountId32 {
type Err = FromSs58Error; type Err = FromSs58Error;
fn from_str(s: &str) -> Result<Self, Self::Err> { fn from_str(s: &str) -> Result<Self, Self::Err> {
AccountId32::from_ss58check(s) AccountId32::from_ss58(s)
} }
} }
@@ -180,16 +180,16 @@ mod test {
let local_account = AccountId32(substrate_account.clone().into()); let local_account = AccountId32(substrate_account.clone().into());
// Both should encode to ss58 the same way: // Both should encode to ss58 the same way:
let substrate_ss58 = substrate_account.to_ss58check(); let substrate_ss58 = substrate_account.ss58();
assert_eq!(substrate_ss58, local_account.to_ss58check()); assert_eq!(substrate_ss58, local_account.ss58());
// Both should decode from ss58 back to the same: // Both should decode from ss58 back to the same:
assert_eq!( assert_eq!(
sp_core::crypto::AccountId32::from_ss58check(&substrate_ss58).unwrap(), sp_core::crypto::AccountId32::from_ss58(&substrate_ss58).unwrap(),
substrate_account substrate_account
); );
assert_eq!( assert_eq!(
AccountId32::from_ss58check(&substrate_ss58).unwrap(), AccountId32::from_ss58(&substrate_ss58).unwrap(),
local_account local_account
); );
} }