diff --git a/Cargo.lock b/Cargo.lock index 1b62a5b6..c282b130 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1502,6 +1502,7 @@ dependencies = [ "serde_json", "serde_with", "sha3", + "starknet-core", "starknet-crypto", "starknet-ff", "thiserror", @@ -1583,6 +1584,7 @@ dependencies = [ "serde_json", "serde_with", "starknet-core", + "starknet-providers", "thiserror", "tokio", "url", diff --git a/Cargo.toml b/Cargo.toml index 32ed3093..8d8f3ea3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -48,3 +48,4 @@ url = "2.2.2" [features] default = ["bigdecimal"] bigdecimal = ["starknet-core/bigdecimal"] +no_unknown_fields = ["starknet-core/no_unknown_fields", "starknet-providers/no_unknown_fields"] diff --git a/starknet-core/Cargo.toml b/starknet-core/Cargo.toml index 370b5094..fce40bae 100644 --- a/starknet-core/Cargo.toml +++ b/starknet-core/Cargo.toml @@ -30,6 +30,7 @@ thiserror = "1.0.30" [dev-dependencies] criterion = { version = "0.4.0", default-features = false } +starknet-core = { path = ".", features = ["no_unknown_fields"] } [target.'cfg(target_arch = "wasm32")'.dev-dependencies] wasm-bindgen-test = "0.3.29" @@ -37,6 +38,7 @@ wasm-bindgen-test = "0.3.29" [features] default = ["bigdecimal"] bigdecimal = ["starknet-ff/bigdecimal"] +no_unknown_fields = [] [[bench]] name = "class_hash" diff --git a/starknet-core/src/types/block.rs b/starknet-core/src/types/block.rs index 8da8c331..72803dc9 100644 --- a/starknet-core/src/types/block.rs +++ b/starknet-core/src/types/block.rs @@ -15,7 +15,7 @@ pub enum BlockId { #[derive(Debug, Deserialize, PartialEq, Eq)] #[serde(rename_all = "SCREAMING_SNAKE_CASE")] -#[cfg_attr(test, serde(deny_unknown_fields))] +#[cfg_attr(feature = "no_unknown_fields", serde(deny_unknown_fields))] pub enum BlockStatus { /// Block that is yet to be closed Pending, @@ -31,7 +31,7 @@ pub enum BlockStatus { #[serde_as] #[derive(Debug, Deserialize)] -#[cfg_attr(test, serde(deny_unknown_fields))] +#[cfg_attr(feature = "no_unknown_fields", serde(deny_unknown_fields))] pub struct Block { #[serde(default)] #[serde_as(as = "UfeHexOption")] diff --git a/starknet-core/src/types/call_contract.rs b/starknet-core/src/types/call_contract.rs index 64a5b737..a9e46e00 100644 --- a/starknet-core/src/types/call_contract.rs +++ b/starknet-core/src/types/call_contract.rs @@ -5,7 +5,7 @@ use serde_with::serde_as; #[serde_as] #[derive(Debug, Deserialize)] -#[cfg_attr(test, serde(deny_unknown_fields))] +#[cfg_attr(feature = "no_unknown_fields", serde(deny_unknown_fields))] pub struct CallContractResult { #[serde_as(as = "Vec")] pub result: Vec, diff --git a/starknet-core/src/types/contract_addresses.rs b/starknet-core/src/types/contract_addresses.rs index 47bfff00..1899758a 100644 --- a/starknet-core/src/types/contract_addresses.rs +++ b/starknet-core/src/types/contract_addresses.rs @@ -3,7 +3,7 @@ use serde::Deserialize; #[derive(Debug, Deserialize)] #[serde(rename_all = "PascalCase")] -#[cfg_attr(test, serde(deny_unknown_fields))] +#[cfg_attr(feature = "no_unknown_fields", serde(deny_unknown_fields))] pub struct ContractAddresses { pub starknet: Address, pub gps_statement_verifier: Address, diff --git a/starknet-core/src/types/contract_artifact.rs b/starknet-core/src/types/contract_artifact.rs index 2dcf470d..ebc4eac7 100644 --- a/starknet-core/src/types/contract_artifact.rs +++ b/starknet-core/src/types/contract_artifact.rs @@ -15,7 +15,7 @@ use std::{collections::BTreeMap, io::Write}; const API_VERSION: FieldElement = FieldElement::ZERO; #[derive(Debug, Serialize, Deserialize)] -#[serde(deny_unknown_fields)] +#[cfg_attr(feature = "no_unknown_fields", serde(deny_unknown_fields))] pub struct ContractArtifact { pub abi: Vec, pub entry_points_by_type: EntryPointsByType, @@ -40,7 +40,7 @@ pub enum CompressProgramError { #[serde_as] #[derive(Debug, Serialize, Deserialize)] -#[serde(deny_unknown_fields)] +#[cfg_attr(feature = "no_unknown_fields", serde(deny_unknown_fields))] pub struct Program { #[serde(skip_serializing_if = "Option::is_none")] pub attributes: Option>, @@ -62,7 +62,7 @@ pub struct Program { } #[derive(Debug, Serialize, Deserialize)] -#[serde(deny_unknown_fields)] +#[cfg_attr(feature = "no_unknown_fields", serde(deny_unknown_fields))] pub struct Attribute { pub accessible_scopes: Vec, pub end_pc: u64, @@ -74,7 +74,7 @@ pub struct Attribute { } #[derive(Debug, Serialize, Deserialize)] -#[serde(deny_unknown_fields)] +#[cfg_attr(feature = "no_unknown_fields", serde(deny_unknown_fields))] pub struct DebugInfo { /// A partial map from file name to its content. Files that are not in the map, are assumed to /// exist in the file system. @@ -84,7 +84,7 @@ pub struct DebugInfo { } #[derive(Debug, Serialize, Deserialize)] -#[serde(deny_unknown_fields)] +#[cfg_attr(feature = "no_unknown_fields", serde(deny_unknown_fields))] pub struct Hint { pub accessible_scopes: Vec, pub code: String, @@ -92,7 +92,7 @@ pub struct Hint { } #[derive(Debug, Serialize, Deserialize)] -#[serde(deny_unknown_fields)] +#[cfg_attr(feature = "no_unknown_fields", serde(deny_unknown_fields))] pub struct Identifier { #[serde(skip_serializing_if = "Option::is_none")] pub decorators: Option>, @@ -116,13 +116,13 @@ pub struct Identifier { } #[derive(Debug, Serialize, Deserialize)] -#[serde(deny_unknown_fields)] +#[cfg_attr(feature = "no_unknown_fields", serde(deny_unknown_fields))] pub struct ReferenceManager { pub references: Vec, } #[derive(Debug, Serialize, Deserialize)] -#[serde(deny_unknown_fields)] +#[cfg_attr(feature = "no_unknown_fields", serde(deny_unknown_fields))] pub struct InstructionLocation { pub accessible_scopes: Vec, // This field is serialized as `null` instead of skipped @@ -132,14 +132,14 @@ pub struct InstructionLocation { } #[derive(Debug, Serialize, Deserialize)] -#[serde(deny_unknown_fields)] +#[cfg_attr(feature = "no_unknown_fields", serde(deny_unknown_fields))] pub struct IdentifierMember { pub cairo_type: String, pub offset: u64, } #[derive(Debug, Serialize, Deserialize)] -#[serde(deny_unknown_fields)] +#[cfg_attr(feature = "no_unknown_fields", serde(deny_unknown_fields))] pub struct Reference { pub ap_tracking_data: ApTrackingData, pub pc: u64, @@ -147,14 +147,14 @@ pub struct Reference { } #[derive(Debug, Serialize, Deserialize)] -#[serde(deny_unknown_fields)] +#[cfg_attr(feature = "no_unknown_fields", serde(deny_unknown_fields))] pub struct FlowTrackingData { pub ap_tracking: ApTrackingData, pub reference_ids: BTreeMap, } #[derive(Debug, Serialize, Deserialize)] -#[serde(deny_unknown_fields)] +#[cfg_attr(feature = "no_unknown_fields", serde(deny_unknown_fields))] pub struct HintLocation { pub location: Location, /// The number of new lines following the "%{" symbol @@ -162,7 +162,7 @@ pub struct HintLocation { } #[derive(Debug, Serialize, Deserialize)] -#[serde(deny_unknown_fields)] +#[cfg_attr(feature = "no_unknown_fields", serde(deny_unknown_fields))] pub struct Location { pub end_col: u64, pub end_line: u64, @@ -174,14 +174,14 @@ pub struct Location { } #[derive(Debug, Serialize, Deserialize)] -#[serde(deny_unknown_fields)] +#[cfg_attr(feature = "no_unknown_fields", serde(deny_unknown_fields))] pub struct ApTrackingData { pub group: u64, pub offset: u64, } #[derive(Debug, Serialize, Deserialize)] -#[serde(deny_unknown_fields)] +#[cfg_attr(feature = "no_unknown_fields", serde(deny_unknown_fields))] pub struct InputFile { #[serde(skip_serializing_if = "Option::is_none")] pub filename: Option, diff --git a/starknet-core/src/types/contract_code.rs b/starknet-core/src/types/contract_code.rs index c55ae9a1..0f23215e 100644 --- a/starknet-core/src/types/contract_code.rs +++ b/starknet-core/src/types/contract_code.rs @@ -5,7 +5,7 @@ use serde_with::serde_as; #[serde_as] #[derive(Debug, Deserialize)] -#[cfg_attr(test, serde(deny_unknown_fields))] +#[cfg_attr(feature = "no_unknown_fields", serde(deny_unknown_fields))] pub struct ContractCode { #[serde_as(as = "Vec")] pub bytecode: Vec, @@ -60,28 +60,28 @@ pub struct Event { } #[derive(Debug, Clone, Serialize, Deserialize)] -#[cfg_attr(test, serde(deny_unknown_fields))] +#[cfg_attr(feature = "no_unknown_fields", serde(deny_unknown_fields))] pub struct Input { pub name: String, pub r#type: String, } #[derive(Debug, Clone, Serialize, Deserialize)] -#[cfg_attr(test, serde(deny_unknown_fields))] +#[cfg_attr(feature = "no_unknown_fields", serde(deny_unknown_fields))] pub struct Output { pub name: String, pub r#type: String, } #[derive(Debug, Clone, Serialize, Deserialize)] -#[cfg_attr(test, serde(deny_unknown_fields))] +#[cfg_attr(feature = "no_unknown_fields", serde(deny_unknown_fields))] pub struct EventData { pub name: String, pub r#type: String, } #[derive(Debug, Clone, Serialize, Deserialize)] -#[cfg_attr(test, serde(deny_unknown_fields))] +#[cfg_attr(feature = "no_unknown_fields", serde(deny_unknown_fields))] pub struct Member { pub name: String, pub offset: u64, diff --git a/starknet-core/src/types/fee.rs b/starknet-core/src/types/fee.rs index dc01d378..ae4b02b1 100644 --- a/starknet-core/src/types/fee.rs +++ b/starknet-core/src/types/fee.rs @@ -3,7 +3,7 @@ use serde::Deserialize; use super::TransactionTrace; #[derive(Debug, Deserialize)] -#[cfg_attr(test, serde(deny_unknown_fields))] +#[cfg_attr(feature = "no_unknown_fields", serde(deny_unknown_fields))] pub struct FeeEstimate { pub overall_fee: u64, pub unit: FeeUnit, @@ -13,14 +13,14 @@ pub struct FeeEstimate { /// Represents the information regarding a StarkNet transaction's simulation. #[derive(Debug, Deserialize)] -#[cfg_attr(test, serde(deny_unknown_fields))] +#[cfg_attr(feature = "no_unknown_fields", serde(deny_unknown_fields))] pub struct TransactionSimulationInfo { pub trace: TransactionTrace, pub fee_estimation: FeeEstimate, } #[derive(Debug, Deserialize)] -#[cfg_attr(test, serde(deny_unknown_fields))] +#[cfg_attr(feature = "no_unknown_fields", serde(deny_unknown_fields))] pub enum FeeUnit { #[serde(rename = "wei")] Wei, diff --git a/starknet-core/src/types/starknet_error.rs b/starknet-core/src/types/starknet_error.rs index 7dfa2742..19bb0044 100644 --- a/starknet-core/src/types/starknet_error.rs +++ b/starknet-core/src/types/starknet_error.rs @@ -1,7 +1,7 @@ use serde::{Deserialize, Serialize}; #[derive(Debug, Deserialize)] -#[cfg_attr(test, serde(deny_unknown_fields))] +#[cfg_attr(feature = "no_unknown_fields", serde(deny_unknown_fields))] pub struct Error { pub code: ErrorCode, pub message: String, @@ -16,7 +16,7 @@ impl std::fmt::Display for Error { } #[derive(Debug, PartialEq, Eq, Deserialize, Serialize)] -#[cfg_attr(test, serde(deny_unknown_fields))] +#[cfg_attr(feature = "no_unknown_fields", serde(deny_unknown_fields))] pub enum ErrorCode { #[serde(rename = "StarknetErrorCode.BLOCK_NOT_FOUND")] BlockNotFound, diff --git a/starknet-core/src/types/state_update.rs b/starknet-core/src/types/state_update.rs index da6b24d3..a8e4e13c 100644 --- a/starknet-core/src/types/state_update.rs +++ b/starknet-core/src/types/state_update.rs @@ -6,7 +6,7 @@ use std::collections::HashMap; #[serde_as] #[derive(Debug, Deserialize)] -#[cfg_attr(test, serde(deny_unknown_fields))] +#[cfg_attr(feature = "no_unknown_fields", serde(deny_unknown_fields))] pub struct StateUpdate { #[serde(default)] #[serde_as(as = "Option")] @@ -20,7 +20,7 @@ pub struct StateUpdate { #[serde_as] #[derive(Debug, Deserialize)] -#[cfg_attr(test, serde(deny_unknown_fields))] +#[cfg_attr(feature = "no_unknown_fields", serde(deny_unknown_fields))] pub struct StateDiff { #[serde_as(as = "HashMap")] pub storage_diffs: HashMap>, @@ -34,7 +34,7 @@ pub struct StateDiff { #[serde_as] #[derive(Debug, Deserialize)] -#[cfg_attr(test, serde(deny_unknown_fields))] +#[cfg_attr(feature = "no_unknown_fields", serde(deny_unknown_fields))] pub struct StorageDiff { #[serde_as(as = "UfeHex")] pub key: FieldElement, @@ -44,7 +44,7 @@ pub struct StorageDiff { #[serde_as] #[derive(Debug, Deserialize)] -#[cfg_attr(test, serde(deny_unknown_fields))] +#[cfg_attr(feature = "no_unknown_fields", serde(deny_unknown_fields))] pub struct DeployedContract { #[serde_as(as = "UfeHex")] pub address: FieldElement, diff --git a/starknet-core/src/types/trace.rs b/starknet-core/src/types/trace.rs index 00bbf005..2b60c448 100644 --- a/starknet-core/src/types/trace.rs +++ b/starknet-core/src/types/trace.rs @@ -7,7 +7,7 @@ use starknet_crypto::FieldElement; #[serde_as] #[derive(Debug, Deserialize)] -#[cfg_attr(test, serde(deny_unknown_fields))] +#[cfg_attr(feature = "no_unknown_fields", serde(deny_unknown_fields))] pub struct BlockTraces { pub traces: Vec, } @@ -15,7 +15,7 @@ pub struct BlockTraces { /// Represents the trace of a StarkNet transaction execution, including internal calls. #[serde_as] #[derive(Debug, Deserialize)] -#[cfg_attr(test, serde(deny_unknown_fields))] +#[cfg_attr(feature = "no_unknown_fields", serde(deny_unknown_fields))] pub struct TransactionTrace { /// An object describing the invocation of a specific function. pub function_invocation: FunctionInvocation, @@ -31,7 +31,7 @@ pub struct TransactionTrace { #[serde_as] #[derive(Debug, Deserialize)] -#[cfg_attr(test, serde(deny_unknown_fields))] +#[cfg_attr(feature = "no_unknown_fields", serde(deny_unknown_fields))] pub struct TransactionTraceWithHash { #[serde(flatten)] pub trace: TransactionTrace, @@ -41,7 +41,7 @@ pub struct TransactionTraceWithHash { #[derive(Debug, Deserialize, PartialEq, Eq)] #[serde(rename_all = "SCREAMING_SNAKE_CASE")] -#[cfg_attr(test, serde(deny_unknown_fields))] +#[cfg_attr(feature = "no_unknown_fields", serde(deny_unknown_fields))] pub enum CallType { Call, Delegate, @@ -50,7 +50,7 @@ pub enum CallType { /// A lean version of CallInfo class, containing merely the information relevant for the user. #[serde_as] #[derive(Debug, Deserialize)] -#[cfg_attr(test, serde(deny_unknown_fields))] +#[cfg_attr(feature = "no_unknown_fields", serde(deny_unknown_fields))] pub struct FunctionInvocation { #[serde_as(as = "UfeHex")] pub caller_address: FieldElement, @@ -80,7 +80,7 @@ pub struct FunctionInvocation { #[serde_as] #[derive(Debug, Deserialize)] -#[cfg_attr(test, serde(deny_unknown_fields))] +#[cfg_attr(feature = "no_unknown_fields", serde(deny_unknown_fields))] pub struct OrderedEventResponse { pub order: u64, #[serde_as(as = "Vec")] @@ -91,7 +91,7 @@ pub struct OrderedEventResponse { #[serde_as] #[derive(Debug, Deserialize)] -#[cfg_attr(test, serde(deny_unknown_fields))] +#[cfg_attr(feature = "no_unknown_fields", serde(deny_unknown_fields))] pub struct OrderedL2ToL1MessageResponse { pub order: u64, pub to_address: Address, diff --git a/starknet-core/src/types/transaction.rs b/starknet-core/src/types/transaction.rs index 9f31a1b2..b659773b 100644 --- a/starknet-core/src/types/transaction.rs +++ b/starknet-core/src/types/transaction.rs @@ -11,7 +11,7 @@ use serde_with::serde_as; #[derive(Debug, Deserialize)] #[serde(tag = "type", rename_all = "SCREAMING_SNAKE_CASE")] -#[cfg_attr(test, serde(deny_unknown_fields))] +#[cfg_attr(feature = "no_unknown_fields", serde(deny_unknown_fields))] pub enum TransactionType { Declare(DeclareTransaction), Deploy(DeployTransaction), @@ -22,7 +22,7 @@ pub enum TransactionType { #[serde_as] #[derive(Debug, Deserialize)] -#[cfg_attr(test, serde(deny_unknown_fields))] +#[cfg_attr(feature = "no_unknown_fields", serde(deny_unknown_fields))] pub struct TransactionStatusInfo { #[serde(default)] #[serde_as(as = "UfePendingBlockHash")] @@ -33,7 +33,7 @@ pub struct TransactionStatusInfo { pub transaction_failure_reason: Option, } #[derive(Debug, Deserialize)] -#[cfg_attr(test, serde(deny_unknown_fields))] +#[cfg_attr(feature = "no_unknown_fields", serde(deny_unknown_fields))] pub struct TransactionFailureReason { pub code: String, pub error_message: Option, @@ -41,7 +41,7 @@ pub struct TransactionFailureReason { #[serde_as] #[derive(Debug, Deserialize)] -#[cfg_attr(test, serde(deny_unknown_fields))] +#[cfg_attr(feature = "no_unknown_fields", serde(deny_unknown_fields))] pub struct TransactionInfo { #[serde(default)] #[serde_as(as = "UfePendingBlockHash")] @@ -56,7 +56,7 @@ pub struct TransactionInfo { #[derive(Debug, Deserialize, PartialEq, Eq)] #[serde(rename_all = "SCREAMING_SNAKE_CASE")] -#[cfg_attr(test, serde(deny_unknown_fields))] +#[cfg_attr(feature = "no_unknown_fields", serde(deny_unknown_fields))] pub enum EntryPointType { External, L1Handler, @@ -65,7 +65,7 @@ pub enum EntryPointType { #[serde_as] #[derive(Debug, Deserialize)] -#[cfg_attr(test, serde(deny_unknown_fields))] +#[cfg_attr(feature = "no_unknown_fields", serde(deny_unknown_fields))] pub struct DeclareTransaction { #[serde_as(as = "UfeHex")] pub class_hash: FieldElement, @@ -85,7 +85,7 @@ pub struct DeclareTransaction { #[serde_as] #[derive(Debug, Deserialize)] -#[cfg_attr(test, serde(deny_unknown_fields))] +#[cfg_attr(feature = "no_unknown_fields", serde(deny_unknown_fields))] pub struct DeployTransaction { #[serde_as(deserialize_as = "Vec")] pub constructor_calldata: Vec, @@ -103,7 +103,7 @@ pub struct DeployTransaction { #[serde_as] #[derive(Debug, Deserialize)] -#[cfg_attr(test, serde(deny_unknown_fields))] +#[cfg_attr(feature = "no_unknown_fields", serde(deny_unknown_fields))] pub struct DeployAccountTransaction { #[serde_as(deserialize_as = "Vec")] pub constructor_calldata: Vec, @@ -127,7 +127,7 @@ pub struct DeployAccountTransaction { #[serde_as] #[derive(Debug, Deserialize)] -#[cfg_attr(test, serde(deny_unknown_fields))] +#[cfg_attr(feature = "no_unknown_fields", serde(deny_unknown_fields))] pub struct InvokeFunctionTransaction { #[serde_as(as = "UfeHex")] pub contract_address: FieldElement, @@ -151,7 +151,7 @@ pub struct InvokeFunctionTransaction { #[serde_as] #[derive(Debug, Deserialize)] -#[cfg_attr(test, serde(deny_unknown_fields))] +#[cfg_attr(feature = "no_unknown_fields", serde(deny_unknown_fields))] pub struct L1HandlerTransaction { #[serde_as(as = "UfeHex")] pub contract_address: FieldElement, diff --git a/starknet-core/src/types/transaction_receipt.rs b/starknet-core/src/types/transaction_receipt.rs index 3e75b7d1..a8fc5230 100644 --- a/starknet-core/src/types/transaction_receipt.rs +++ b/starknet-core/src/types/transaction_receipt.rs @@ -10,7 +10,7 @@ use serde_with::serde_as; #[serde_as] #[derive(Debug, Deserialize)] -#[cfg_attr(test, serde(deny_unknown_fields))] +#[cfg_attr(feature = "no_unknown_fields", serde(deny_unknown_fields))] pub struct Receipt { #[serde(default)] #[serde_as(as = "UfePendingBlockHash")] @@ -33,7 +33,7 @@ pub struct Receipt { #[serde_as] #[derive(Debug, Deserialize)] -#[cfg_attr(test, serde(deny_unknown_fields))] +#[cfg_attr(feature = "no_unknown_fields", serde(deny_unknown_fields))] pub struct ConfirmedReceipt { #[serde_as(as = "UfeHex")] pub transaction_hash: FieldElement, @@ -49,7 +49,7 @@ pub struct ConfirmedReceipt { #[derive(Debug, Deserialize, PartialEq, Eq)] #[serde(rename_all = "SCREAMING_SNAKE_CASE")] -#[cfg_attr(test, serde(deny_unknown_fields))] +#[cfg_attr(feature = "no_unknown_fields", serde(deny_unknown_fields))] pub enum TransactionStatus { /// Transaction has not been received yet (i.e. not written to storage) NotReceived, @@ -67,7 +67,7 @@ pub enum TransactionStatus { } #[derive(Debug, Deserialize)] -#[cfg_attr(test, serde(deny_unknown_fields))] +#[cfg_attr(feature = "no_unknown_fields", serde(deny_unknown_fields))] pub struct ExecutionResources { pub n_steps: u64, pub n_memory_holes: u64, @@ -75,7 +75,7 @@ pub struct ExecutionResources { } #[derive(Debug, Deserialize)] -#[cfg_attr(test, serde(deny_unknown_fields))] +#[cfg_attr(feature = "no_unknown_fields", serde(deny_unknown_fields))] pub struct BuiltinInstanceCounter { pub pedersen_builtin: Option, pub range_check_builtin: Option, @@ -87,7 +87,7 @@ pub struct BuiltinInstanceCounter { #[serde_as] #[derive(Debug, Deserialize)] -#[cfg_attr(test, serde(deny_unknown_fields))] +#[cfg_attr(feature = "no_unknown_fields", serde(deny_unknown_fields))] pub struct L1ToL2Message { pub from_address: L1Address, #[serde_as(as = "UfeHex")] @@ -103,7 +103,7 @@ pub struct L1ToL2Message { #[serde_as] #[derive(Debug, Deserialize)] -#[cfg_attr(test, serde(deny_unknown_fields))] +#[cfg_attr(feature = "no_unknown_fields", serde(deny_unknown_fields))] pub struct L2ToL1Message { #[serde_as(as = "UfeHex")] pub from_address: FieldElement, @@ -114,7 +114,7 @@ pub struct L2ToL1Message { #[serde_as] #[derive(Debug, Deserialize)] -#[cfg_attr(test, serde(deny_unknown_fields))] +#[cfg_attr(feature = "no_unknown_fields", serde(deny_unknown_fields))] pub struct Event { #[serde_as(as = "UfeHex")] pub from_address: FieldElement, diff --git a/starknet-core/src/types/transaction_request.rs b/starknet-core/src/types/transaction_request.rs index a60a98ce..c1320f2b 100644 --- a/starknet-core/src/types/transaction_request.rs +++ b/starknet-core/src/types/transaction_request.rs @@ -12,7 +12,7 @@ use std::sync::Arc; #[serde_as] #[derive(Debug, Deserialize)] -#[cfg_attr(test, serde(deny_unknown_fields))] +#[cfg_attr(feature = "no_unknown_fields", serde(deny_unknown_fields))] pub struct AddTransactionResult { pub code: AddTransactionResultCode, #[serde_as(as = "UfeHex")] @@ -26,7 +26,7 @@ pub struct AddTransactionResult { } #[derive(Debug, PartialEq, Eq, Deserialize)] -#[cfg_attr(test, serde(deny_unknown_fields))] +#[cfg_attr(feature = "no_unknown_fields", serde(deny_unknown_fields))] pub enum AddTransactionResultCode { #[serde(rename = "TRANSACTION_RECEIVED")] TransactionReceived, @@ -130,7 +130,7 @@ pub struct ContractDefinition { #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(rename_all = "SCREAMING_SNAKE_CASE")] -#[cfg_attr(test, serde(deny_unknown_fields))] +#[cfg_attr(feature = "no_unknown_fields", serde(deny_unknown_fields))] pub struct EntryPointsByType { pub constructor: Vec, pub external: Vec, @@ -139,7 +139,7 @@ pub struct EntryPointsByType { #[serde_as] #[derive(Debug, Clone, Serialize, Deserialize)] -#[cfg_attr(test, serde(deny_unknown_fields))] +#[cfg_attr(feature = "no_unknown_fields", serde(deny_unknown_fields))] pub struct EntryPoint { #[serde_as(as = "UfeHex")] pub offset: FieldElement, diff --git a/starknet-providers/Cargo.toml b/starknet-providers/Cargo.toml index 8546bad8..8c909e5b 100644 --- a/starknet-providers/Cargo.toml +++ b/starknet-providers/Cargo.toml @@ -25,4 +25,9 @@ serde_with = "1.12.0" [dev-dependencies] flate2 = "1.0.22" +starknet-providers = { path = ".", features = ["no_unknown_fields"] } tokio = { version = "1.15.0", features = ["full"] } + +[features] +default = [] +no_unknown_fields = [] diff --git a/starknet-providers/src/jsonrpc/models/codegen.rs b/starknet-providers/src/jsonrpc/models/codegen.rs index f6bd67cf..6d6600cb 100644 --- a/starknet-providers/src/jsonrpc/models/codegen.rs +++ b/starknet-providers/src/jsonrpc/models/codegen.rs @@ -3,7 +3,7 @@ // https://github.com/xJonathanLEI/starknet-jsonrpc-codegen // Code generated with version: -// https://github.com/xJonathanLEI/starknet-jsonrpc-codegen#c75e6067c10b9f1161f99657e9c9819528bc96a6 +// https://github.com/xJonathanLEI/starknet-jsonrpc-codegen#275a28e3b6efb7f05216e643a73c9f51ee7d658f // Code generation requested but not implemented for these types: // - `BLOCK_ID` @@ -25,6 +25,7 @@ use starknet_core::{ use super::{serde_impls::NumAsHex, *}; #[derive(Debug, Clone, Serialize, Deserialize)] +#[cfg_attr(feature = "no_unknown_fields", serde(deny_unknown_fields))] pub struct ResultPageRequest { /// A pointer to the last element of the delivered page, use this token in a subsequent query to /// obtain the next page @@ -38,6 +39,7 @@ pub struct ResultPageRequest { /// Event information decorated with metadata on where it was emitted. #[serde_as] #[derive(Debug, Clone, Serialize, Deserialize)] +#[cfg_attr(feature = "no_unknown_fields", serde(deny_unknown_fields))] pub struct EmittedEvent { #[serde_as(as = "UfeHex")] pub from_address: FieldElement, @@ -58,6 +60,7 @@ pub struct EmittedEvent { /// A StarkNet event. #[serde_as] #[derive(Debug, Clone, Serialize, Deserialize)] +#[cfg_attr(feature = "no_unknown_fields", serde(deny_unknown_fields))] pub struct Event { #[serde_as(as = "UfeHex")] pub from_address: FieldElement, @@ -99,6 +102,7 @@ pub enum BlockTag { /// An object describing the node synchronization status. #[serde_as] #[derive(Debug, Clone, Serialize, Deserialize)] +#[cfg_attr(feature = "no_unknown_fields", serde(deny_unknown_fields))] pub struct SyncStatus { /// The hash of the block from which the sync started #[serde_as(as = "UfeHex")] @@ -122,6 +126,7 @@ pub struct SyncStatus { #[serde_as] #[derive(Debug, Clone, Serialize, Deserialize)] +#[cfg_attr(feature = "no_unknown_fields", serde(deny_unknown_fields))] pub struct StateUpdate { #[serde_as(as = "UfeHex")] pub block_hash: FieldElement, @@ -138,6 +143,7 @@ pub struct StateUpdate { #[serde_as] #[derive(Debug, Clone, Serialize, Deserialize)] +#[cfg_attr(feature = "no_unknown_fields", serde(deny_unknown_fields))] pub struct StateDiff { pub storage_diffs: Vec, #[serde_as(as = "Vec")] @@ -148,6 +154,7 @@ pub struct StateDiff { #[serde_as] #[derive(Debug, Clone, Serialize, Deserialize)] +#[cfg_attr(feature = "no_unknown_fields", serde(deny_unknown_fields))] pub struct NonceUpdate { /// The address of the contract #[serde_as(as = "UfeHex")] @@ -160,6 +167,7 @@ pub struct NonceUpdate { /// The block object. #[serde_as] #[derive(Debug, Clone, Serialize, Deserialize)] +#[cfg_attr(feature = "no_unknown_fields", serde(deny_unknown_fields))] pub struct BlockWithTxHashes { pub status: BlockStatus, #[serde_as(as = "UfeHex")] @@ -185,6 +193,7 @@ pub struct BlockWithTxHashes { /// The block object. #[serde_as] #[derive(Debug, Clone, Serialize, Deserialize)] +#[cfg_attr(feature = "no_unknown_fields", serde(deny_unknown_fields))] pub struct BlockWithTxs { pub status: BlockStatus, #[serde_as(as = "UfeHex")] @@ -210,6 +219,7 @@ pub struct BlockWithTxs { /// upon decentralization. #[serde_as] #[derive(Debug, Clone, Serialize, Deserialize)] +#[cfg_attr(feature = "no_unknown_fields", serde(deny_unknown_fields))] pub struct PendingBlockWithTxHashes { /// The hashes of the transactions included in this block #[serde_as(as = "Vec")] @@ -228,6 +238,7 @@ pub struct PendingBlockWithTxHashes { /// upon decentralization. #[serde_as] #[derive(Debug, Clone, Serialize, Deserialize)] +#[cfg_attr(feature = "no_unknown_fields", serde(deny_unknown_fields))] pub struct PendingBlockWithTxs { /// The transactions in this block pub transactions: Vec, @@ -243,6 +254,7 @@ pub struct PendingBlockWithTxs { #[serde_as] #[derive(Debug, Clone, Serialize, Deserialize)] +#[cfg_attr(feature = "no_unknown_fields", serde(deny_unknown_fields))] pub struct DeployedContractItem { /// The address of the contract #[serde_as(as = "UfeHex")] @@ -254,6 +266,7 @@ pub struct DeployedContractItem { #[serde_as] #[derive(Debug, Clone, Serialize, Deserialize)] +#[cfg_attr(feature = "no_unknown_fields", serde(deny_unknown_fields))] pub struct ContractStorageDiffItem { /// The contract address for which the storage changed #[serde_as(as = "UfeHex")] @@ -264,6 +277,7 @@ pub struct ContractStorageDiffItem { #[serde_as] #[derive(Debug, Clone, Serialize, Deserialize)] +#[cfg_attr(feature = "no_unknown_fields", serde(deny_unknown_fields))] pub struct StorageEntry { /// The key of the changed value #[serde_as(as = "UfeHex")] @@ -599,6 +613,7 @@ pub struct PendingL1HandlerTransactionReceipt { #[serde_as] #[derive(Debug, Clone, Serialize, Deserialize)] +#[cfg_attr(feature = "no_unknown_fields", serde(deny_unknown_fields))] pub struct MsgToL1 { /// The target L1 address the message is sent to #[serde_as(as = "UfeHex")] @@ -637,6 +652,7 @@ pub enum BlockStatus { /// Function call information. #[serde_as] #[derive(Debug, Clone, Serialize, Deserialize)] +#[cfg_attr(feature = "no_unknown_fields", serde(deny_unknown_fields))] pub struct FunctionCall { #[serde_as(as = "UfeHex")] pub contract_address: FieldElement, @@ -649,6 +665,7 @@ pub struct FunctionCall { /// The definition of a StarkNet contract class. #[derive(Debug, Clone, Serialize, Deserialize)] +#[cfg_attr(feature = "no_unknown_fields", serde(deny_unknown_fields))] pub struct ContractClass { /// A base64 representation of the compressed program code #[serde(with = "base64")] @@ -659,6 +676,7 @@ pub struct ContractClass { } #[derive(Debug, Clone, Serialize, Deserialize)] +#[cfg_attr(feature = "no_unknown_fields", serde(deny_unknown_fields))] pub struct EntryPointsByType { #[serde(rename = "CONSTRUCTOR")] pub constructor: Vec, @@ -670,6 +688,7 @@ pub struct EntryPointsByType { #[serde_as] #[derive(Debug, Clone, Serialize, Deserialize)] +#[cfg_attr(feature = "no_unknown_fields", serde(deny_unknown_fields))] pub struct ContractEntryPoint { /// The offset of the entry point in the program #[serde_as(as = "NumAsHex")] @@ -702,6 +721,7 @@ pub enum FunctionAbiType { } #[derive(Debug, Clone, Serialize, Deserialize)] +#[cfg_attr(feature = "no_unknown_fields", serde(deny_unknown_fields))] pub struct StructAbiEntry { pub r#type: StructAbiType, /// The struct name @@ -711,6 +731,7 @@ pub struct StructAbiEntry { } #[derive(Debug, Clone, Serialize, Deserialize)] +#[cfg_attr(feature = "no_unknown_fields", serde(deny_unknown_fields))] pub struct StructMember { /// The parameter's name pub name: String, @@ -721,6 +742,7 @@ pub struct StructMember { } #[derive(Debug, Clone, Serialize, Deserialize)] +#[cfg_attr(feature = "no_unknown_fields", serde(deny_unknown_fields))] pub struct EventAbiEntry { pub r#type: EventAbiType, /// The event name @@ -739,6 +761,7 @@ pub struct FunctionAbiEntry { } #[derive(Debug, Clone, Serialize, Deserialize)] +#[cfg_attr(feature = "no_unknown_fields", serde(deny_unknown_fields))] pub struct TypedParameter { /// The parameter's name pub name: String, @@ -748,6 +771,7 @@ pub struct TypedParameter { #[serde_as] #[derive(Debug, Clone, Serialize, Deserialize)] +#[cfg_attr(feature = "no_unknown_fields", serde(deny_unknown_fields))] pub struct FeeEstimate { /// The Ethereum gas cost of the transaction (see /// https://docs.starknet.io/docs/fees/fee-mechanism for more info) @@ -802,6 +826,7 @@ impl<'de> Deserialize<'de> for DeclareTransaction { fn deserialize>(deserializer: D) -> Result { #[serde_as] #[derive(Deserialize)] + #[cfg_attr(feature = "no_unknown_fields", serde(deny_unknown_fields))] struct Tagged { #[serde_as(as = "UfeHex")] pub transaction_hash: FieldElement, @@ -878,6 +903,7 @@ impl<'de> Deserialize<'de> for BroadcastedDeclareTransaction { fn deserialize>(deserializer: D) -> Result { #[serde_as] #[derive(Deserialize)] + #[cfg_attr(feature = "no_unknown_fields", serde(deny_unknown_fields))] struct Tagged { #[serde(default, skip_serializing_if = "Option::is_none")] pub r#type: Option, @@ -957,6 +983,7 @@ impl<'de> Deserialize<'de> for DeployAccountTransaction { fn deserialize>(deserializer: D) -> Result { #[serde_as] #[derive(Deserialize)] + #[cfg_attr(feature = "no_unknown_fields", serde(deny_unknown_fields))] struct Tagged { #[serde_as(as = "UfeHex")] pub transaction_hash: FieldElement, @@ -1040,6 +1067,7 @@ impl<'de> Deserialize<'de> for BroadcastedDeployAccountTransaction { fn deserialize>(deserializer: D) -> Result { #[serde_as] #[derive(Deserialize)] + #[cfg_attr(feature = "no_unknown_fields", serde(deny_unknown_fields))] struct Tagged { #[serde(default, skip_serializing_if = "Option::is_none")] pub r#type: Option, @@ -1114,6 +1142,7 @@ impl<'de> Deserialize<'de> for DeployTransaction { fn deserialize>(deserializer: D) -> Result { #[serde_as] #[derive(Deserialize)] + #[cfg_attr(feature = "no_unknown_fields", serde(deny_unknown_fields))] struct Tagged { #[serde_as(as = "UfeHex")] pub transaction_hash: FieldElement, @@ -1178,6 +1207,7 @@ impl<'de> Deserialize<'de> for BroadcastedDeployTransaction { fn deserialize>(deserializer: D) -> Result { #[serde_as] #[derive(Deserialize)] + #[cfg_attr(feature = "no_unknown_fields", serde(deny_unknown_fields))] struct Tagged { pub contract_class: ContractClass, #[serde_as(as = "NumAsHex")] @@ -1251,6 +1281,7 @@ impl<'de> Deserialize<'de> for InvokeTransactionV0 { fn deserialize>(deserializer: D) -> Result { #[serde_as] #[derive(Deserialize)] + #[cfg_attr(feature = "no_unknown_fields", serde(deny_unknown_fields))] struct Tagged { #[serde_as(as = "UfeHex")] pub transaction_hash: FieldElement, @@ -1340,6 +1371,7 @@ impl<'de> Deserialize<'de> for InvokeTransactionV1 { fn deserialize>(deserializer: D) -> Result { #[serde_as] #[derive(Deserialize)] + #[cfg_attr(feature = "no_unknown_fields", serde(deny_unknown_fields))] struct Tagged { #[serde_as(as = "UfeHex")] pub transaction_hash: FieldElement, @@ -1426,6 +1458,7 @@ impl<'de> Deserialize<'de> for BroadcastedInvokeTransactionV0 { fn deserialize>(deserializer: D) -> Result { #[serde_as] #[derive(Deserialize)] + #[cfg_attr(feature = "no_unknown_fields", serde(deny_unknown_fields))] struct Tagged { #[serde(default, skip_serializing_if = "Option::is_none")] pub r#type: Option, @@ -1509,6 +1542,7 @@ impl<'de> Deserialize<'de> for BroadcastedInvokeTransactionV1 { fn deserialize>(deserializer: D) -> Result { #[serde_as] #[derive(Deserialize)] + #[cfg_attr(feature = "no_unknown_fields", serde(deny_unknown_fields))] struct Tagged { #[serde(default, skip_serializing_if = "Option::is_none")] pub r#type: Option, @@ -1589,6 +1623,7 @@ impl<'de> Deserialize<'de> for L1HandlerTransaction { fn deserialize>(deserializer: D) -> Result { #[serde_as] #[derive(Deserialize)] + #[cfg_attr(feature = "no_unknown_fields", serde(deny_unknown_fields))] struct Tagged { #[serde_as(as = "UfeHex")] pub transaction_hash: FieldElement, @@ -1662,6 +1697,7 @@ impl<'de> Deserialize<'de> for InvokeTransactionReceipt { fn deserialize>(deserializer: D) -> Result { #[serde_as] #[derive(Deserialize)] + #[cfg_attr(feature = "no_unknown_fields", serde(deny_unknown_fields))] struct Tagged { #[serde_as(as = "UfeHex")] pub transaction_hash: FieldElement, @@ -1734,6 +1770,7 @@ impl<'de> Deserialize<'de> for DeclareTransactionReceipt { fn deserialize>(deserializer: D) -> Result { #[serde_as] #[derive(Deserialize)] + #[cfg_attr(feature = "no_unknown_fields", serde(deny_unknown_fields))] struct Tagged { #[serde_as(as = "UfeHex")] pub transaction_hash: FieldElement, @@ -1809,6 +1846,7 @@ impl<'de> Deserialize<'de> for DeployAccountTransactionReceipt { fn deserialize>(deserializer: D) -> Result { #[serde_as] #[derive(Deserialize)] + #[cfg_attr(feature = "no_unknown_fields", serde(deny_unknown_fields))] struct Tagged { #[serde_as(as = "UfeHex")] pub transaction_hash: FieldElement, @@ -1887,6 +1925,7 @@ impl<'de> Deserialize<'de> for DeployTransactionReceipt { fn deserialize>(deserializer: D) -> Result { #[serde_as] #[derive(Deserialize)] + #[cfg_attr(feature = "no_unknown_fields", serde(deny_unknown_fields))] struct Tagged { #[serde_as(as = "UfeHex")] pub transaction_hash: FieldElement, @@ -1962,6 +2001,7 @@ impl<'de> Deserialize<'de> for L1HandlerTransactionReceipt { fn deserialize>(deserializer: D) -> Result { #[serde_as] #[derive(Deserialize)] + #[cfg_attr(feature = "no_unknown_fields", serde(deny_unknown_fields))] struct Tagged { #[serde_as(as = "UfeHex")] pub transaction_hash: FieldElement, @@ -2027,6 +2067,7 @@ impl<'de> Deserialize<'de> for PendingInvokeTransactionReceipt { fn deserialize>(deserializer: D) -> Result { #[serde_as] #[derive(Deserialize)] + #[cfg_attr(feature = "no_unknown_fields", serde(deny_unknown_fields))] struct Tagged { #[serde_as(as = "UfeHex")] pub transaction_hash: FieldElement, @@ -2085,6 +2126,7 @@ impl<'de> Deserialize<'de> for PendingDeclareTransactionReceipt { fn deserialize>(deserializer: D) -> Result { #[serde_as] #[derive(Deserialize)] + #[cfg_attr(feature = "no_unknown_fields", serde(deny_unknown_fields))] struct Tagged { #[serde_as(as = "UfeHex")] pub transaction_hash: FieldElement, @@ -2143,6 +2185,7 @@ impl<'de> Deserialize<'de> for PendingDeployAccountTransactionReceipt { fn deserialize>(deserializer: D) -> Result { #[serde_as] #[derive(Deserialize)] + #[cfg_attr(feature = "no_unknown_fields", serde(deny_unknown_fields))] struct Tagged { #[serde_as(as = "UfeHex")] pub transaction_hash: FieldElement, @@ -2204,6 +2247,7 @@ impl<'de> Deserialize<'de> for PendingDeployTransactionReceipt { fn deserialize>(deserializer: D) -> Result { #[serde_as] #[derive(Deserialize)] + #[cfg_attr(feature = "no_unknown_fields", serde(deny_unknown_fields))] struct Tagged { #[serde_as(as = "UfeHex")] pub transaction_hash: FieldElement, @@ -2265,6 +2309,7 @@ impl<'de> Deserialize<'de> for PendingL1HandlerTransactionReceipt { fn deserialize>(deserializer: D) -> Result { #[serde_as] #[derive(Deserialize)] + #[cfg_attr(feature = "no_unknown_fields", serde(deny_unknown_fields))] struct Tagged { #[serde_as(as = "UfeHex")] pub transaction_hash: FieldElement,