diff --git a/Cargo.toml b/Cargo.toml index cb11bf84..137915ef 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -54,7 +54,6 @@ no_unknown_fields = [ [workspace.lints] rust.missing_debug_implementations = "warn" -rust.unreachable_pub = "warn" rust.unused_must_use = "deny" rust.rust_2018_idioms = { level = "deny", priority = -1 } rustdoc.all = "warn" diff --git a/starknet-accounts/tests/single_owner_account.rs b/starknet-accounts/tests/single_owner_account.rs index c779c491..f836a7c4 100644 --- a/starknet-accounts/tests/single_owner_account.rs +++ b/starknet-accounts/tests/single_owner_account.rs @@ -31,6 +31,7 @@ fn create_sequencer_client() -> SequencerGatewayProvider { } fn create_jsonrpc_client() -> JsonRpcClient { + #[allow(clippy::or_fun_call)] let rpc_url = std::env::var("STARKNET_RPC") .unwrap_or("https://juno.rpc.sepolia.starknet.rs/rpc/v0_7".into()); JsonRpcClient::new(HttpTransport::new(url::Url::parse(&rpc_url).unwrap())) diff --git a/starknet-contract/Cargo.toml b/starknet-contract/Cargo.toml index 992069df..b4da496e 100644 --- a/starknet-contract/Cargo.toml +++ b/starknet-contract/Cargo.toml @@ -27,3 +27,6 @@ rand = { version = "0.8.5", features=["std_rng"] } starknet-signers = { version = "0.9.0", path = "../starknet-signers" } tokio = { version = "1.27.0", features = ["full"] } url = "2.3.1" + +[lints] +workspace = true diff --git a/starknet-core/Cargo.toml b/starknet-core/Cargo.toml index f3f7862d..27aea9e1 100644 --- a/starknet-core/Cargo.toml +++ b/starknet-core/Cargo.toml @@ -49,3 +49,6 @@ harness = false [[bench]] name = "sierra_class_hash" harness = false + +[lints] +workspace = true diff --git a/starknet-core/src/chain_id.rs b/starknet-core/src/chain_id.rs index cbb430fa..91331d6f 100644 --- a/starknet-core/src/chain_id.rs +++ b/starknet-core/src/chain_id.rs @@ -46,7 +46,6 @@ mod test { ("SN_GOERLI2", TESTNET2), ("SN_SEPOLIA", SEPOLIA), ] - .into_iter() { assert_eq!(cairo_short_string_to_felt(text).unwrap(), felt); } diff --git a/starknet-core/src/crypto.rs b/starknet-core/src/crypto.rs index 634faab9..0c9d1c45 100644 --- a/starknet-core/src/crypto.rs +++ b/starknet-core/src/crypto.rs @@ -49,7 +49,7 @@ pub use errors::{EcdsaSignError, EcdsaVerifyError}; pub fn compute_hash_on_elements(data: &[Felt]) -> Felt { let mut current_hash = Felt::ZERO; - for item in data.iter() { + for item in data { current_hash = pedersen_hash(¤t_hash, item); } diff --git a/starknet-core/src/serde/byte_array.rs b/starknet-core/src/serde/byte_array.rs index 9d171396..0d2bb46e 100644 --- a/starknet-core/src/serde/byte_array.rs +++ b/starknet-core/src/serde/byte_array.rs @@ -24,7 +24,7 @@ pub mod base64 { impl<'de> Visitor<'de> for Base64Visitor { type Value = Vec; - fn expecting(&self, formatter: &mut Formatter) -> alloc::fmt::Result { + fn expecting(&self, formatter: &mut Formatter<'_>) -> alloc::fmt::Result { write!(formatter, "string") } diff --git a/starknet-core/src/serde/num_hex.rs b/starknet-core/src/serde/num_hex.rs index 985b9053..68509c8a 100644 --- a/starknet-core/src/serde/num_hex.rs +++ b/starknet-core/src/serde/num_hex.rs @@ -22,7 +22,7 @@ pub mod u64 { impl<'de> Visitor<'de> for NumHexVisitor { type Value = u64; - fn expecting(&self, formatter: &mut Formatter) -> alloc::fmt::Result { + fn expecting(&self, formatter: &mut Formatter<'_>) -> alloc::fmt::Result { write!(formatter, "string") } diff --git a/starknet-core/src/serde/unsigned_field_element.rs b/starknet-core/src/serde/unsigned_field_element.rs index 38317ff9..b03c5104 100644 --- a/starknet-core/src/serde/unsigned_field_element.rs +++ b/starknet-core/src/serde/unsigned_field_element.rs @@ -8,10 +8,13 @@ use serde_with::{DeserializeAs, SerializeAs}; use starknet_types_core::felt::Felt; +#[derive(Debug)] pub struct UfeHex; +#[derive(Debug)] pub struct UfeHexOption; +#[derive(Debug)] pub struct UfePendingBlockHash; struct UfeHexVisitor; @@ -39,7 +42,7 @@ impl<'de> DeserializeAs<'de, Felt> for UfeHex { impl<'de> Visitor<'de> for UfeHexVisitor { type Value = Felt; - fn expecting(&self, formatter: &mut Formatter) -> alloc::fmt::Result { + fn expecting(&self, formatter: &mut Formatter<'_>) -> alloc::fmt::Result { write!(formatter, "string") } @@ -75,7 +78,7 @@ impl<'de> DeserializeAs<'de, Option> for UfeHexOption { impl<'de> Visitor<'de> for UfeHexOptionVisitor { type Value = Option; - fn expecting(&self, formatter: &mut Formatter) -> alloc::fmt::Result { + fn expecting(&self, formatter: &mut Formatter<'_>) -> alloc::fmt::Result { write!(formatter, "string") } @@ -118,7 +121,7 @@ impl<'de> DeserializeAs<'de, Option> for UfePendingBlockHash { impl<'de> Visitor<'de> for UfePendingBlockHashVisitor { type Value = Option; - fn expecting(&self, formatter: &mut Formatter) -> alloc::fmt::Result { + fn expecting(&self, formatter: &mut Formatter<'_>) -> alloc::fmt::Result { write!(formatter, "string") } diff --git a/starknet-core/src/types/codegen.rs b/starknet-core/src/types/codegen.rs index 46e11560..3c79d4a1 100644 --- a/starknet-core/src/types/codegen.rs +++ b/starknet-core/src/types/codegen.rs @@ -389,7 +389,7 @@ pub struct ComputationResources { /// The number of unused memory cells (each cell is roughly equivalent to a step) #[serde(skip_serializing_if = "Option::is_none")] pub memory_holes: Option, - /// The number of range_check builtin instances + /// The number of `range_check` builtin instances #[serde(skip_serializing_if = "Option::is_none")] pub range_check_builtin_applications: Option, /// The number of pedersen builtin instances @@ -398,7 +398,7 @@ pub struct ComputationResources { /// The number of poseidon builtin instances #[serde(skip_serializing_if = "Option::is_none")] pub poseidon_builtin_applications: Option, - /// The number of ec_op builtin instances + /// The number of `ec_op` builtin instances #[serde(skip_serializing_if = "Option::is_none")] pub ec_op_builtin_applications: Option, /// The number of ecdsa builtin instances @@ -1568,7 +1568,7 @@ pub struct SimulatedTransaction { /// Flags that indicate how to simulate a given transaction. By default, the sequencer behavior is /// replicated locally (enough funds are expected to be in the account, and fee will be deducted /// from the balance before the simulation of the next transaction). To skip the fee charge, use the -/// skip_fee_charge flag. +/// `skip_fee_charge` flag. #[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)] pub enum SimulationFlag { #[serde(rename = "SKIP_VALIDATE")] @@ -1618,7 +1618,7 @@ pub enum StarknetError { InvalidTransactionNonce, /// Max fee is smaller than the minimal transaction cost (validation plus fee transfer) InsufficientMaxFee, - /// Account balance is smaller than the transaction's max_fee + /// Account balance is smaller than the transaction's `max_fee` InsufficientAccountBalance, /// Account validation failed ValidationFailure(String), @@ -1679,7 +1679,7 @@ impl core::fmt::Display for StarknetError { } impl StarknetError { - pub fn message(&self) -> &'static str { + pub const fn message(&self) -> &'static str { match self { Self::FailedToReceiveTransaction => "Failed to write transaction", Self::ContractNotFound => "Contract not found", @@ -1848,54 +1848,54 @@ pub struct TransactionWithReceipt { pub receipt: TransactionReceipt, } -/// Request for method starknet_addDeclareTransaction +/// Request for method `starknet_addDeclareTransaction` #[derive(Debug, Clone, PartialEq, Eq)] pub struct AddDeclareTransactionRequest { /// Declare transaction required to declare a new class on Starknet pub declare_transaction: BroadcastedDeclareTransaction, } -/// Reference version of [AddDeclareTransactionRequest]. +/// Reference version of [`AddDeclareTransactionRequest`]. #[derive(Debug, Clone, PartialEq, Eq)] pub struct AddDeclareTransactionRequestRef<'a> { pub declare_transaction: &'a BroadcastedDeclareTransaction, } -/// Request for method starknet_addDeployAccountTransaction +/// Request for method `starknet_addDeployAccountTransaction` #[derive(Debug, Clone, PartialEq, Eq)] pub struct AddDeployAccountTransactionRequest { /// The deploy account transaction pub deploy_account_transaction: BroadcastedDeployAccountTransaction, } -/// Reference version of [AddDeployAccountTransactionRequest]. +/// Reference version of [`AddDeployAccountTransactionRequest`]. #[derive(Debug, Clone, PartialEq, Eq)] pub struct AddDeployAccountTransactionRequestRef<'a> { pub deploy_account_transaction: &'a BroadcastedDeployAccountTransaction, } -/// Request for method starknet_addInvokeTransaction +/// Request for method `starknet_addInvokeTransaction` #[derive(Debug, Clone, PartialEq, Eq)] pub struct AddInvokeTransactionRequest { /// The information needed to invoke the function (or account, for version 1 transactions) pub invoke_transaction: BroadcastedInvokeTransaction, } -/// Reference version of [AddInvokeTransactionRequest]. +/// Reference version of [`AddInvokeTransactionRequest`]. #[derive(Debug, Clone, PartialEq, Eq)] pub struct AddInvokeTransactionRequestRef<'a> { pub invoke_transaction: &'a BroadcastedInvokeTransaction, } -/// Request for method starknet_blockHashAndNumber +/// Request for method `starknet_blockHashAndNumber` #[derive(Debug, Clone, PartialEq, Eq)] pub struct BlockHashAndNumberRequest; -/// Request for method starknet_blockNumber +/// Request for method `starknet_blockNumber` #[derive(Debug, Clone, PartialEq, Eq)] pub struct BlockNumberRequest; -/// Request for method starknet_call +/// Request for method `starknet_call` #[derive(Debug, Clone, PartialEq, Eq)] pub struct CallRequest { pub request: FunctionCall, @@ -1904,18 +1904,18 @@ pub struct CallRequest { pub block_id: BlockId, } -/// Reference version of [CallRequest]. +/// Reference version of [`CallRequest`]. #[derive(Debug, Clone, PartialEq, Eq)] pub struct CallRequestRef<'a> { pub request: &'a FunctionCall, pub block_id: &'a BlockId, } -/// Request for method starknet_chainId +/// Request for method `starknet_chainId` #[derive(Debug, Clone, PartialEq, Eq)] pub struct ChainIdRequest; -/// Request for method starknet_estimateFee +/// Request for method `starknet_estimateFee` #[derive(Debug, Clone, PartialEq, Eq)] pub struct EstimateFeeRequest { pub request: Vec, @@ -1926,7 +1926,7 @@ pub struct EstimateFeeRequest { pub block_id: BlockId, } -/// Reference version of [EstimateFeeRequest]. +/// Reference version of [`EstimateFeeRequest`]. #[derive(Debug, Clone, PartialEq, Eq)] pub struct EstimateFeeRequestRef<'a> { pub request: &'a [BroadcastedTransaction], @@ -1934,7 +1934,7 @@ pub struct EstimateFeeRequestRef<'a> { pub block_id: &'a BlockId, } -/// Request for method starknet_estimateMessageFee +/// Request for method `starknet_estimateMessageFee` #[derive(Debug, Clone, PartialEq, Eq)] pub struct EstimateMessageFeeRequest { /// the message's parameters @@ -1944,66 +1944,66 @@ pub struct EstimateMessageFeeRequest { pub block_id: BlockId, } -/// Reference version of [EstimateMessageFeeRequest]. +/// Reference version of [`EstimateMessageFeeRequest`]. #[derive(Debug, Clone, PartialEq, Eq)] pub struct EstimateMessageFeeRequestRef<'a> { pub message: &'a MsgFromL1, pub block_id: &'a BlockId, } -/// Request for method starknet_getBlockTransactionCount +/// Request for method `starknet_getBlockTransactionCount` #[derive(Debug, Clone, PartialEq, Eq)] pub struct GetBlockTransactionCountRequest { /// The hash of the requested block, or number (height) of the requested block, or a block tag pub block_id: BlockId, } -/// Reference version of [GetBlockTransactionCountRequest]. +/// Reference version of [`GetBlockTransactionCountRequest`]. #[derive(Debug, Clone, PartialEq, Eq)] pub struct GetBlockTransactionCountRequestRef<'a> { pub block_id: &'a BlockId, } -/// Request for method starknet_getBlockWithReceipts +/// Request for method `starknet_getBlockWithReceipts` #[derive(Debug, Clone, PartialEq, Eq)] pub struct GetBlockWithReceiptsRequest { /// The hash of the requested block, or number (height) of the requested block, or a block tag pub block_id: BlockId, } -/// Reference version of [GetBlockWithReceiptsRequest]. +/// Reference version of [`GetBlockWithReceiptsRequest`]. #[derive(Debug, Clone, PartialEq, Eq)] pub struct GetBlockWithReceiptsRequestRef<'a> { pub block_id: &'a BlockId, } -/// Request for method starknet_getBlockWithTxHashes +/// Request for method `starknet_getBlockWithTxHashes` #[derive(Debug, Clone, PartialEq, Eq)] pub struct GetBlockWithTxHashesRequest { /// The hash of the requested block, or number (height) of the requested block, or a block tag pub block_id: BlockId, } -/// Reference version of [GetBlockWithTxHashesRequest]. +/// Reference version of [`GetBlockWithTxHashesRequest`]. #[derive(Debug, Clone, PartialEq, Eq)] pub struct GetBlockWithTxHashesRequestRef<'a> { pub block_id: &'a BlockId, } -/// Request for method starknet_getBlockWithTxs +/// Request for method `starknet_getBlockWithTxs` #[derive(Debug, Clone, PartialEq, Eq)] pub struct GetBlockWithTxsRequest { /// The hash of the requested block, or number (height) of the requested block, or a block tag pub block_id: BlockId, } -/// Reference version of [GetBlockWithTxsRequest]. +/// Reference version of [`GetBlockWithTxsRequest`]. #[derive(Debug, Clone, PartialEq, Eq)] pub struct GetBlockWithTxsRequestRef<'a> { pub block_id: &'a BlockId, } -/// Request for method starknet_getClassAt +/// Request for method `starknet_getClassAt` #[derive(Debug, Clone, PartialEq, Eq)] pub struct GetClassAtRequest { /// The hash of the requested block, or number (height) of the requested block, or a block tag @@ -2012,14 +2012,14 @@ pub struct GetClassAtRequest { pub contract_address: Felt, } -/// Reference version of [GetClassAtRequest]. +/// Reference version of [`GetClassAtRequest`]. #[derive(Debug, Clone, PartialEq, Eq)] pub struct GetClassAtRequestRef<'a> { pub block_id: &'a BlockId, pub contract_address: &'a Felt, } -/// Request for method starknet_getClassHashAt +/// Request for method `starknet_getClassHashAt` #[derive(Debug, Clone, PartialEq, Eq)] pub struct GetClassHashAtRequest { /// The hash of the requested block, or number (height) of the requested block, or a block tag @@ -2028,14 +2028,14 @@ pub struct GetClassHashAtRequest { pub contract_address: Felt, } -/// Reference version of [GetClassHashAtRequest]. +/// Reference version of [`GetClassHashAtRequest`]. #[derive(Debug, Clone, PartialEq, Eq)] pub struct GetClassHashAtRequestRef<'a> { pub block_id: &'a BlockId, pub contract_address: &'a Felt, } -/// Request for method starknet_getClass +/// Request for method `starknet_getClass` #[derive(Debug, Clone, PartialEq, Eq)] pub struct GetClassRequest { /// The hash of the requested block, or number (height) of the requested block, or a block tag @@ -2044,26 +2044,26 @@ pub struct GetClassRequest { pub class_hash: Felt, } -/// Reference version of [GetClassRequest]. +/// Reference version of [`GetClassRequest`]. #[derive(Debug, Clone, PartialEq, Eq)] pub struct GetClassRequestRef<'a> { pub block_id: &'a BlockId, pub class_hash: &'a Felt, } -/// Request for method starknet_getEvents +/// Request for method `starknet_getEvents` #[derive(Debug, Clone, PartialEq, Eq)] pub struct GetEventsRequest { pub filter: EventFilterWithPage, } -/// Reference version of [GetEventsRequest]. +/// Reference version of [`GetEventsRequest`]. #[derive(Debug, Clone, PartialEq, Eq)] pub struct GetEventsRequestRef<'a> { pub filter: &'a EventFilterWithPage, } -/// Request for method starknet_getNonce +/// Request for method `starknet_getNonce` #[derive(Debug, Clone, PartialEq, Eq)] pub struct GetNonceRequest { /// The hash of the requested block, or number (height) of the requested block, or a block tag @@ -2072,27 +2072,27 @@ pub struct GetNonceRequest { pub contract_address: Felt, } -/// Reference version of [GetNonceRequest]. +/// Reference version of [`GetNonceRequest`]. #[derive(Debug, Clone, PartialEq, Eq)] pub struct GetNonceRequestRef<'a> { pub block_id: &'a BlockId, pub contract_address: &'a Felt, } -/// Request for method starknet_getStateUpdate +/// Request for method `starknet_getStateUpdate` #[derive(Debug, Clone, PartialEq, Eq)] pub struct GetStateUpdateRequest { /// The hash of the requested block, or number (height) of the requested block, or a block tag pub block_id: BlockId, } -/// Reference version of [GetStateUpdateRequest]. +/// Reference version of [`GetStateUpdateRequest`]. #[derive(Debug, Clone, PartialEq, Eq)] pub struct GetStateUpdateRequestRef<'a> { pub block_id: &'a BlockId, } -/// Request for method starknet_getStorageAt +/// Request for method `starknet_getStorageAt` #[derive(Debug, Clone, PartialEq, Eq)] pub struct GetStorageAtRequest { /// The address of the contract to read from @@ -2103,7 +2103,7 @@ pub struct GetStorageAtRequest { pub block_id: BlockId, } -/// Reference version of [GetStorageAtRequest]. +/// Reference version of [`GetStorageAtRequest`]. #[derive(Debug, Clone, PartialEq, Eq)] pub struct GetStorageAtRequestRef<'a> { pub contract_address: &'a Felt, @@ -2111,7 +2111,7 @@ pub struct GetStorageAtRequestRef<'a> { pub block_id: &'a BlockId, } -/// Request for method starknet_getTransactionByBlockIdAndIndex +/// Request for method `starknet_getTransactionByBlockIdAndIndex` #[derive(Debug, Clone, PartialEq, Eq)] pub struct GetTransactionByBlockIdAndIndexRequest { /// The hash of the requested block, or number (height) of the requested block, or a block tag @@ -2119,50 +2119,50 @@ pub struct GetTransactionByBlockIdAndIndexRequest { pub index: u64, } -/// Reference version of [GetTransactionByBlockIdAndIndexRequest]. +/// Reference version of [`GetTransactionByBlockIdAndIndexRequest`]. #[derive(Debug, Clone, PartialEq, Eq)] pub struct GetTransactionByBlockIdAndIndexRequestRef<'a> { pub block_id: &'a BlockId, pub index: &'a u64, } -/// Request for method starknet_getTransactionByHash +/// Request for method `starknet_getTransactionByHash` #[derive(Debug, Clone, PartialEq, Eq)] pub struct GetTransactionByHashRequest { pub transaction_hash: Felt, } -/// Reference version of [GetTransactionByHashRequest]. +/// Reference version of [`GetTransactionByHashRequest`]. #[derive(Debug, Clone, PartialEq, Eq)] pub struct GetTransactionByHashRequestRef<'a> { pub transaction_hash: &'a Felt, } -/// Request for method starknet_getTransactionReceipt +/// Request for method `starknet_getTransactionReceipt` #[derive(Debug, Clone, PartialEq, Eq)] pub struct GetTransactionReceiptRequest { pub transaction_hash: Felt, } -/// Reference version of [GetTransactionReceiptRequest]. +/// Reference version of [`GetTransactionReceiptRequest`]. #[derive(Debug, Clone, PartialEq, Eq)] pub struct GetTransactionReceiptRequestRef<'a> { pub transaction_hash: &'a Felt, } -/// Request for method starknet_getTransactionStatus +/// Request for method `starknet_getTransactionStatus` #[derive(Debug, Clone, PartialEq, Eq)] pub struct GetTransactionStatusRequest { pub transaction_hash: Felt, } -/// Reference version of [GetTransactionStatusRequest]. +/// Reference version of [`GetTransactionStatusRequest`]. #[derive(Debug, Clone, PartialEq, Eq)] pub struct GetTransactionStatusRequestRef<'a> { pub transaction_hash: &'a Felt, } -/// Request for method starknet_simulateTransactions +/// Request for method `starknet_simulateTransactions` #[derive(Debug, Clone, PartialEq, Eq)] pub struct SimulateTransactionsRequest { /// The hash of the requested block, or number (height) of the requested block, or a block tag, @@ -2174,7 +2174,7 @@ pub struct SimulateTransactionsRequest { pub simulation_flags: Vec, } -/// Reference version of [SimulateTransactionsRequest]. +/// Reference version of [`SimulateTransactionsRequest`]. #[derive(Debug, Clone, PartialEq, Eq)] pub struct SimulateTransactionsRequestRef<'a> { pub block_id: &'a BlockId, @@ -2182,34 +2182,34 @@ pub struct SimulateTransactionsRequestRef<'a> { pub simulation_flags: &'a [SimulationFlag], } -/// Request for method starknet_specVersion +/// Request for method `starknet_specVersion` #[derive(Debug, Clone, PartialEq, Eq)] pub struct SpecVersionRequest; -/// Request for method starknet_syncing +/// Request for method `starknet_syncing` #[derive(Debug, Clone, PartialEq, Eq)] pub struct SyncingRequest; -/// Request for method starknet_traceBlockTransactions +/// Request for method `starknet_traceBlockTransactions` #[derive(Debug, Clone, PartialEq, Eq)] pub struct TraceBlockTransactionsRequest { /// The hash of the requested block, or number (height) of the requested block, or a block tag pub block_id: BlockId, } -/// Reference version of [TraceBlockTransactionsRequest]. +/// Reference version of [`TraceBlockTransactionsRequest`]. #[derive(Debug, Clone, PartialEq, Eq)] pub struct TraceBlockTransactionsRequestRef<'a> { pub block_id: &'a BlockId, } -/// Request for method starknet_traceTransaction +/// Request for method `starknet_traceTransaction` #[derive(Debug, Clone, PartialEq, Eq)] pub struct TraceTransactionRequest { pub transaction_hash: Felt, } -/// Reference version of [TraceTransactionRequest]. +/// Reference version of [`TraceTransactionRequest`]. #[derive(Debug, Clone, PartialEq, Eq)] pub struct TraceTransactionRequestRef<'a> { pub transaction_hash: &'a Felt, diff --git a/starknet-core/src/types/contract/legacy.rs b/starknet-core/src/types/contract/legacy.rs index 56cab605..b61478f8 100644 --- a/starknet-core/src/types/contract/legacy.rs +++ b/starknet-core/src/types/contract/legacy.rs @@ -361,26 +361,26 @@ impl<'de> Deserialize<'de> for RawLegacyAbiEntry { let temp_value = serde_json::Value::deserialize(deserializer)?; match &temp_value["type"] { serde_json::Value::String(type_str) => match &type_str[..] { - "constructor" => Ok(RawLegacyAbiEntry::Constructor( + "constructor" => Ok(Self::Constructor( RawLegacyConstructor::deserialize(temp_value).map_err(|err| { DeError::custom(format!("invalid constructor variant: {err}")) })?, )), - "function" => Ok(RawLegacyAbiEntry::Function( + "function" => Ok(Self::Function( RawLegacyFunction::deserialize(temp_value).map_err(|err| { DeError::custom(format!("invalid function variant: {err}")) })?, )), - "struct" => Ok(RawLegacyAbiEntry::Struct( + "struct" => Ok(Self::Struct( RawLegacyStruct::deserialize(temp_value) .map_err(|err| DeError::custom(format!("invalid struct variant: {err}")))?, )), - "l1_handler" => Ok(RawLegacyAbiEntry::L1Handler( + "l1_handler" => Ok(Self::L1Handler( RawLegacyL1Handler::deserialize(temp_value).map_err(|err| { DeError::custom(format!("invalid l1_handler variant: {err}")) })?, )), - "event" => Ok(RawLegacyAbiEntry::Event( + "event" => Ok(Self::Event( RawLegacyEvent::deserialize(temp_value) .map_err(|err| DeError::custom(format!("invalid event variant: {err}")))?, )), @@ -402,7 +402,7 @@ impl LegacyContractClass { // Hashes external entry points elements.push({ let mut buffer = Vec::new(); - for entrypoint in self.entry_points_by_type.external.iter() { + for entrypoint in &self.entry_points_by_type.external { buffer.push(entrypoint.selector); buffer.push(entrypoint.offset.into()); } @@ -412,7 +412,7 @@ impl LegacyContractClass { // Hashes L1 handler entry points elements.push({ let mut buffer = Vec::new(); - for entrypoint in self.entry_points_by_type.l1_handler.iter() { + for entrypoint in &self.entry_points_by_type.l1_handler { buffer.push(entrypoint.selector); buffer.push(entrypoint.offset.into()); } @@ -422,7 +422,7 @@ impl LegacyContractClass { // Hashes constructor entry points elements.push({ let mut buffer = Vec::new(); - for entrypoint in self.entry_points_by_type.constructor.iter() { + for entrypoint in &self.entry_points_by_type.constructor { buffer.push(entrypoint.selector); buffer.push(entrypoint.offset.into()); } @@ -868,7 +868,6 @@ mod tests { "../../../test-data/contracts/cairo0/artifacts/pre-0.11.0/event_example.txt" ), ] - .into_iter() { serde_json::from_str::(raw_artifact).unwrap(); } @@ -907,7 +906,6 @@ mod tests { ), ), ] - .into_iter() { let artifact = serde_json::from_str::(raw_artifact).unwrap(); let computed_hash = artifact.class_hash().unwrap(); @@ -952,7 +950,6 @@ mod tests { ), ), ] - .into_iter() { let artifact = serde_json::from_str::(raw_artifact).unwrap(); let computed_hash = artifact.hinted_class_hash().unwrap(); diff --git a/starknet-core/src/types/contract/mod.rs b/starknet-core/src/types/contract/mod.rs index 24046f9b..6d33b64f 100644 --- a/starknet-core/src/types/contract/mod.rs +++ b/starknet-core/src/types/contract/mod.rs @@ -16,7 +16,7 @@ use crate::{ /// Module containing types related to artifacts of contracts compiled with a Cairo 0.x compiler. pub mod legacy; -/// Cairo string for "CONTRACT_CLASS_V0.1.0" +/// Cairo string for `CONTRACT_CLASS_V0.1.0` const PREFIX_CONTRACT_CLASS_V0_1_0: Felt = Felt::from_raw([ 37302452645455172, 18446734822722598327, @@ -24,7 +24,7 @@ const PREFIX_CONTRACT_CLASS_V0_1_0: Felt = Felt::from_raw([ 5800711240972404213, ]); -/// Cairo string for "COMPILED_CLASS_V1" +/// Cairo string for `COMPILED_CLASS_V1` const PREFIX_COMPILED_CLASS_V1: Felt = Felt::from_raw([ 324306817650036332, 18446744073709549462, @@ -278,7 +278,7 @@ struct BytecodeSegmentedNode { /// Internal structure used for post-Sierra-1.5.0 CASM hash calculation. /// -/// Represents a child of [BytecodeSegmentedNode]. +/// Represents a child of [`BytecodeSegmentedNode`]. struct BytecodeSegment { segment_length: u64, #[allow(unused)] @@ -545,12 +545,12 @@ impl CompiledClass { ) -> Result { let mut hasher = PoseidonHasher::new(); - for entry in entrypoints.iter() { + for entry in entrypoints { hasher.update(entry.selector); hasher.update(entry.offset.into()); let mut builtin_hasher = PoseidonHasher::new(); - for builtin in entry.builtins.iter() { + for builtin in &entry.builtins { builtin_hasher.update(cairo_short_string_to_felt(builtin)?) } @@ -594,7 +594,7 @@ impl CompiledClass { let mut res = Vec::new(); let mut total_len = 0; - for item in bytecode_segment_lengths.iter() { + for item in bytecode_segment_lengths { let visited_pc_before = if !visited_pcs.is_empty() { Some(visited_pcs[visited_pcs.len() - 1]) } else { @@ -666,7 +666,7 @@ impl BytecodeLeaf { impl BytecodeSegmentedNode { fn hash(&self) -> Felt { let mut hasher = PoseidonHasher::new(); - for node in self.segments.iter() { + for node in &self.segments { hasher.update(node.segment_length.into()); hasher.update(node.inner_structure.hash()); } @@ -761,7 +761,7 @@ impl Serialize for TypedAbiEvent { } match self { - TypedAbiEvent::Struct(inner) => StructRef::serialize( + Self::Struct(inner) => StructRef::serialize( &StructRef { name: &inner.name, kind: "struct", @@ -769,7 +769,7 @@ impl Serialize for TypedAbiEvent { }, serializer, ), - TypedAbiEvent::Enum(inner) => EnumRef::serialize( + Self::Enum(inner) => EnumRef::serialize( &EnumRef { name: &inner.name, kind: "enum", @@ -790,7 +790,7 @@ impl Serialize for IntOrList { Self::Int(int) => serializer.serialize_u64(*int), Self::List(list) => { let mut seq = serializer.serialize_seq(Some(list.len()))?; - for item in list.iter() { + for item in list { seq.serialize_element(item)?; } seq.end() @@ -802,7 +802,7 @@ impl Serialize for IntOrList { impl<'de> Visitor<'de> for IntOrListVisitor { type Value = IntOrList; - fn expecting(&self, formatter: &mut core::fmt::Formatter) -> core::fmt::Result { + fn expecting(&self, formatter: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { write!(formatter, "number or list") } @@ -837,7 +837,7 @@ impl<'de> Deserialize<'de> for IntOrList { fn hash_sierra_entrypoints(entrypoints: &[SierraEntryPoint]) -> Felt { let mut hasher = PoseidonHasher::new(); - for entry in entrypoints.iter() { + for entry in entrypoints { hasher.update(entry.selector); hasher.update(entry.function_idx.into()); } @@ -865,7 +865,6 @@ mod tests { include_str!("../../../test-data/contracts/cairo2/artifacts/erc20_sierra.txt"), include_str!("../../../test-data/contracts/cairo2.6/artifacts/erc20_sierra.txt"), ] - .into_iter() { match serde_json::from_str::(raw_artifact) { Ok(ContractArtifact::SierraClass(_)) => {} @@ -884,7 +883,6 @@ mod tests { include_str!("../../../test-data/contracts/cairo2/artifacts/erc20_compiled.txt"), include_str!("../../../test-data/contracts/cairo2.6/artifacts/erc20_compiled.txt"), ] - .into_iter() { match serde_json::from_str::(raw_artifact) { Ok(ContractArtifact::CompiledClass(_)) => {} @@ -925,7 +923,6 @@ mod tests { include_str!("../../../test-data/contracts/cairo2/artifacts/abi_types.hashes.json"), ), ] - .into_iter() { let sierra_class = serde_json::from_str::(raw_artifact).unwrap(); let computed_hash = sierra_class.class_hash().unwrap(); @@ -966,7 +963,6 @@ mod tests { include_str!("../../../test-data/contracts/cairo2.6/artifacts/erc20.hashes.json"), ), ] - .into_iter() { let compiled_class = serde_json::from_str::(raw_artifact).unwrap(); let computed_hash = compiled_class.class_hash().unwrap(); diff --git a/starknet-core/src/types/conversions.rs b/starknet-core/src/types/conversions.rs index 38e7aa5f..670c1a66 100644 --- a/starknet-core/src/types/conversions.rs +++ b/starknet-core/src/types/conversions.rs @@ -10,33 +10,33 @@ impl From for RawLegacyAbiEntry { fn from(value: LegacyContractAbiEntry) -> Self { match value { LegacyContractAbiEntry::Function(inner) => match inner.r#type { - LegacyFunctionAbiType::Function => RawLegacyAbiEntry::Function(RawLegacyFunction { + LegacyFunctionAbiType::Function => Self::Function(RawLegacyFunction { inputs: inner.inputs, name: inner.name, outputs: inner.outputs, state_mutability: inner.state_mutability, }), LegacyFunctionAbiType::L1Handler => { - RawLegacyAbiEntry::L1Handler(RawLegacyL1Handler { + Self::L1Handler(RawLegacyL1Handler { inputs: inner.inputs, name: inner.name, outputs: inner.outputs, }) } LegacyFunctionAbiType::Constructor => { - RawLegacyAbiEntry::Constructor(RawLegacyConstructor { + Self::Constructor(RawLegacyConstructor { inputs: inner.inputs, name: inner.name, outputs: inner.outputs, }) } }, - LegacyContractAbiEntry::Event(inner) => RawLegacyAbiEntry::Event(RawLegacyEvent { + LegacyContractAbiEntry::Event(inner) => Self::Event(RawLegacyEvent { data: inner.data, keys: inner.keys, name: inner.name, }), - LegacyContractAbiEntry::Struct(inner) => RawLegacyAbiEntry::Struct(RawLegacyStruct { + LegacyContractAbiEntry::Struct(inner) => Self::Struct(RawLegacyStruct { members: inner .members .into_iter() diff --git a/starknet-core/src/types/eth_address.rs b/starknet-core/src/types/eth_address.rs index dfc3028e..fd4d3b46 100644 --- a/starknet-core/src/types/eth_address.rs +++ b/starknet-core/src/types/eth_address.rs @@ -83,7 +83,7 @@ impl EthAddress { felt.try_into() } - pub fn as_bytes(&self) -> &[u8; 20] { + pub const fn as_bytes(&self) -> &[u8; 20] { &self.inner } } @@ -109,7 +109,7 @@ impl<'de> Deserialize<'de> for EthAddress { impl<'de> Visitor<'de> for EthAddressVisitor { type Value = EthAddress; - fn expecting(&self, formatter: &mut Formatter) -> alloc::fmt::Result { + fn expecting(&self, formatter: &mut Formatter<'_>) -> alloc::fmt::Result { write!(formatter, "string") } diff --git a/starknet-core/src/types/execution_result.rs b/starknet-core/src/types/execution_result.rs index 2a757531..b0d56a1c 100644 --- a/starknet-core/src/types/execution_result.rs +++ b/starknet-core/src/types/execution_result.rs @@ -12,10 +12,10 @@ pub enum ExecutionResult { } impl ExecutionResult { - pub fn status(&self) -> TransactionExecutionStatus { + pub const fn status(&self) -> TransactionExecutionStatus { match self { - ExecutionResult::Succeeded => TransactionExecutionStatus::Succeeded, - ExecutionResult::Reverted { .. } => TransactionExecutionStatus::Reverted, + Self::Succeeded => TransactionExecutionStatus::Succeeded, + Self::Reverted { .. } => TransactionExecutionStatus::Reverted, } } @@ -25,8 +25,8 @@ impl ExecutionResult { /// variant. pub fn revert_reason(&self) -> Option<&str> { match self { - ExecutionResult::Succeeded => None, - ExecutionResult::Reverted { reason } => Some(reason), + Self::Succeeded => None, + Self::Reverted { reason } => Some(reason), } } } diff --git a/starknet-core/src/types/hash_256.rs b/starknet-core/src/types/hash_256.rs index dd3e31d0..3a7c21ef 100644 --- a/starknet-core/src/types/hash_256.rs +++ b/starknet-core/src/types/hash_256.rs @@ -68,7 +68,7 @@ impl Hash256 { felt.into() } - pub fn as_bytes(&self) -> &[u8; HASH_256_BYTE_COUNT] { + pub const fn as_bytes(&self) -> &[u8; HASH_256_BYTE_COUNT] { &self.inner } } @@ -94,7 +94,7 @@ impl<'de> Deserialize<'de> for Hash256 { impl<'de> Visitor<'de> for Hash256Visitor { type Value = Hash256; - fn expecting(&self, formatter: &mut Formatter) -> alloc::fmt::Result { + fn expecting(&self, formatter: &mut Formatter<'_>) -> alloc::fmt::Result { write!(formatter, "string") } @@ -196,7 +196,7 @@ mod tests { "25c5b1592b1743b62d7fabd4373d98219c2ff3750f49ec0608a8355fa3bb060f5", ]; - for item in test_data.into_iter() { + for item in test_data { match Hash256::from_hex(item) { Err(FromHexError::UnexpectedLength) => {} _ => panic!("Unexpected test result"), @@ -214,7 +214,7 @@ mod tests { "0x?5c5b1592b1743b62d7fabd4373d98219c2f63750f49ec0608a8355fa3bb060", ]; - for item in test_data.into_iter() { + for item in test_data { match Hash256::from_hex(item) { Err(FromHexError::InvalidHexString) => {} _ => panic!("Unexpected test result"), diff --git a/starknet-core/src/types/mod.rs b/starknet-core/src/types/mod.rs index d46535bc..bf401f8e 100644 --- a/starknet-core/src/types/mod.rs +++ b/starknet-core/src/types/mod.rs @@ -309,7 +309,7 @@ pub enum ExecuteInvocation { mod errors { use core::fmt::{Display, Formatter, Result}; - #[derive(Debug, PartialEq)] + #[derive(Debug, PartialEq, Eq)] pub enum ParseMsgToL2Error { EmptyCalldata, FromAddressOutOfRange, @@ -339,8 +339,8 @@ pub use errors::ParseMsgToL2Error; impl MaybePendingBlockWithTxHashes { pub fn transactions(&self) -> &[Felt] { match self { - MaybePendingBlockWithTxHashes::Block(block) => &block.transactions, - MaybePendingBlockWithTxHashes::PendingBlock(block) => &block.transactions, + Self::Block(block) => &block.transactions, + Self::PendingBlock(block) => &block.transactions, } } @@ -355,8 +355,8 @@ impl MaybePendingBlockWithTxHashes { impl MaybePendingBlockWithTxs { pub fn transactions(&self) -> &[Transaction] { match self { - MaybePendingBlockWithTxs::Block(block) => &block.transactions, - MaybePendingBlockWithTxs::PendingBlock(block) => &block.transactions, + Self::Block(block) => &block.transactions, + Self::PendingBlock(block) => &block.transactions, } } @@ -371,8 +371,8 @@ impl MaybePendingBlockWithTxs { impl MaybePendingBlockWithReceipts { pub fn transactions(&self) -> &[TransactionWithReceipt] { match self { - MaybePendingBlockWithReceipts::Block(block) => &block.transactions, - MaybePendingBlockWithReceipts::PendingBlock(block) => &block.transactions, + Self::Block(block) => &block.transactions, + Self::PendingBlock(block) => &block.transactions, } } @@ -385,86 +385,86 @@ impl MaybePendingBlockWithReceipts { } impl TransactionStatus { - pub fn finality_status(&self) -> SequencerTransactionStatus { + pub const fn finality_status(&self) -> SequencerTransactionStatus { match self { - TransactionStatus::Received => SequencerTransactionStatus::Received, - TransactionStatus::Rejected => SequencerTransactionStatus::Rejected, - TransactionStatus::AcceptedOnL2(_) => SequencerTransactionStatus::AcceptedOnL2, - TransactionStatus::AcceptedOnL1(_) => SequencerTransactionStatus::AcceptedOnL1, + Self::Received => SequencerTransactionStatus::Received, + Self::Rejected => SequencerTransactionStatus::Rejected, + Self::AcceptedOnL2(_) => SequencerTransactionStatus::AcceptedOnL2, + Self::AcceptedOnL1(_) => SequencerTransactionStatus::AcceptedOnL1, } } } impl Transaction { - pub fn transaction_hash(&self) -> &Felt { + pub const fn transaction_hash(&self) -> &Felt { match self { - Transaction::Invoke(tx) => tx.transaction_hash(), - Transaction::L1Handler(tx) => &tx.transaction_hash, - Transaction::Declare(tx) => tx.transaction_hash(), - Transaction::Deploy(tx) => &tx.transaction_hash, - Transaction::DeployAccount(tx) => tx.transaction_hash(), + Self::Invoke(tx) => tx.transaction_hash(), + Self::L1Handler(tx) => &tx.transaction_hash, + Self::Declare(tx) => tx.transaction_hash(), + Self::Deploy(tx) => &tx.transaction_hash, + Self::DeployAccount(tx) => tx.transaction_hash(), } } } impl InvokeTransaction { - pub fn transaction_hash(&self) -> &Felt { + pub const fn transaction_hash(&self) -> &Felt { match self { - InvokeTransaction::V0(tx) => &tx.transaction_hash, - InvokeTransaction::V1(tx) => &tx.transaction_hash, - InvokeTransaction::V3(tx) => &tx.transaction_hash, + Self::V0(tx) => &tx.transaction_hash, + Self::V1(tx) => &tx.transaction_hash, + Self::V3(tx) => &tx.transaction_hash, } } } impl DeclareTransaction { - pub fn transaction_hash(&self) -> &Felt { + pub const fn transaction_hash(&self) -> &Felt { match self { - DeclareTransaction::V0(tx) => &tx.transaction_hash, - DeclareTransaction::V1(tx) => &tx.transaction_hash, - DeclareTransaction::V2(tx) => &tx.transaction_hash, - DeclareTransaction::V3(tx) => &tx.transaction_hash, + Self::V0(tx) => &tx.transaction_hash, + Self::V1(tx) => &tx.transaction_hash, + Self::V2(tx) => &tx.transaction_hash, + Self::V3(tx) => &tx.transaction_hash, } } } impl DeployAccountTransaction { - pub fn transaction_hash(&self) -> &Felt { + pub const fn transaction_hash(&self) -> &Felt { match self { - DeployAccountTransaction::V1(tx) => &tx.transaction_hash, - DeployAccountTransaction::V3(tx) => &tx.transaction_hash, + Self::V1(tx) => &tx.transaction_hash, + Self::V3(tx) => &tx.transaction_hash, } } } impl TransactionReceipt { - pub fn transaction_hash(&self) -> &Felt { + pub const fn transaction_hash(&self) -> &Felt { match self { - TransactionReceipt::Invoke(receipt) => &receipt.transaction_hash, - TransactionReceipt::L1Handler(receipt) => &receipt.transaction_hash, - TransactionReceipt::Declare(receipt) => &receipt.transaction_hash, - TransactionReceipt::Deploy(receipt) => &receipt.transaction_hash, - TransactionReceipt::DeployAccount(receipt) => &receipt.transaction_hash, + Self::Invoke(receipt) => &receipt.transaction_hash, + Self::L1Handler(receipt) => &receipt.transaction_hash, + Self::Declare(receipt) => &receipt.transaction_hash, + Self::Deploy(receipt) => &receipt.transaction_hash, + Self::DeployAccount(receipt) => &receipt.transaction_hash, } } - pub fn finality_status(&self) -> &TransactionFinalityStatus { + pub const fn finality_status(&self) -> &TransactionFinalityStatus { match self { - TransactionReceipt::Invoke(receipt) => &receipt.finality_status, - TransactionReceipt::L1Handler(receipt) => &receipt.finality_status, - TransactionReceipt::Declare(receipt) => &receipt.finality_status, - TransactionReceipt::Deploy(receipt) => &receipt.finality_status, - TransactionReceipt::DeployAccount(receipt) => &receipt.finality_status, + Self::Invoke(receipt) => &receipt.finality_status, + Self::L1Handler(receipt) => &receipt.finality_status, + Self::Declare(receipt) => &receipt.finality_status, + Self::Deploy(receipt) => &receipt.finality_status, + Self::DeployAccount(receipt) => &receipt.finality_status, } } - pub fn execution_result(&self) -> &ExecutionResult { + pub const fn execution_result(&self) -> &ExecutionResult { match self { - TransactionReceipt::Invoke(receipt) => &receipt.execution_result, - TransactionReceipt::L1Handler(receipt) => &receipt.execution_result, - TransactionReceipt::Declare(receipt) => &receipt.execution_result, - TransactionReceipt::Deploy(receipt) => &receipt.execution_result, - TransactionReceipt::DeployAccount(receipt) => &receipt.execution_result, + Self::Invoke(receipt) => &receipt.execution_result, + Self::L1Handler(receipt) => &receipt.execution_result, + Self::Declare(receipt) => &receipt.execution_result, + Self::Deploy(receipt) => &receipt.execution_result, + Self::DeployAccount(receipt) => &receipt.execution_result, } } } @@ -488,44 +488,44 @@ impl L1HandlerTransaction { } } -impl AsRef for BlockId { - fn as_ref(&self) -> &BlockId { +impl AsRef for BlockId { + fn as_ref(&self) -> &Self { self } } -impl AsRef for FunctionCall { - fn as_ref(&self) -> &FunctionCall { +impl AsRef for FunctionCall { + fn as_ref(&self) -> &Self { self } } -impl AsRef for MsgFromL1 { - fn as_ref(&self) -> &MsgFromL1 { +impl AsRef for MsgFromL1 { + fn as_ref(&self) -> &Self { self } } -impl AsRef for BroadcastedTransaction { - fn as_ref(&self) -> &BroadcastedTransaction { +impl AsRef for BroadcastedTransaction { + fn as_ref(&self) -> &Self { self } } -impl AsRef for BroadcastedInvokeTransaction { - fn as_ref(&self) -> &BroadcastedInvokeTransaction { +impl AsRef for BroadcastedInvokeTransaction { + fn as_ref(&self) -> &Self { self } } -impl AsRef for BroadcastedDeclareTransaction { - fn as_ref(&self) -> &BroadcastedDeclareTransaction { +impl AsRef for BroadcastedDeclareTransaction { + fn as_ref(&self) -> &Self { self } } -impl AsRef for BroadcastedDeployAccountTransaction { - fn as_ref(&self) -> &BroadcastedDeployAccountTransaction { +impl AsRef for BroadcastedDeployAccountTransaction { + fn as_ref(&self) -> &Self { self } } diff --git a/starknet-core/src/types/msg.rs b/starknet-core/src/types/msg.rs index e1f1ce04..c34919e9 100644 --- a/starknet-core/src/types/msg.rs +++ b/starknet-core/src/types/msg.rs @@ -17,7 +17,7 @@ pub struct MsgToL2 { impl MsgToL2 { /// Calculates the message hash based on the algorithm documented here: /// - /// https://docs.starknet.io/documentation/architecture_and_concepts/L1-L2_Communication/messaging-mechanism/ + /// pub fn hash(&self) -> Hash256 { let mut hasher = Keccak256::new(); @@ -40,7 +40,7 @@ impl MsgToL2 { hasher.update((self.payload.len() as u64).to_be_bytes()); // Payload - for item in self.payload.iter() { + for item in &self.payload { hasher.update(item.to_bytes_be()); } @@ -54,7 +54,7 @@ impl MsgToL2 { impl MsgToL1 { /// Calculates the message hash based on the algorithm documented here: /// - /// https://docs.starknet.io/documentation/architecture_and_concepts/Network_Architecture/messaging-mechanism/#structure_and_hashing_l2-l1 + /// pub fn hash(&self) -> Hash256 { let mut hasher = Keccak256::new(); @@ -69,7 +69,7 @@ impl MsgToL1 { hasher.update((self.payload.len() as u64).to_be_bytes()); // Payload - for item in self.payload.iter() { + for item in &self.payload { hasher.update(item.to_bytes_be()); } diff --git a/starknet-core/src/types/receipt_block.rs b/starknet-core/src/types/receipt_block.rs index 4287e2e6..77299441 100644 --- a/starknet-core/src/types/receipt_block.rs +++ b/starknet-core/src/types/receipt_block.rs @@ -12,38 +12,38 @@ pub enum ReceiptBlock { impl ReceiptBlock { /// Returns `true` if and only if it's the `Pending` variant. - pub fn is_pending(&self) -> bool { + pub const fn is_pending(&self) -> bool { match self { - ReceiptBlock::Pending => true, - ReceiptBlock::Block { .. } => false, + Self::Pending => true, + Self::Block { .. } => false, } } /// Returns `true` if and only if it's the `Block` variant. - pub fn is_block(&self) -> bool { + pub const fn is_block(&self) -> bool { match self { - ReceiptBlock::Pending => false, - ReceiptBlock::Block { .. } => true, + Self::Pending => false, + Self::Block { .. } => true, } } /// Returns `None` if block is not `Block`. /// /// A more idiomatic way of accessing the block hash is to match the `Block` enum variant. - pub fn block_hash(&self) -> Option { + pub const fn block_hash(&self) -> Option { match self { - ReceiptBlock::Pending => None, - ReceiptBlock::Block { block_hash, .. } => Some(*block_hash), + Self::Pending => None, + Self::Block { block_hash, .. } => Some(*block_hash), } } /// Returns `None` if block is not `Block`. /// /// A more idiomatic way of accessing the block number is to match the `Block` enum variant. - pub fn block_number(&self) -> Option { + pub const fn block_number(&self) -> Option { match self { - ReceiptBlock::Pending => None, - ReceiptBlock::Block { block_number, .. } => Some(*block_number), + Self::Pending => None, + Self::Block { block_number, .. } => Some(*block_number), } } } diff --git a/starknet-core/src/types/serde_impls.rs b/starknet-core/src/types/serde_impls.rs index 95a5221f..7b97ae1c 100644 --- a/starknet-core/src/types/serde_impls.rs +++ b/starknet-core/src/types/serde_impls.rs @@ -58,7 +58,7 @@ impl<'de> DeserializeAs<'de, u128> for NumAsHex { impl<'de> Visitor<'de> for NumAsHexVisitorU64 { type Value = u64; - fn expecting(&self, formatter: &mut Formatter) -> alloc::fmt::Result { + fn expecting(&self, formatter: &mut Formatter<'_>) -> alloc::fmt::Result { write!(formatter, "string or number") } @@ -98,7 +98,7 @@ impl<'de> Visitor<'de> for NumAsHexVisitorU64 { impl<'de> Visitor<'de> for NumAsHexVisitorU128 { type Value = u128; - fn expecting(&self, formatter: &mut Formatter) -> alloc::fmt::Result { + fn expecting(&self, formatter: &mut Formatter<'_>) -> alloc::fmt::Result { write!(formatter, "string or number") } @@ -128,8 +128,8 @@ impl Serialize for SyncStatusType { S: serde::Serializer, { match self { - SyncStatusType::NotSyncing => serializer.serialize_bool(false), - SyncStatusType::Syncing(sync_status) => SyncStatus::serialize(sync_status, serializer), + Self::NotSyncing => serializer.serialize_bool(false), + Self::Syncing(sync_status) => SyncStatus::serialize(sync_status, serializer), } } } @@ -145,7 +145,7 @@ impl<'de> Deserialize<'de> for SyncStatusType { false => Ok(Self::NotSyncing), }, - SyncStatusTypeDe::SyncStatus(value) => Ok(SyncStatusType::Syncing(value)), + SyncStatusTypeDe::SyncStatus(value) => Ok(Self::Syncing(value)), } } } @@ -233,19 +233,19 @@ mod transaction_status { S: Serializer, { let raw = match self { - TransactionStatus::Received => Raw { + Self::Received => Raw { finality_status: SequencerTransactionStatus::Received, execution_status: None, }, - TransactionStatus::Rejected => Raw { + Self::Rejected => Raw { finality_status: SequencerTransactionStatus::Rejected, execution_status: None, }, - TransactionStatus::AcceptedOnL2(exe) => Raw { + Self::AcceptedOnL2(exe) => Raw { finality_status: SequencerTransactionStatus::AcceptedOnL2, execution_status: Some(*exe), }, - TransactionStatus::AcceptedOnL1(exe) => Raw { + Self::AcceptedOnL1(exe) => Raw { finality_status: SequencerTransactionStatus::AcceptedOnL1, execution_status: Some(*exe), }, @@ -420,7 +420,6 @@ mod tests { (BlockId::Tag(BlockTag::Latest), "\"latest\""), (BlockId::Tag(BlockTag::Pending), "\"pending\""), ] - .into_iter() { assert_eq!(serde_json::to_string(&block_id).unwrap(), json); assert_eq!(serde_json::from_str::(json).unwrap(), block_id); @@ -434,7 +433,7 @@ mod tests { #[derive(Debug, PartialEq, Eq, Deserialize)] struct Value(#[serde_as(as = "NumAsHex")] u64); - for (num, json) in [(Value(100), "\"0x64\""), (Value(100), "100")].into_iter() { + for (num, json) in [(Value(100), "\"0x64\""), (Value(100), "100")] { assert_eq!(serde_json::from_str::(json).unwrap(), num); } } diff --git a/starknet-core/src/utils.rs b/starknet-core/src/utils.rs index c1fa8273..10bac139 100644 --- a/starknet-core/src/utils.rs +++ b/starknet-core/src/utils.rs @@ -126,7 +126,7 @@ pub fn get_storage_var_address(var_name: &str, args: &[Felt]) -> Result Result Result { if !str.is_ascii() { return Err(CairoShortStringToFeltError::NonAsciiCharacter); @@ -153,7 +153,7 @@ pub fn cairo_short_string_to_felt(str: &str) -> Result Result { if felt == &Felt::ZERO { return Ok(String::new()); @@ -165,7 +165,7 @@ pub fn parse_cairo_short_string(felt: &Felt) -> Result