Skip to content

Commit

Permalink
feat: optional feature no_unknown_fields (xJonathanLEI#267)
Browse files Browse the repository at this point in the history
  • Loading branch information
xJonathanLEI authored Jan 11, 2023
1 parent a6d864f commit d35867a
Show file tree
Hide file tree
Showing 17 changed files with 118 additions and 63 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
2 changes: 2 additions & 0 deletions starknet-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,15 @@ 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"

[features]
default = ["bigdecimal"]
bigdecimal = ["starknet-ff/bigdecimal"]
no_unknown_fields = []

[[bench]]
name = "class_hash"
Expand Down
4 changes: 2 additions & 2 deletions starknet-core/src/types/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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")]
Expand Down
2 changes: 1 addition & 1 deletion starknet-core/src/types/call_contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<UfeHex>")]
pub result: Vec<FieldElement>,
Expand Down
2 changes: 1 addition & 1 deletion starknet-core/src/types/contract_addresses.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
30 changes: 15 additions & 15 deletions starknet-core/src/types/contract_artifact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<AbiEntry>,
pub entry_points_by_type: EntryPointsByType,
Expand All @@ -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<Vec<Attribute>>,
Expand All @@ -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<String>,
pub end_pc: u64,
Expand All @@ -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.
Expand All @@ -84,15 +84,15 @@ 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<String>,
pub code: String,
pub flow_tracking_data: FlowTrackingData,
}

#[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<Vec<String>>,
Expand All @@ -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<Reference>,
}

#[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<String>,
// This field is serialized as `null` instead of skipped
Expand All @@ -132,37 +132,37 @@ 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,
pub value: String,
}

#[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<String, u64>,
}

#[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
pub n_prefix_newlines: u64,
}

#[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,
Expand All @@ -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<String>,
Expand Down
10 changes: 5 additions & 5 deletions starknet-core/src/types/contract_code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<UfeHex>")]
pub bytecode: Vec<FieldElement>,
Expand Down Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions starknet-core/src/types/fee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions starknet-core/src/types/starknet_error.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions starknet-core/src/types/state_update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<UfeHex>")]
Expand All @@ -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<UfeHex, _>")]
pub storage_diffs: HashMap<FieldElement, Vec<StorageDiff>>,
Expand All @@ -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,
Expand All @@ -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,
Expand Down
14 changes: 7 additions & 7 deletions starknet-core/src/types/trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ 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<TransactionTraceWithHash>,
}

/// 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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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<UfeHex>")]
Expand All @@ -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,
Expand Down
Loading

0 comments on commit d35867a

Please sign in to comment.