diff --git a/crates/rpc/src/dto/block.rs b/crates/rpc/src/dto/block.rs index e1fa127cb6..7f195b69e5 100644 --- a/crates/rpc/src/dto/block.rs +++ b/crates/rpc/src/dto/block.rs @@ -4,12 +4,6 @@ use serde::de::Error; use crate::dto::SerializeStruct; use crate::{Reorg, RpcVersion}; -#[derive(Debug)] -pub struct BlockHeader<'a>(pub &'a pathfinder_common::BlockHeader); - -#[derive(Debug)] -pub struct PendingBlockHeader<'a>(pub &'a starknet_gateway_types::reply::PendingBlock); - impl crate::dto::DeserializeForVersion for pathfinder_common::BlockId { fn deserialize(value: super::Value) -> Result { if value.is_string() { @@ -38,48 +32,45 @@ impl crate::dto::DeserializeForVersion for pathfinder_common::BlockId { } } -impl crate::dto::SerializeForVersion for BlockHeader<'_> { +impl crate::dto::SerializeForVersion for pathfinder_common::BlockHeader { fn serialize( &self, serializer: crate::dto::Serializer, ) -> Result { let mut serializer = serializer.serialize_struct()?; - serializer.serialize_field("block_hash", &crate::dto::Felt(&self.0.hash.0))?; - serializer.serialize_field("parent_hash", &crate::dto::Felt(&self.0.parent_hash.0))?; - serializer.serialize_field("block_number", &self.0.number.get())?; - serializer.serialize_field("new_root", &crate::dto::Felt(&self.0.state_commitment.0))?; - serializer.serialize_field("timestamp", &self.0.timestamp.get())?; - serializer.serialize_field( - "sequencer_address", - &crate::dto::Felt(&self.0.sequencer_address.0), - )?; + serializer.serialize_field("block_hash", &self.hash)?; + serializer.serialize_field("parent_hash", &self.parent_hash)?; + serializer.serialize_field("block_number", &self.number.get())?; + serializer.serialize_field("new_root", &self.state_commitment)?; + serializer.serialize_field("timestamp", &self.timestamp.get())?; + serializer.serialize_field("sequencer_address", &self.sequencer_address)?; serializer.serialize_field( "l1_gas_price", &ResourcePrice { - price_in_wei: self.0.eth_l1_gas_price, - price_in_fri: self.0.strk_l1_gas_price, + price_in_wei: self.eth_l1_gas_price, + price_in_fri: self.strk_l1_gas_price, }, )?; - serializer.serialize_field("starknet_version", &self.0.starknet_version.to_string())?; + serializer.serialize_field("starknet_version", &self.starknet_version.to_string())?; serializer.serialize_field( "l1_data_gas_price", &ResourcePrice { - price_in_wei: self.0.eth_l1_data_gas_price, - price_in_fri: self.0.strk_l1_data_gas_price, + price_in_wei: self.eth_l1_data_gas_price, + price_in_fri: self.strk_l1_data_gas_price, }, )?; if serializer.version == RpcVersion::V08 { serializer.serialize_field( "l2_gas_price", &ResourcePrice { - price_in_wei: self.0.eth_l2_gas_price, - price_in_fri: self.0.strk_l2_gas_price, + price_in_wei: self.eth_l2_gas_price, + price_in_fri: self.strk_l2_gas_price, }, )?; } serializer.serialize_field( "l1_da_mode", - &match self.0.l1_da_mode { + &match self.l1_da_mode { L1DataAvailabilityMode::Blob => "BLOB", L1DataAvailabilityMode::Calldata => "CALLDATA", }, @@ -88,45 +79,42 @@ impl crate::dto::SerializeForVersion for BlockHeader<'_> { } } -impl crate::dto::SerializeForVersion for PendingBlockHeader<'_> { +impl crate::dto::SerializeForVersion for starknet_gateway_types::reply::PendingBlock { fn serialize( &self, serializer: crate::dto::Serializer, ) -> Result { let mut serializer = serializer.serialize_struct()?; - serializer.serialize_field("parent_hash", &crate::dto::Felt(&self.0.parent_hash.0))?; - serializer.serialize_field("timestamp", &self.0.timestamp.get())?; - serializer.serialize_field( - "sequencer_address", - &crate::dto::Felt(&self.0.sequencer_address.0), - )?; + serializer.serialize_field("parent_hash", &self.parent_hash)?; + serializer.serialize_field("timestamp", &self.timestamp.get())?; + serializer.serialize_field("sequencer_address", &self.sequencer_address)?; serializer.serialize_field( "l1_gas_price", &ResourcePrice { - price_in_wei: self.0.l1_gas_price.price_in_wei, - price_in_fri: self.0.l1_gas_price.price_in_fri, + price_in_wei: self.l1_gas_price.price_in_wei, + price_in_fri: self.l1_gas_price.price_in_fri, }, )?; - serializer.serialize_field("starknet_version", &self.0.starknet_version.to_string())?; + serializer.serialize_field("starknet_version", &self.starknet_version.to_string())?; serializer.serialize_field( "l1_data_gas_price", &ResourcePrice { - price_in_wei: self.0.l1_data_gas_price.price_in_wei, - price_in_fri: self.0.l1_data_gas_price.price_in_fri, + price_in_wei: self.l1_data_gas_price.price_in_wei, + price_in_fri: self.l1_data_gas_price.price_in_fri, }, )?; if serializer.version == RpcVersion::V08 { serializer.serialize_field( "l2_gas_price", &ResourcePrice { - price_in_wei: self.0.l2_gas_price.price_in_wei, - price_in_fri: self.0.l2_gas_price.price_in_fri, + price_in_wei: self.l2_gas_price.price_in_wei, + price_in_fri: self.l2_gas_price.price_in_fri, }, )?; } serializer.serialize_field( "l1_da_mode", - &match self.0.l1_da_mode { + &match self.l1_da_mode { starknet_gateway_types::reply::L1DataAvailabilityMode::Blob => "BLOB", starknet_gateway_types::reply::L1DataAvailabilityMode::Calldata => "CALLDATA", }, @@ -160,15 +148,9 @@ impl crate::dto::SerializeForVersion for Reorg { ) -> Result { let mut serializer = serializer.serialize_struct()?; serializer.serialize_field("first_block_number", &self.first_block_number.get())?; - serializer.serialize_field( - "first_block_hash", - &crate::dto::Felt(&self.first_block_hash.0), - )?; + serializer.serialize_field("first_block_hash", &self.first_block_hash)?; serializer.serialize_field("last_block_number", &self.last_block_number.get())?; - serializer.serialize_field( - "last_block_hash", - &crate::dto::Felt(&self.last_block_hash.0), - )?; + serializer.serialize_field("last_block_hash", &self.last_block_hash)?; serializer.end() } } diff --git a/crates/rpc/src/dto/class.rs b/crates/rpc/src/dto/class.rs index 6b923e6990..1c9311e1b1 100644 --- a/crates/rpc/src/dto/class.rs +++ b/crates/rpc/src/dto/class.rs @@ -1,37 +1,15 @@ use serde_with::ser::SerializeAsWrap; use super::U64Hex; -use crate::dto::{Felt, SerializeForVersion}; +use crate::dto::SerializeForVersion; use crate::types; -pub struct DeprecatedContractClass<'a>(pub &'a types::CairoContractClass); -pub struct ContractClass<'a>(pub &'a types::SierraContractClass); - -pub struct DeprecatedCairoEntryPoint<'a>(pub &'a types::ContractEntryPoint); -pub struct SierraEntryPoint<'a>(pub &'a types::SierraEntryPoint); - -pub struct ContractAbi<'a>(pub &'a [types::ContractAbiEntry]); -pub struct ContractAbiEntry<'a>(pub &'a types::ContractAbiEntry); -pub struct FunctionAbiEntry<'a>(pub &'a types::FunctionAbiEntry); -pub struct EventAbiEntry<'a>(pub &'a types::EventAbiEntry); -pub struct StructAbiEntry<'a>(pub &'a types::StructAbiEntry); - -pub struct FunctionAbiType(pub types::FunctionAbiType); -pub struct EventAbiType; -pub struct StructAbiType; - -pub struct TypedParameter<'a>(pub &'a types::TypedParameter); -pub struct FunctionStateMutability; -pub struct StructMember<'a>(pub &'a types::StructMember); - -impl SerializeForVersion for DeprecatedContractClass<'_> { +impl SerializeForVersion for types::CairoContractClass { fn serialize( &self, serializer: crate::dto::Serializer, ) -> Result { - struct EntryPointsByType<'a>(&'a types::ContractEntryPoints); - - impl SerializeForVersion for EntryPointsByType<'_> { + impl SerializeForVersion for types::ContractEntryPoints { fn serialize( &self, serializer: crate::dto::Serializer, @@ -40,20 +18,20 @@ impl SerializeForVersion for DeprecatedContractClass<'_> { serializer.serialize_iter( "CONSTRUCTOR", - self.0.constructor.len(), - &mut self.0.constructor.iter().map(DeprecatedCairoEntryPoint), + self.constructor.len(), + &mut self.constructor.iter(), )?; serializer.serialize_iter( "EXTERNAL", - self.0.external.len(), - &mut self.0.external.iter().map(DeprecatedCairoEntryPoint), + self.external.len(), + &mut self.external.iter(), )?; serializer.serialize_iter( "L1_HANDLER", - self.0.l1_handler.len(), - &mut self.0.l1_handler.iter().map(DeprecatedCairoEntryPoint), + self.l1_handler.len(), + &mut self.l1_handler.iter(), )?; serializer.end() @@ -62,25 +40,20 @@ impl SerializeForVersion for DeprecatedContractClass<'_> { let mut serializer = serializer.serialize_struct()?; - serializer.serialize_field("program", &self.0.program)?; - serializer.serialize_field( - "entry_points_by_type", - &EntryPointsByType(&self.0.entry_points_by_type), - )?; - serializer.serialize_optional("abi", self.0.abi.as_ref().map(|x| ContractAbi(x)))?; + serializer.serialize_field("program", &self.program)?; + serializer.serialize_field("entry_points_by_type", &self.entry_points_by_type)?; + serializer.serialize_optional("abi", self.abi)?; serializer.end() } } -impl SerializeForVersion for ContractClass<'_> { +impl SerializeForVersion for types::SierraContractClass { fn serialize( &self, serializer: crate::dto::Serializer, ) -> Result { - struct EntryPointsByType<'a>(&'a types::SierraEntryPoints); - - impl SerializeForVersion for EntryPointsByType<'_> { + impl SerializeForVersion for types::SierraEntryPoints { fn serialize( &self, serializer: crate::dto::Serializer, @@ -89,20 +62,20 @@ impl SerializeForVersion for ContractClass<'_> { serializer.serialize_iter( "CONSTRUCTOR", - self.0.constructor.len(), - &mut self.0.constructor.iter().map(SierraEntryPoint), + self.constructor.len(), + &mut self.constructor.iter(), )?; serializer.serialize_iter( "EXTERNAL", - self.0.external.len(), - &mut self.0.external.iter().map(SierraEntryPoint), + self.external.len(), + &mut self.external.iter(), )?; serializer.serialize_iter( "L1_HANDLER", - self.0.l1_handler.len(), - &mut self.0.l1_handler.iter().map(SierraEntryPoint), + self.l1_handler.len(), + &mut self.l1_handler.iter(), )?; serializer.end() @@ -113,102 +86,90 @@ impl SerializeForVersion for ContractClass<'_> { serializer.serialize_iter( "sierra_program", - self.0.sierra_program.len(), - &mut self.0.sierra_program.iter().map(Felt), + self.sierra_program.len(), + &mut self.sierra_program.iter(), )?; - serializer.serialize_field("contract_class_version", &self.0.contract_class_version)?; - serializer.serialize_field( - "entry_points_by_type", - &EntryPointsByType(&self.0.entry_points_by_type), - )?; + serializer.serialize_field("contract_class_version", &self.contract_class_version)?; + serializer.serialize_field("entry_points_by_type", &self.entry_points_by_type)?; // ABI is optional, so skip if its empty. - let abi = (!self.0.abi.is_empty()).then_some(&self.0.abi); + let abi = (!self.abi.is_empty()).then_some(&self.abi); serializer.serialize_optional("abi", abi)?; serializer.end() } } -impl SerializeForVersion for DeprecatedCairoEntryPoint<'_> { +impl SerializeForVersion for types::ContractEntryPoint { fn serialize( &self, serializer: crate::dto::Serializer, ) -> Result { let mut serializer = serializer.serialize_struct()?; - serializer.serialize_field("offset", &self.0.offset)?; - serializer.serialize_field("selector", &Felt(&self.0.selector))?; + serializer.serialize_field("offset", &self.offset)?; + serializer.serialize_field("selector", &self.selector)?; serializer.end() } } -impl SerializeForVersion for SierraEntryPoint<'_> { +impl SerializeForVersion for types::SierraEntryPoint { fn serialize( &self, serializer: crate::dto::Serializer, ) -> Result { let mut serializer = serializer.serialize_struct()?; - serializer.serialize_field("selector", &Felt(&self.0.selector))?; - serializer.serialize_field("function_idx", &self.0.function_idx)?; + serializer.serialize_field("selector", &self.selector)?; + serializer.serialize_field("function_idx", &self.function_idx)?; serializer.end() } } -impl SerializeForVersion for ContractAbi<'_> { +impl SerializeForVersion for [types::ContractAbiEntry] { fn serialize( &self, serializer: crate::dto::Serializer, ) -> Result { - serializer.serialize_iter(self.0.len(), &mut self.0.iter().map(ContractAbiEntry)) + serializer.serialize_iter(self.len(), &mut self.iter()) } } -impl SerializeForVersion for ContractAbiEntry<'_> { +impl SerializeForVersion for types::ContractAbiEntry { fn serialize( &self, serializer: crate::dto::Serializer, ) -> Result { - match self.0 { - types::ContractAbiEntry::Function(f) => FunctionAbiEntry(f).serialize(serializer), - types::ContractAbiEntry::Event(e) => EventAbiEntry(e).serialize(serializer), - types::ContractAbiEntry::Struct(s) => StructAbiEntry(s).serialize(serializer), + match self { + types::ContractAbiEntry::Function(f) => f.serialize(serializer), + types::ContractAbiEntry::Event(e) => e.serialize(serializer), + types::ContractAbiEntry::Struct(s) => s.serialize(serializer), } } } -impl SerializeForVersion for FunctionAbiEntry<'_> { +impl SerializeForVersion for types::FunctionAbiEntry { fn serialize( &self, serializer: crate::dto::Serializer, ) -> Result { let mut serializer = serializer.serialize_struct()?; - serializer.serialize_field("type", &FunctionAbiType(self.0.r#type))?; - serializer.serialize_field("name", &self.0.name)?; + serializer.serialize_field("type", &self.r#type)?; + serializer.serialize_field("name", &self.name)?; - let inputs = self.0.inputs.as_deref().unwrap_or_default(); - serializer.serialize_iter( - "inputs", - inputs.len(), - &mut inputs.iter().map(TypedParameter), - )?; + let inputs = self.inputs.as_deref().unwrap_or_default(); + serializer.serialize_iter("inputs", inputs.len(), &mut inputs.iter())?; - let outputs = self.0.outputs.as_deref().unwrap_or_default(); - serializer.serialize_iter( - "outputs", - outputs.len(), - &mut outputs.iter().map(TypedParameter), - )?; + let outputs = self.outputs.as_deref().unwrap_or_default(); + serializer.serialize_iter("outputs", outputs.len(), &mut outputs.iter())?; serializer.serialize_optional( "stateMutability", - self.0 - .state_mutability + self.state_mutability .as_ref() .map(|_| FunctionStateMutability), ); @@ -217,7 +178,7 @@ impl SerializeForVersion for FunctionAbiEntry<'_> { } } -impl SerializeForVersion for EventAbiEntry<'_> { +impl SerializeForVersion for types::EventAbiEntry { fn serialize( &self, serializer: crate::dto::Serializer, @@ -225,19 +186,19 @@ impl SerializeForVersion for EventAbiEntry<'_> { let mut serializer = serializer.serialize_struct()?; serializer.serialize_field("type", &EventAbiType)?; - serializer.serialize_field("name", &self.0.name)?; + serializer.serialize_field("name", &self.name)?; - let keys = self.0.keys.as_deref().unwrap_or_default(); - serializer.serialize_iter("keys", keys.len(), &mut keys.iter().map(TypedParameter))?; + let keys = self.keys.as_deref().unwrap_or_default(); + serializer.serialize_iter("keys", keys.len(), &mut keys.iter())?; - let data = self.0.data.as_deref().unwrap_or_default(); - serializer.serialize_iter("data", data.len(), &mut data.iter().map(TypedParameter))?; + let data = self.data.as_deref().unwrap_or_default(); + serializer.serialize_iter("data", data.len(), &mut data.iter())?; serializer.end() } } -impl SerializeForVersion for StructAbiEntry<'_> { +impl SerializeForVersion for types::StructAbiEntry { fn serialize( &self, serializer: crate::dto::Serializer, @@ -245,26 +206,22 @@ impl SerializeForVersion for StructAbiEntry<'_> { let mut serializer = serializer.serialize_struct()?; serializer.serialize_field("type", &StructAbiType)?; - serializer.serialize_field("name", &self.0.name)?; + serializer.serialize_field("name", &self.name)?; // FIXME: this should be a NonZero according to the RPC spec. - serializer.serialize_field("size", &self.0.size)?; + serializer.serialize_field("size", &self.size)?; - serializer.serialize_iter( - "members", - self.0.members.len(), - &mut self.0.members.iter().map(StructMember), - )?; + serializer.serialize_iter("members", self.members.len(), &mut self.members.iter())?; serializer.end() } } -impl SerializeForVersion for FunctionAbiType { +impl SerializeForVersion for types::FunctionAbiType { fn serialize( &self, serializer: crate::dto::Serializer, ) -> Result { - match self.0 { + match self { types::FunctionAbiType::Function => "function", types::FunctionAbiType::L1Handler => "l1_handler", types::FunctionAbiType::Constructor => "constructor", @@ -273,6 +230,8 @@ impl SerializeForVersion for FunctionAbiType { } } +pub struct EventAbiType; + impl SerializeForVersion for EventAbiType { fn serialize( &self, @@ -282,6 +241,8 @@ impl SerializeForVersion for EventAbiType { } } +pub struct StructAbiType; + impl SerializeForVersion for StructAbiType { fn serialize( &self, @@ -291,30 +252,32 @@ impl SerializeForVersion for StructAbiType { } } -impl SerializeForVersion for TypedParameter<'_> { +pub struct FunctionStateMutability; + +impl SerializeForVersion for FunctionStateMutability { fn serialize( &self, serializer: crate::dto::Serializer, ) -> Result { - let mut serializer = serializer.serialize_struct()?; - - serializer.serialize_field("name", &self.0.name)?; - serializer.serialize_field("type", &self.0.r#type)?; - - serializer.end() + serializer.serialize_str("view") } } -impl SerializeForVersion for FunctionStateMutability { +impl SerializeForVersion for types::TypedParameter { fn serialize( &self, serializer: crate::dto::Serializer, ) -> Result { - serializer.serialize_str("view") + let mut serializer = serializer.serialize_struct()?; + + serializer.serialize_field("name", &self.name)?; + serializer.serialize_field("type", &self.r#type)?; + + serializer.end() } } -impl SerializeForVersion for StructMember<'_> { +impl SerializeForVersion for types::StructMember { fn serialize( &self, serializer: crate::dto::Serializer, @@ -324,11 +287,11 @@ impl SerializeForVersion for StructMember<'_> { // FIXME: these clones could be removed if the types::* definitions were // smarter. let parameter = types::TypedParameter { - name: self.0.typed_parameter_name.clone(), - r#type: self.0.typed_parameter_type.clone(), + name: self.typed_parameter_name.clone(), + r#type: self.typed_parameter_type.clone(), }; - serializer.flatten(&TypedParameter(¶meter))?; - serializer.serialize_field("offset", &self.0.offset)?; + serializer.flatten(¶meter)?; + serializer.serialize_field("offset", &self.offset)?; serializer.end() } diff --git a/crates/rpc/src/dto/event.rs b/crates/rpc/src/dto/event.rs index f803476cc7..24ff581fc4 100644 --- a/crates/rpc/src/dto/event.rs +++ b/crates/rpc/src/dto/event.rs @@ -18,7 +18,7 @@ impl SerializeForVersion for Event<'_> { fn serialize(&self, serializer: Serializer) -> Result { let mut serializer = serializer.serialize_struct()?; - serializer.serialize_field("from_address", &dto::Address(self.address))?; + serializer.serialize_field("from_address", &self.address)?; serializer.flatten(&EventContext { keys: self.keys, data: self.data, @@ -32,16 +32,8 @@ impl SerializeForVersion for EventContext<'_> { fn serialize(&self, serializer: Serializer) -> Result { let mut serializer = serializer.serialize_struct()?; - serializer.serialize_iter( - "keys", - self.keys.len(), - &mut self.keys.iter().map(|x| dto::Felt(&x.0)), - )?; - serializer.serialize_iter( - "data", - self.data.len(), - &mut self.data.iter().map(|x| dto::Felt(&x.0)), - )?; + serializer.serialize_iter("keys", self.keys.len(), &mut self.keys.iter().map(|x| &x.0))?; + serializer.serialize_iter("data", self.data.len(), &mut self.data.iter().map(|x| &x.0))?; serializer.end() } diff --git a/crates/rpc/src/dto/fee.rs b/crates/rpc/src/dto/fee.rs index 208db7f12c..085e426806 100644 --- a/crates/rpc/src/dto/fee.rs +++ b/crates/rpc/src/dto/fee.rs @@ -1,9 +1,6 @@ use super::U256Hex; -#[derive(Debug, PartialEq, Eq)] -pub struct FeeEstimate<'a>(pub &'a pathfinder_executor::types::FeeEstimate); - -impl crate::dto::SerializeForVersion for FeeEstimate<'_> { +impl crate::dto::SerializeForVersion for pathfinder_executor::types::FeeEstimate { fn serialize( &self, serializer: crate::dto::Serializer, @@ -11,40 +8,34 @@ impl crate::dto::SerializeForVersion for FeeEstimate<'_> { let mut serializer = serializer.serialize_struct()?; if serializer.version >= crate::dto::RpcVersion::V08 { - serializer.serialize_field("l1_gas_consumed", &U256Hex(self.0.l1_gas_consumed))?; - serializer.serialize_field("l1_gas_price", &U256Hex(self.0.l1_gas_price))?; - serializer.serialize_field( - "l1_data_gas_consumed", - &U256Hex(self.0.l1_data_gas_consumed), - )?; - serializer.serialize_field("l1_data_gas_price", &U256Hex(self.0.l1_data_gas_price))?; - serializer.serialize_field("l2_gas_consumed", &U256Hex(self.0.l2_gas_consumed))?; - serializer.serialize_field("l2_gas_price", &U256Hex(self.0.l2_gas_price))?; - serializer.serialize_field("overall_fee", &U256Hex(self.0.overall_fee))?; - serializer.serialize_field("unit", &PriceUnit(&self.0.unit))?; - } else { - serializer.serialize_field("gas_price", &U256Hex(self.0.l1_gas_price))?; - serializer.serialize_field("gas_consumed", &U256Hex(self.0.l1_gas_consumed))?; + serializer.serialize_field("l1_gas_consumed", &U256Hex(self.l1_gas_consumed))?; + serializer.serialize_field("l1_gas_price", &U256Hex(self.l1_gas_price))?; serializer - .serialize_field("data_gas_consumed", &U256Hex(self.0.l1_data_gas_consumed))?; - serializer.serialize_field("data_gas_price", &U256Hex(self.0.l1_data_gas_price))?; - serializer.serialize_field("overall_fee", &U256Hex(self.0.overall_fee))?; - serializer.serialize_field("unit", &PriceUnit(&self.0.unit))?; + .serialize_field("l1_data_gas_consumed", &U256Hex(self.l1_data_gas_consumed))?; + serializer.serialize_field("l1_data_gas_price", &U256Hex(self.l1_data_gas_price))?; + serializer.serialize_field("l2_gas_consumed", &U256Hex(self.l2_gas_consumed))?; + serializer.serialize_field("l2_gas_price", &U256Hex(self.l2_gas_price))?; + serializer.serialize_field("overall_fee", &U256Hex(self.overall_fee))?; + serializer.serialize_field("unit", &self.unit)?; + } else { + serializer.serialize_field("gas_price", &U256Hex(self.l1_gas_price))?; + serializer.serialize_field("gas_consumed", &U256Hex(self.l1_gas_consumed))?; + serializer.serialize_field("data_gas_consumed", &U256Hex(self.l1_data_gas_consumed))?; + serializer.serialize_field("data_gas_price", &U256Hex(self.l1_data_gas_price))?; + serializer.serialize_field("overall_fee", &U256Hex(self.overall_fee))?; + serializer.serialize_field("unit", &self.unit)?; } serializer.end() } } -#[derive(Debug, PartialEq, Eq)] -struct PriceUnit<'a>(&'a pathfinder_executor::types::PriceUnit); - -impl crate::dto::SerializeForVersion for PriceUnit<'_> { +impl crate::dto::SerializeForVersion for pathfinder_executor::types::PriceUnit { fn serialize( &self, serializer: crate::dto::Serializer, ) -> Result { - serializer.serialize_str(match self.0 { + serializer.serialize_str(match self { pathfinder_executor::types::PriceUnit::Wei => "WEI", pathfinder_executor::types::PriceUnit::Fri => "FRI", }) diff --git a/crates/rpc/src/dto/primitives.rs b/crates/rpc/src/dto/primitives.rs index bbae94ae1d..2fe8c44533 100644 --- a/crates/rpc/src/dto/primitives.rs +++ b/crates/rpc/src/dto/primitives.rs @@ -7,7 +7,6 @@ use crate::dto::{self, Serializer}; pub struct SyncStatus<'a>(pub &'a crate::types::syncing::Status); -pub struct Felt<'a>(pub &'a pathfinder_crypto::Felt); pub struct BlockHash<'a>(pub &'a pathfinder_common::BlockHash); pub struct ChainId<'a>(pub &'a pathfinder_common::ChainId); pub struct BlockNumber(pub pathfinder_common::BlockNumber); @@ -230,22 +229,22 @@ impl DeserializeForVersion for U64Hex { } } -impl SerializeForVersion for SyncStatus<'_> { +impl SerializeForVersion for crate::types::syncing::Status { fn serialize(&self, serializer: Serializer) -> Result { let mut serializer = serializer.serialize_struct()?; - serializer.serialize_field("starting_block_hash", &BlockHash(&self.0.starting.hash))?; - serializer.serialize_field("starting_block_num", &BlockNumber(self.0.starting.number))?; - serializer.serialize_field("current_block_hash", &BlockHash(&self.0.current.hash))?; - serializer.serialize_field("current_block_num", &BlockNumber(self.0.current.number))?; - serializer.serialize_field("highest_block_hash", &BlockHash(&self.0.highest.hash))?; - serializer.serialize_field("highest_block_num", &BlockNumber(self.0.highest.number))?; + serializer.serialize_field("starting_block_hash", &self.starting.hash)?; + serializer.serialize_field("starting_block_num", &self.starting.number)?; + serializer.serialize_field("current_block_hash", &self.current.hash)?; + serializer.serialize_field("current_block_num", &self.current.number)?; + serializer.serialize_field("highest_block_hash", &self.highest.hash)?; + serializer.serialize_field("highest_block_num", &self.highest.number)?; serializer.end() } } -impl SerializeForVersion for Felt<'_> { +impl SerializeForVersion for pathfinder_crypto::Felt { fn serialize(&self, serializer: Serializer) -> Result { - let hex_str = hex_str::bytes_to_hex_str_stripped(self.0.as_be_bytes()); + let hex_str = hex_str::bytes_to_hex_str_stripped(self.as_be_bytes()); serializer.serialize_str(&hex_str) } } @@ -264,15 +263,15 @@ impl DeserializeForVersion for pathfinder_crypto::Felt { } } -impl SerializeForVersion for BlockHash<'_> { +impl SerializeForVersion for pathfinder_common::BlockHash { fn serialize(&self, serializer: Serializer) -> Result { - serializer.serialize(&Felt(&self.0 .0)) + serializer.serialize(&self.0) } } -impl SerializeForVersion for ChainId<'_> { +impl SerializeForVersion for pathfinder_common::ChainId { fn serialize(&self, serializer: Serializer) -> Result { - let hex_str = hex_str::bytes_to_hex_str_stripped(self.0 .0.as_be_bytes()); + let hex_str = hex_str::bytes_to_hex_str_stripped(self.0.as_be_bytes()); serializer.serialize_str(&hex_str) } } @@ -354,9 +353,9 @@ impl DeserializeForVersion for pathfinder_common::EthereumAddress { } } -impl SerializeForVersion for Address<'_> { +impl SerializeForVersion for pathfinder_common::ContractAddress { fn serialize(&self, serializer: Serializer) -> Result { - serializer.serialize(&Felt(&self.0 .0)) + serializer.serialize(&self.0) } } @@ -379,7 +378,7 @@ mod tests { #[test] fn felt() { - let uut = Felt(&felt!("0x1234")); + let uut = &felt!("0x1234"); let expected = json!("0x1234"); let encoded = uut.serialize(Default::default()).unwrap(); @@ -389,8 +388,8 @@ mod tests { #[test] fn block_hash() { let hash = block_hash!("0x1234"); - let expected = Felt(&hash.0).serialize(Default::default()).unwrap(); - let encoded = BlockHash(&hash).serialize(Default::default()).unwrap(); + let expected = &hash.0.serialize(Default::default()).unwrap(); + let encoded = &hash.serialize(Default::default()).unwrap(); assert_eq!(encoded, expected); } @@ -399,7 +398,7 @@ mod tests { fn block_number() { let number = pathfinder_common::BlockNumber::new_or_panic(1234); let expected = json!(1234); - let encoded = BlockNumber(number).serialize(Default::default()).unwrap(); + let encoded = number.serialize(Default::default()).unwrap(); assert_eq!(encoded, expected); } @@ -425,22 +424,22 @@ mod tests { let s = Serializer::default(); let expected = json!({ - "starting_block_hash": BlockHash(&status.starting.hash).serialize(s).unwrap(), - "current_block_hash": BlockHash(&status.current.hash).serialize(s).unwrap(), - "highest_block_hash": BlockHash(&status.highest.hash).serialize(s).unwrap(), - "starting_block_num": BlockNumber(status.starting.number).serialize(s).unwrap(), - "current_block_num": BlockNumber(status.current.number).serialize(s).unwrap(), - "highest_block_num": BlockNumber(status.highest.number).serialize(s).unwrap(), + "starting_block_hash": &status.starting.hash.serialize(s).unwrap(), + "current_block_hash": &status.current.hash.serialize(s).unwrap(), + "highest_block_hash": &status.highest.hash.serialize(s).unwrap(), + "starting_block_num": status.starting.number.serialize(s).unwrap(), + "current_block_num": status.current.number.serialize(s).unwrap(), + "highest_block_num": status.highest.number.serialize(s).unwrap(), }); - let encoded = SyncStatus(&status).serialize(s).unwrap(); + let encoded = status.serialize(s).unwrap(); assert_eq!(encoded, expected); } #[test] fn chain_id() { - let uut = ChainId(&pathfinder_common::ChainId(felt!("0x1234"))); + let uut = pathfinder_common::ChainId(felt!("0x1234")); let expected = json!("0x1234"); let encoded = uut.serialize(Default::default()).unwrap(); diff --git a/crates/rpc/src/dto/receipt.rs b/crates/rpc/src/dto/receipt.rs index ee05fc4748..68894b02cd 100644 --- a/crates/rpc/src/dto/receipt.rs +++ b/crates/rpc/src/dto/receipt.rs @@ -157,8 +157,8 @@ impl SerializeForVersion for TxnReceiptWithBlockInfo<'_> { finality: *finality, })?; - serializer.serialize_optional("block_hash", block_hash.map(dto::BlockHash))?; - serializer.serialize_optional("block_number", block_number.map(dto::BlockNumber))?; + serializer.serialize_optional("block_hash", *block_hash)?; + serializer.serialize_optional("block_number", *block_number)?; serializer.end() } @@ -211,7 +211,7 @@ impl SerializeForVersion for DeployTxnReceipt<'_> { serializer.flatten(&CommonReceiptProperties(self.0))?; serializer.serialize_field("type", &"DEPLOY")?; - serializer.serialize_field("contract_address", &dto::Felt(&contract_address.0))?; + serializer.serialize_field("contract_address", &contract_address)?; serializer.end() } @@ -241,7 +241,7 @@ impl SerializeForVersion for DeployAccountTxnReceipt<'_> { serializer.flatten(&CommonReceiptProperties(self.0))?; serializer.serialize_field("type", &"DEPLOY_ACCOUNT")?; - serializer.serialize_field("contract_address", &dto::Felt(&contract_address.0))?; + serializer.serialize_field("contract_address", &contract_address)?; serializer.end() } @@ -297,7 +297,7 @@ impl SerializeForVersion for CommonReceiptProperties<'_> { fn serialize(&self, serializer: Serializer) -> Result { let mut serializer = serializer.serialize_struct()?; - serializer.serialize_field("transaction_hash", &dto::TxnHash(&self.0.transaction.hash))?; + serializer.serialize_field("transaction_hash", &self.0.transaction.hash)?; serializer.serialize_field( "actual_fee", &FeePayment { @@ -336,7 +336,7 @@ impl SerializeForVersion for FeePayment<'_> { fn serialize(&self, serializer: Serializer) -> Result { let mut serializer = serializer.serialize_struct()?; - serializer.serialize_field("amount", &dto::Felt(&self.amount.0))?; + serializer.serialize_field("amount", &self.amount)?; serializer.serialize_field("unit", &PriceUnit(self.transaction_version))?; serializer.end() @@ -347,8 +347,8 @@ impl SerializeForVersion for MsgToL1<'_> { fn serialize(&self, serializer: Serializer) -> Result { let mut serializer = serializer.serialize_struct()?; - serializer.serialize_field("from_address", &dto::Felt(&self.0.from_address.0))?; - serializer.serialize_field("to_address", &dto::Felt(&self.0.to_address.0))?; + serializer.serialize_field("from_address", &self.0.from_address)?; + serializer.serialize_field("to_address", &self.0.to_address)?; serializer.serialize_iter("payload", self.0.payload.len(), &mut self.0.payload.iter())?; serializer.end() diff --git a/crates/rpc/src/dto/simulation.rs b/crates/rpc/src/dto/simulation.rs index 6f24a4e49e..6d375386af 100644 --- a/crates/rpc/src/dto/simulation.rs +++ b/crates/rpc/src/dto/simulation.rs @@ -2,7 +2,7 @@ use anyhow::anyhow; use pathfinder_common::{ContractAddress, ContractNonce}; use serde::ser::Error; -use super::{FeeEstimate, SerializeStruct}; +use super::SerializeStruct; use crate::RpcVersion; #[derive(Debug)] @@ -21,108 +21,71 @@ impl crate::dto::SerializeForVersion for TransactionTrace { pathfinder_executor::types::TransactionTrace::Declare(trace) => { serializer.serialize_field("type", &"DECLARE")?; if let Some(fee_transfer_invocation) = &trace.fee_transfer_invocation { - serializer.serialize_field( - "fee_transfer_invocation", - &FunctionInvocation(fee_transfer_invocation), - )?; + serializer + .serialize_field("fee_transfer_invocation", &fee_transfer_invocation)?; } if let Some(validate_invocation) = &trace.validate_invocation { - serializer.serialize_field( - "validate_invocation", - &FunctionInvocation(validate_invocation), - )?; + serializer.serialize_field("validate_invocation", &validate_invocation)?; } if self.include_state_diff { - serializer.serialize_field("state_diff", &StateDiff(&trace.state_diff))?; + serializer.serialize_field("state_diff", &trace.state_diff)?; } - serializer.serialize_field( - "execution_resources", - &ExecutionResources(&trace.execution_resources), - )?; + serializer.serialize_field("execution_resources", &trace.execution_resources)?; } pathfinder_executor::types::TransactionTrace::DeployAccount(trace) => { serializer.serialize_field("type", &"DEPLOY_ACCOUNT")?; serializer.serialize_field( "constructor_invocation", - &FunctionInvocation(trace.constructor_invocation.as_ref().ok_or_else( - || { - serde_json::error::Error::custom( - "Missing constructor_invocation in trace", - ) - }, - )?), + &trace.constructor_invocation.as_ref().ok_or_else(|| { + serde_json::error::Error::custom("Missing constructor_invocation in trace") + })?, )?; if let Some(fee_transfer_invocation) = &trace.fee_transfer_invocation { - serializer.serialize_field( - "fee_transfer_invocation", - &FunctionInvocation(fee_transfer_invocation), - )?; + serializer + .serialize_field("fee_transfer_invocation", &fee_transfer_invocation)?; } if let Some(validate_invocation) = &trace.validate_invocation { - serializer.serialize_field( - "validate_invocation", - &FunctionInvocation(validate_invocation), - )?; + serializer.serialize_field("validate_invocation", &validate_invocation)?; } if self.include_state_diff { - serializer.serialize_field("state_diff", &StateDiff(&trace.state_diff))?; + serializer.serialize_field("state_diff", &trace.state_diff)?; } - serializer.serialize_field( - "execution_resources", - &ExecutionResources(&trace.execution_resources), - )?; + serializer.serialize_field("execution_resources", &trace.execution_resources)?; } pathfinder_executor::types::TransactionTrace::Invoke(trace) => { serializer.serialize_field("type", &"INVOKE")?; - serializer.serialize_field( - "execute_invocation", - &ExecuteInvocation(&trace.execute_invocation), - )?; + serializer.serialize_field("execute_invocation", &trace.execute_invocation)?; if let Some(fee_transfer_invocation) = &trace.fee_transfer_invocation { - serializer.serialize_field( - "fee_transfer_invocation", - &FunctionInvocation(fee_transfer_invocation), - )?; + serializer + .serialize_field("fee_transfer_invocation", &fee_transfer_invocation)?; } if let Some(validate_invocation) = &trace.validate_invocation { - serializer.serialize_field( - "validate_invocation", - &FunctionInvocation(validate_invocation), - )?; + serializer.serialize_field("validate_invocation", &validate_invocation)?; } if self.include_state_diff { - serializer.serialize_field("state_diff", &StateDiff(&trace.state_diff))?; + serializer.serialize_field("state_diff", &trace.state_diff)?; } - serializer.serialize_field( - "execution_resources", - &ExecutionResources(&trace.execution_resources), - )?; + serializer.serialize_field("execution_resources", &trace.execution_resources)?; } pathfinder_executor::types::TransactionTrace::L1Handler(trace) => { serializer.serialize_field("type", &"L1_HANDLER")?; serializer.serialize_field( "function_invocation", - &FunctionInvocation(trace.function_invocation.as_ref().ok_or_else(|| { + &trace.function_invocation.as_ref().ok_or_else(|| { serde_json::error::Error::custom("Missing function_invocation in trace") - })?), + })?, )?; if self.include_state_diff { - serializer.serialize_field("state_diff", &StateDiff(&trace.state_diff))?; + serializer.serialize_field("state_diff", &trace.state_diff)?; } - serializer.serialize_field( - "execution_resources", - &ExecutionResources(&trace.execution_resources), - )?; + serializer.serialize_field("execution_resources", &trace.execution_resources)?; } } serializer.end() } } -#[derive(Debug)] -pub(crate) struct FunctionInvocation<'a>(&'a pathfinder_executor::types::FunctionInvocation); - -impl crate::dto::SerializeForVersion for FunctionInvocation<'_> { +impl crate::dto::SerializeForVersion for &pathfinder_executor::types::FunctionInvocation { fn serialize( &self, serializer: crate::dto::Serializer, @@ -130,106 +93,71 @@ impl crate::dto::SerializeForVersion for FunctionInvocation<'_> { let mut serializer = serializer.serialize_struct()?; serializer.serialize_field( "call_type", - &match self.0.call_type { + &match self.call_type { pathfinder_executor::types::CallType::Call => "CALL", pathfinder_executor::types::CallType::Delegate => "DELEGATE", }, )?; - serializer.serialize_field("caller_address", &crate::dto::Felt(&self.0.caller_address))?; + serializer.serialize_field("caller_address", &self.caller_address)?; serializer.serialize_iter( "calls", - self.0.internal_calls.len(), - &mut self.0.internal_calls.iter().map(FunctionInvocation), + self.internal_calls.len(), + &mut self.internal_calls.iter(), )?; - if let Some(class_hash) = &self.0.class_hash { - serializer.serialize_field("class_hash", &crate::dto::Felt(class_hash))?; + if let Some(class_hash) = &self.class_hash { + serializer.serialize_field("class_hash", &class_hash)?; } serializer.serialize_field( "entry_point_type", - &match self.0.entry_point_type { + &match self.entry_point_type { pathfinder_executor::types::EntryPointType::Constructor => "CONSTRUCTOR", pathfinder_executor::types::EntryPointType::External => "EXTERNAL", pathfinder_executor::types::EntryPointType::L1Handler => "L1_HANDLER", }, )?; - serializer.serialize_iter( - "events", - self.0.events.len(), - &mut self.0.events.iter().map(Event), - )?; - serializer.serialize_field( - "contract_address", - &crate::dto::Felt(&self.0.contract_address.0), - )?; - serializer.serialize_field("entry_point_selector", &crate::dto::Felt(&self.0.selector))?; - serializer.serialize_iter( - "calldata", - self.0.calldata.len(), - &mut self.0.calldata.iter().map(crate::dto::Felt), - )?; - serializer.serialize_iter( - "messages", - self.0.messages.len(), - &mut self.0.messages.iter().map(MsgToL1), - )?; - serializer.serialize_iter( - "result", - self.0.result.len(), - &mut self.0.result.iter().map(crate::dto::Felt), - )?; + serializer.serialize_iter("events", self.events.len(), &mut self.events.iter())?; + serializer.serialize_field("contract_address", &self.contract_address)?; + serializer.serialize_field("entry_point_selector", &self.selector)?; + serializer.serialize_iter("calldata", self.calldata.len(), &mut self.calldata.iter())?; + serializer.serialize_iter("messages", self.messages.len(), &mut self.messages.iter())?; + serializer.serialize_iter("result", self.result.len(), &mut self.result.iter())?; match serializer.version { RpcVersion::V08 => serializer.serialize_field( "execution_resources", - &InnerCallExecutionResources(&self.0.execution_resources), + &InnerCallExecutionResources(&self.execution_resources), )?, _ => serializer.serialize_field( "execution_resources", - &ComputationResources(&self.0.computation_resources), + &ComputationResources(&self.computation_resources), )?, } serializer.end() } } -struct Event<'a>(&'a pathfinder_executor::types::Event); - -impl crate::dto::SerializeForVersion for Event<'_> { +impl crate::dto::SerializeForVersion for &pathfinder_executor::types::Event { fn serialize( &self, serializer: crate::dto::Serializer, ) -> Result { let mut serializer = serializer.serialize_struct()?; - serializer.serialize_field("order", &self.0.order)?; - serializer.serialize_iter( - "data", - self.0.data.len(), - &mut self.0.data.iter().map(crate::dto::Felt), - )?; - serializer.serialize_iter( - "keys", - self.0.keys.len(), - &mut self.0.keys.iter().map(crate::dto::Felt), - )?; + serializer.serialize_field("order", &self.order)?; + serializer.serialize_iter("data", self.data.len(), &mut self.data.iter())?; + serializer.serialize_iter("keys", self.keys.len(), &mut self.keys.iter())?; serializer.end() } } -struct MsgToL1<'a>(&'a pathfinder_executor::types::MsgToL1); - -impl crate::dto::SerializeForVersion for MsgToL1<'_> { +impl crate::dto::SerializeForVersion for &pathfinder_executor::types::MsgToL1 { fn serialize( &self, serializer: crate::dto::Serializer, ) -> Result { let mut serializer = serializer.serialize_struct()?; - serializer.serialize_field("order", &self.0.order)?; - serializer.serialize_iter( - "payload", - self.0.payload.len(), - &mut self.0.payload.iter().map(crate::dto::Felt), - )?; - serializer.serialize_field("to_address", &crate::dto::Felt(&self.0.to_address))?; - serializer.serialize_field("from_address", &crate::dto::Felt(&self.0.from_address))?; + serializer.serialize_field("order", &self.order)?; + serializer.serialize_iter("payload", self.payload.len(), &mut self.payload.iter())?; + serializer.serialize_field("to_address", &self.to_address)?; + serializer.serialize_field("from_address", &self.from_address)?; serializer.end() } } @@ -309,9 +237,7 @@ impl crate::dto::SerializeForVersion for InnerCallExecutionResources<'_> { } } -struct StateDiff<'a>(&'a pathfinder_executor::types::StateDiff); - -impl crate::dto::SerializeForVersion for StateDiff<'_> { +impl crate::dto::SerializeForVersion for pathfinder_executor::types::StateDiff { fn serialize( &self, serializer: crate::dto::Serializer, @@ -319,38 +245,30 @@ impl crate::dto::SerializeForVersion for StateDiff<'_> { let mut serializer = serializer.serialize_struct()?; serializer.serialize_iter( "storage_diffs", - self.0.storage_diffs.len(), - &mut self.0.storage_diffs.iter().map(StorageDiff), + self.storage_diffs.len(), + &mut self.storage_diffs.iter().map(StorageDiff), )?; serializer.serialize_iter( "deprecated_declared_classes", - self.0.deprecated_declared_classes.len(), - &mut self - .0 - .deprecated_declared_classes - .iter() - .map(|v| crate::dto::Felt(&v.0)), + self.deprecated_declared_classes.len(), + &mut self.deprecated_declared_classes.iter(), )?; serializer.serialize_iter( "declared_classes", - self.0.declared_classes.len(), - &mut self.0.declared_classes.iter().map(DeclaredSierraClass), + self.declared_classes.len(), + &mut self.declared_classes.iter(), )?; serializer.serialize_iter( "deployed_contracts", - self.0.deployed_contracts.len(), - &mut self.0.deployed_contracts.iter().map(DeployedContract), + self.deployed_contracts.len(), + &mut self.deployed_contracts.iter(), )?; serializer.serialize_iter( "replaced_classes", - self.0.replaced_classes.len(), - &mut self.0.replaced_classes.iter().map(ReplacedClass), - )?; - serializer.serialize_iter( - "nonces", - self.0.nonces.len(), - &mut self.0.nonces.iter().map(Nonce), + self.replaced_classes.len(), + &mut self.replaced_classes.iter(), )?; + serializer.serialize_iter("nonces", self.nonces.len(), &mut self.nonces.iter())?; serializer.end() } } @@ -368,74 +286,56 @@ impl crate::dto::SerializeForVersion for StorageDiff<'_> { serializer: crate::dto::Serializer, ) -> Result { let mut serializer = serializer.serialize_struct()?; - serializer.serialize_field("address", &crate::dto::Felt(&self.0 .0 .0))?; - serializer.serialize_iter( - "storage_entries", - self.0 .1.len(), - &mut self.0 .1.iter().map(StorageEntry), - )?; + serializer.serialize_field("address", &self.0 .0)?; + serializer.serialize_iter("storage_entries", self.0 .1.len(), &mut self.0 .1.iter())?; serializer.end() } } -struct StorageEntry<'a>(&'a pathfinder_executor::types::StorageDiff); - -impl crate::dto::SerializeForVersion for StorageEntry<'_> { +impl crate::dto::SerializeForVersion for &pathfinder_executor::types::StorageDiff { fn serialize( &self, serializer: crate::dto::Serializer, ) -> Result { let mut serializer = serializer.serialize_struct()?; - serializer.serialize_field("key", &crate::dto::Felt(&self.0.key.0))?; - serializer.serialize_field("value", &crate::dto::Felt(&self.0.value.0))?; + serializer.serialize_field("key", &self.key)?; + serializer.serialize_field("value", &self.value)?; serializer.end() } } -struct DeclaredSierraClass<'a>(&'a pathfinder_executor::types::DeclaredSierraClass); - -impl crate::dto::SerializeForVersion for DeclaredSierraClass<'_> { +impl crate::dto::SerializeForVersion for &pathfinder_executor::types::DeclaredSierraClass { fn serialize( &self, serializer: crate::dto::Serializer, ) -> Result { let mut serializer = serializer.serialize_struct()?; - serializer.serialize_field("class_hash", &crate::dto::Felt(&self.0.class_hash.0))?; - serializer.serialize_field( - "compiled_class_hash", - &crate::dto::Felt(&self.0.compiled_class_hash.0), - )?; + serializer.serialize_field("class_hash", &self.class_hash)?; + serializer.serialize_field("compiled_class_hash", &self.compiled_class_hash)?; serializer.end() } } -struct DeployedContract<'a>(&'a pathfinder_executor::types::DeployedContract); - -impl crate::dto::SerializeForVersion for DeployedContract<'_> { +impl crate::dto::SerializeForVersion for &pathfinder_executor::types::DeployedContract { fn serialize( &self, serializer: crate::dto::Serializer, ) -> Result { let mut serializer = serializer.serialize_struct()?; - serializer.serialize_field("address", &crate::dto::Felt(&self.0.address.0))?; - serializer.serialize_field("class_hash", &crate::dto::Felt(&self.0.class_hash.0))?; + serializer.serialize_field("address", &self.address)?; + serializer.serialize_field("class_hash", &self.class_hash)?; serializer.end() } } -struct ReplacedClass<'a>(&'a pathfinder_executor::types::ReplacedClass); - -impl crate::dto::SerializeForVersion for ReplacedClass<'_> { +impl crate::dto::SerializeForVersion for &pathfinder_executor::types::ReplacedClass { fn serialize( &self, serializer: crate::dto::Serializer, ) -> Result { let mut serializer = serializer.serialize_struct()?; - serializer.serialize_field( - "contract_address", - &crate::dto::Felt(&self.0.contract_address.0), - )?; - serializer.serialize_field("class_hash", &crate::dto::Felt(&self.0.class_hash.0))?; + serializer.serialize_field("contract_address", &self.contract_address)?; + serializer.serialize_field("class_hash", &self.class_hash)?; serializer.end() } } @@ -448,15 +348,13 @@ impl crate::dto::SerializeForVersion for Nonce<'_> { serializer: crate::dto::Serializer, ) -> Result { let mut serializer = serializer.serialize_struct()?; - serializer.serialize_field("contract_address", &crate::dto::Felt(&self.0 .0 .0))?; - serializer.serialize_field("nonce", &crate::dto::Felt(&self.0 .1 .0))?; + serializer.serialize_field("contract_address", &self.0 .0)?; + serializer.serialize_field("nonce", &self.0 .1)?; serializer.end() } } -struct ExecutionResources<'a>(&'a pathfinder_executor::types::ExecutionResources); - -impl crate::dto::SerializeForVersion for ExecutionResources<'_> { +impl crate::dto::SerializeForVersion for pathfinder_executor::types::ExecutionResources { fn serialize( &self, serializer: crate::dto::Serializer, @@ -464,48 +362,41 @@ impl crate::dto::SerializeForVersion for ExecutionResources<'_> { match serializer.version { RpcVersion::V08 => { let mut serializer = serializer.serialize_struct()?; - serializer.serialize_field("l1_gas", &self.0.l1_gas)?; - serializer.serialize_field("l1_data_gas", &self.0.l1_data_gas)?; - serializer.serialize_field("l2_gas", &self.0.l2_gas)?; + serializer.serialize_field("l1_gas", &self.l1_gas)?; + serializer.serialize_field("l1_data_gas", &self.l1_data_gas)?; + serializer.serialize_field("l2_gas", &self.l2_gas)?; serializer.end() } _ => { let mut serializer = serializer.serialize_struct()?; - serializer.flatten(&ComputationResources(&self.0.computation_resources))?; - serializer.serialize_field( - "data_availability", - &DataAvailabilityResources(&self.0.data_availability), - )?; + serializer.flatten(&ComputationResources(&self.computation_resources))?; + serializer.serialize_field("data_availability", &self.data_availability)?; serializer.end() } } } } -struct DataAvailabilityResources<'a>(&'a pathfinder_executor::types::DataAvailabilityResources); - -impl crate::dto::SerializeForVersion for DataAvailabilityResources<'_> { +impl crate::dto::SerializeForVersion for pathfinder_executor::types::DataAvailabilityResources { fn serialize( &self, serializer: crate::dto::Serializer, ) -> Result { let mut serializer = serializer.serialize_struct()?; - serializer.serialize_field("l1_gas", &self.0.l1_gas)?; - serializer.serialize_field("l1_data_gas", &self.0.l1_data_gas)?; + serializer.serialize_field("l1_gas", &self.l1_gas)?; + serializer.serialize_field("l1_data_gas", &self.l1_data_gas)?; serializer.end() } } -struct ExecuteInvocation<'a>(&'a pathfinder_executor::types::ExecuteInvocation); - -impl crate::dto::SerializeForVersion for ExecuteInvocation<'_> { +impl crate::dto::SerializeForVersion for pathfinder_executor::types::ExecuteInvocation { fn serialize( &self, serializer: crate::dto::Serializer, ) -> Result { - match self.0 { + match self { pathfinder_executor::types::ExecuteInvocation::FunctionInvocation(Some(invocation)) => { - FunctionInvocation(invocation).serialize(serializer) + invocation.serialize(serializer) } pathfinder_executor::types::ExecuteInvocation::FunctionInvocation(None) => { let mut serializer = serializer.serialize_struct()?; @@ -577,19 +468,17 @@ impl crate::dto::DeserializeForVersion for SimulationFlags { } } -pub(crate) struct SimulatedTransaction(pub pathfinder_executor::types::TransactionSimulation); - -impl crate::dto::SerializeForVersion for SimulatedTransaction { +impl crate::dto::SerializeForVersion for pathfinder_executor::types::TransactionSimulation { fn serialize( &self, serializer: crate::dto::Serializer, ) -> Result { let mut serializer = serializer.serialize_struct()?; - serializer.serialize_field("fee_estimation", &FeeEstimate(&self.0.fee_estimation))?; + serializer.serialize_field("fee_estimation", &self.fee_estimation)?; serializer.serialize_field( "transaction_trace", &TransactionTrace { - trace: self.0.trace.clone(), + trace: self.trace.clone(), include_state_diff: false, }, )?; @@ -626,11 +515,8 @@ mod tests { CallType, ComputationResources, ExecutionResources, - FeeEstimate, - FunctionInvocation, SerializeForVersion, Serializer, - SimulatedTransaction, TransactionTrace, }; use crate::method::call::FunctionCall; diff --git a/crates/rpc/src/dto/state_update.rs b/crates/rpc/src/dto/state_update.rs index 8259a06e18..91e6122082 100644 --- a/crates/rpc/src/dto/state_update.rs +++ b/crates/rpc/src/dto/state_update.rs @@ -30,9 +30,9 @@ impl SerializeForVersion for StateUpdate<'_> { fn serialize(&self, serializer: Serializer) -> Result { let mut serializer = serializer.serialize_struct()?; - serializer.serialize_field("block_hash", &dto::BlockHash(&self.0.block_hash))?; - serializer.serialize_field("old_root", &dto::Felt(&self.0.state_commitment.0))?; - serializer.serialize_field("new_root", &dto::Felt(&self.0.parent_state_commitment.0))?; + serializer.serialize_field("block_hash", &self.0.block_hash)?; + serializer.serialize_field("old_root", &self.0.state_commitment.0)?; + serializer.serialize_field("new_root", &self.0.parent_state_commitment.0)?; serializer.serialize_field("state_diff", &StateDiff(self.0))?; serializer.end() @@ -43,7 +43,7 @@ impl SerializeForVersion for PendingStateUpdate<'_> { fn serialize(&self, serializer: Serializer) -> Result { let mut serializer = serializer.serialize_struct()?; - serializer.serialize_field("old_root", &dto::Felt(&self.0.state_commitment.0))?; + serializer.serialize_field("old_root", &self.0.state_commitment.0)?; serializer.serialize_field("state_diff", &StateDiff(self.0))?; serializer.end() @@ -72,8 +72,8 @@ impl SerializeForVersion for StateDiff<'_> { ) -> Result { let mut serializer = serializer.serialize_struct()?; - serializer.serialize_field("class_hash", &dto::Felt(&self.sierra.0))?; - serializer.serialize_field("compiled_class_hash", &dto::Felt(&self.casm.0))?; + serializer.serialize_field("class_hash", &self.sierra.0)?; + serializer.serialize_field("compiled_class_hash", &self.casm.0)?; serializer.end() } @@ -86,8 +86,8 @@ impl SerializeForVersion for StateDiff<'_> { ) -> Result { let mut serializer = serializer.serialize_struct()?; - serializer.serialize_field("contract_address", &dto::Address(self.address))?; - serializer.serialize_field("class_hash", &dto::Felt(&self.hash.0))?; + serializer.serialize_field("contract_address", &self.address)?; + serializer.serialize_field("class_hash", &self.hash.0)?; serializer.end() } @@ -100,8 +100,8 @@ impl SerializeForVersion for StateDiff<'_> { ) -> Result { let mut serializer = serializer.serialize_struct()?; - serializer.serialize_field("contract_address", &dto::Address(self.address))?; - serializer.serialize_field("nonce", &dto::Felt(&self.nonce.0))?; + serializer.serialize_field("contract_address", &self.address)?; + serializer.serialize_field("nonce", &self.nonce.0)?; serializer.end() } @@ -127,11 +127,7 @@ impl SerializeForVersion for StateDiff<'_> { }); let diff_count = storage_diffs.clone().count(); - let mut deprecated_classes = self - .0 - .declared_cairo_classes - .iter() - .map(|x| dto::Felt(&x.0)); + let mut deprecated_classes = self.0.declared_cairo_classes.iter(); let mut declared_classes = self .0 @@ -211,8 +207,8 @@ impl SerializeForVersion for ContractStorageDiffItem<'_> { ) -> Result { let mut serializer = serializer.serialize_struct()?; - serializer.serialize_field("key", &dto::Felt(&self.key.0))?; - serializer.serialize_field("value", &dto::Felt(&self.value.0))?; + serializer.serialize_field("key", &self.key.0)?; + serializer.serialize_field("value", &self.value.0)?; serializer.end() } @@ -220,7 +216,7 @@ impl SerializeForVersion for ContractStorageDiffItem<'_> { let mut serializer = serializer.serialize_struct()?; - serializer.serialize_field("address", &dto::Felt(&self.address.0))?; + serializer.serialize_field("address", &self.address)?; serializer.serialize_iter( "storage_entries", self.storage_entries.len(), @@ -238,8 +234,8 @@ impl SerializeForVersion for DeployedContractItem<'_> { fn serialize(&self, serializer: Serializer) -> Result { let mut serializer = serializer.serialize_struct()?; - serializer.serialize_field("address", &dto::Felt(&self.address.0))?; - serializer.serialize_field("class_hash", &dto::Felt(&self.class_hash.0))?; + serializer.serialize_field("address", &self.address)?; + serializer.serialize_field("class_hash", &self.class_hash.0)?; serializer.end() } diff --git a/crates/rpc/src/dto/transaction.rs b/crates/rpc/src/dto/transaction.rs index a50d145cf4..0ab2e5b2c4 100644 --- a/crates/rpc/src/dto/transaction.rs +++ b/crates/rpc/src/dto/transaction.rs @@ -6,270 +6,182 @@ use super::{DeserializeForVersion, U128Hex, U64Hex}; use crate::dto; use crate::dto::{SerializeForVersion, Serializer}; -pub struct TxnHash<'a>(pub &'a TransactionHash); - -pub struct Transaction<'a>(pub &'a pathfinder_common::transaction::Transaction); pub struct TransactionWithHash<'a>(pub &'a pathfinder_common::transaction::Transaction); -struct ResourceBounds<'a>(&'a pathfinder_common::transaction::ResourceBounds); - -struct ResourceBound<'a>(&'a pathfinder_common::transaction::ResourceBound); - -struct DataAvailabilityMode<'a>(&'a pathfinder_common::transaction::DataAvailabilityMode); - -impl SerializeForVersion for TxnHash<'_> { +impl SerializeForVersion for pathfinder_common::TransactionHash { fn serialize(&self, serializer: Serializer) -> Result { - dto::Felt(&self.0 .0).serialize(serializer) + self.0.serialize(serializer) } } -impl SerializeForVersion for Transaction<'_> { +impl SerializeForVersion for pathfinder_common::transaction::Transaction { fn serialize(&self, serializer: Serializer) -> Result { let mut s = serializer.serialize_struct()?; - match &self.0.variant { + match &self.variant { TransactionVariant::DeclareV0(tx) => { s.serialize_field("type", &"DECLARE")?; - s.serialize_field("sender_address", &dto::Felt(&tx.sender_address.0))?; - s.serialize_field("max_fee", &dto::Felt(&tx.max_fee.0))?; + s.serialize_field("sender_address", &tx.sender_address)?; + s.serialize_field("max_fee", &tx.max_fee)?; s.serialize_field("version", &"0x0")?; - s.serialize_iter( - "signature", - tx.signature.len(), - &mut tx.signature.iter().map(|v| dto::Felt(&v.0)), - )?; - s.serialize_field("class_hash", &dto::Felt(&tx.class_hash.0))?; + s.serialize_iter("signature", tx.signature.len(), &mut tx.signature.iter())?; + s.serialize_field("class_hash", &tx.class_hash)?; } TransactionVariant::DeclareV1(tx) => { s.serialize_field("type", &"DECLARE")?; - s.serialize_field("sender_address", &dto::Felt(&tx.sender_address.0))?; - s.serialize_field("max_fee", &dto::Felt(&tx.max_fee.0))?; + s.serialize_field("sender_address", &tx.sender_address)?; + s.serialize_field("max_fee", &tx.max_fee)?; s.serialize_field("version", &"0x1")?; - s.serialize_iter( - "signature", - tx.signature.len(), - &mut tx.signature.iter().map(|v| dto::Felt(&v.0)), - )?; - s.serialize_field("nonce", &dto::Felt(&tx.nonce.0))?; - s.serialize_field("class_hash", &dto::Felt(&tx.class_hash.0))?; + s.serialize_iter("signature", tx.signature.len(), &mut tx.signature.iter())?; + s.serialize_field("nonce", &tx.nonce)?; + s.serialize_field("class_hash", &tx.class_hash)?; } TransactionVariant::DeclareV2(tx) => { s.serialize_field("type", &"DECLARE")?; - s.serialize_field("sender_address", &dto::Felt(&tx.sender_address.0))?; - s.serialize_field("compiled_class_hash", &dto::Felt(&tx.compiled_class_hash.0))?; - s.serialize_field("max_fee", &dto::Felt(&tx.max_fee.0))?; + s.serialize_field("sender_address", &tx.sender_address)?; + s.serialize_field("compiled_class_hash", &tx.compiled_class_hash)?; + s.serialize_field("max_fee", &tx.max_fee)?; s.serialize_field("version", &"0x2")?; - s.serialize_iter( - "signature", - tx.signature.len(), - &mut tx.signature.iter().map(|v| dto::Felt(&v.0)), - )?; - s.serialize_field("nonce", &dto::Felt(&tx.nonce.0))?; - s.serialize_field("class_hash", &dto::Felt(&tx.class_hash.0))?; + s.serialize_iter("signature", tx.signature.len(), &mut tx.signature.iter())?; + s.serialize_field("nonce", &tx.nonce)?; + s.serialize_field("class_hash", &tx.class_hash)?; } TransactionVariant::DeclareV3(tx) => { s.serialize_field("type", &"DECLARE")?; - s.serialize_field("sender_address", &dto::Felt(&tx.sender_address.0))?; - s.serialize_field("compiled_class_hash", &dto::Felt(&tx.compiled_class_hash.0))?; + s.serialize_field("sender_address", &tx.sender_address)?; + s.serialize_field("compiled_class_hash", &tx.compiled_class_hash)?; s.serialize_field("version", &"0x3")?; - s.serialize_iter( - "signature", - tx.signature.len(), - &mut tx.signature.iter().map(|v| dto::Felt(&v.0)), - )?; - s.serialize_field("nonce", &dto::Felt(&tx.nonce.0))?; - s.serialize_field("class_hash", &dto::Felt(&tx.class_hash.0))?; - s.serialize_field("resource_bounds", &ResourceBounds(&tx.resource_bounds))?; + s.serialize_iter("signature", tx.signature.len(), &mut tx.signature.iter())?; + s.serialize_field("nonce", &tx.nonce)?; + s.serialize_field("class_hash", &tx.class_hash)?; + s.serialize_field("resource_bounds", &tx.resource_bounds)?; s.serialize_field("tip", &U64Hex(tx.tip.0))?; s.serialize_iter( "paymaster_data", tx.paymaster_data.len(), - &mut tx.paymaster_data.iter().map(|v| dto::Felt(&v.0)), + &mut tx.paymaster_data.iter(), )?; s.serialize_iter( "account_deployment_data", tx.account_deployment_data.len(), - &mut tx.account_deployment_data.iter().map(|v| dto::Felt(&v.0)), + &mut tx.account_deployment_data.iter(), )?; s.serialize_field( "nonce_data_availability_mode", - &DataAvailabilityMode(&tx.nonce_data_availability_mode), - )?; - s.serialize_field( - "fee_data_availability_mode", - &DataAvailabilityMode(&tx.fee_data_availability_mode), + &tx.nonce_data_availability_mode, )?; + s.serialize_field("fee_data_availability_mode", &tx.fee_data_availability_mode)?; } TransactionVariant::DeployV0(tx) => { s.serialize_field("version", &"0x0")?; s.serialize_field("type", &"DEPLOY")?; - s.serialize_field( - "contract_address_salt", - &dto::Felt(&tx.contract_address_salt.0), - )?; + s.serialize_field("contract_address_salt", &tx.contract_address_salt)?; s.serialize_iter( "constructor_calldata", tx.constructor_calldata.len(), - &mut tx.constructor_calldata.iter().map(|v| dto::Felt(&v.0)), + &mut tx.constructor_calldata.iter(), )?; - s.serialize_field("class_hash", &dto::Felt(&tx.class_hash.0))?; + s.serialize_field("class_hash", &tx.class_hash)?; } TransactionVariant::DeployV1(tx) => { s.serialize_field("version", &"0x1")?; s.serialize_field("type", &"DEPLOY")?; - s.serialize_field( - "contract_address_salt", - &dto::Felt(&tx.contract_address_salt.0), - )?; + s.serialize_field("contract_address_salt", &tx.contract_address_salt)?; s.serialize_iter( "constructor_calldata", tx.constructor_calldata.len(), - &mut tx.constructor_calldata.iter().map(|v| dto::Felt(&v.0)), + &mut tx.constructor_calldata.iter(), )?; - s.serialize_field("class_hash", &dto::Felt(&tx.class_hash.0))?; + s.serialize_field("class_hash", &tx.class_hash)?; } TransactionVariant::DeployAccountV1(tx) => { s.serialize_field("type", &"DEPLOY_ACCOUNT")?; - s.serialize_field("max_fee", &dto::Felt(&tx.max_fee.0))?; + s.serialize_field("max_fee", &tx.max_fee)?; s.serialize_field("version", &"0x1")?; - s.serialize_iter( - "signature", - tx.signature.len(), - &mut tx.signature.iter().map(|v| dto::Felt(&v.0)), - )?; - s.serialize_field("nonce", &dto::Felt(&tx.nonce.0))?; - s.serialize_field( - "contract_address_salt", - &dto::Felt(&tx.contract_address_salt.0), - )?; + s.serialize_iter("signature", tx.signature.len(), &mut tx.signature.iter())?; + s.serialize_field("nonce", &tx.nonce)?; + s.serialize_field("contract_address_salt", &tx.contract_address_salt)?; s.serialize_iter( "constructor_calldata", tx.constructor_calldata.len(), - &mut tx.constructor_calldata.iter().map(|v| dto::Felt(&v.0)), + &mut tx.constructor_calldata.iter(), )?; - s.serialize_field("class_hash", &dto::Felt(&tx.class_hash.0))?; + s.serialize_field("class_hash", &tx.class_hash)?; } TransactionVariant::DeployAccountV3(tx) => { s.serialize_field("type", &"DEPLOY_ACCOUNT")?; s.serialize_field("version", &"0x3")?; - s.serialize_iter( - "signature", - tx.signature.len(), - &mut tx.signature.iter().map(|v| dto::Felt(&v.0)), - )?; - s.serialize_field("nonce", &dto::Felt(&tx.nonce.0))?; - s.serialize_field( - "contract_address_salt", - &dto::Felt(&tx.contract_address_salt.0), - )?; + s.serialize_iter("signature", tx.signature.len(), &mut tx.signature.iter())?; + s.serialize_field("nonce", &tx.nonce)?; + s.serialize_field("contract_address_salt", &tx.contract_address_salt)?; s.serialize_iter( "constructor_calldata", tx.constructor_calldata.len(), - &mut tx.constructor_calldata.iter().map(|v| dto::Felt(&v.0)), + &mut tx.constructor_calldata.iter(), )?; - s.serialize_field("class_hash", &dto::Felt(&tx.class_hash.0))?; - s.serialize_field("resource_bounds", &ResourceBounds(&tx.resource_bounds))?; + s.serialize_field("class_hash", &tx.class_hash)?; + s.serialize_field("resource_bounds", &tx.resource_bounds)?; s.serialize_field("tip", &U64Hex(tx.tip.0))?; s.serialize_iter( "paymaster_data", tx.paymaster_data.len(), - &mut tx.paymaster_data.iter().map(|v| dto::Felt(&v.0)), + &mut tx.paymaster_data.iter(), )?; s.serialize_field( "nonce_data_availability_mode", - &DataAvailabilityMode(&tx.nonce_data_availability_mode), - )?; - s.serialize_field( - "fee_data_availability_mode", - &DataAvailabilityMode(&tx.fee_data_availability_mode), + &tx.nonce_data_availability_mode, )?; + s.serialize_field("fee_data_availability_mode", &tx.fee_data_availability_mode)?; } TransactionVariant::InvokeV0(tx) => { s.serialize_field("type", &"INVOKE")?; - s.serialize_field("max_fee", &dto::Felt(&tx.max_fee.0))?; + s.serialize_field("max_fee", &tx.max_fee)?; s.serialize_field("version", &"0x0")?; - s.serialize_iter( - "signature", - tx.signature.len(), - &mut tx.signature.iter().map(|v| dto::Felt(&v.0)), - )?; - s.serialize_field("contract_address", &dto::Felt(&tx.sender_address.0))?; - s.serialize_field( - "entry_point_selector", - &dto::Felt(&tx.entry_point_selector.0), - )?; - s.serialize_iter( - "calldata", - tx.calldata.len(), - &mut tx.calldata.iter().map(|v| dto::Felt(&v.0)), - )?; + s.serialize_iter("signature", tx.signature.len(), &mut tx.signature.iter())?; + s.serialize_field("contract_address", &tx.sender_address)?; + s.serialize_field("entry_point_selector", &tx.entry_point_selector)?; + s.serialize_iter("calldata", tx.calldata.len(), &mut tx.calldata.iter())?; } TransactionVariant::InvokeV1(tx) => { s.serialize_field("type", &"INVOKE")?; - s.serialize_field("sender_address", &dto::Felt(&tx.sender_address.0))?; - s.serialize_iter( - "calldata", - tx.calldata.len(), - &mut tx.calldata.iter().map(|v| dto::Felt(&v.0)), - )?; - s.serialize_field("max_fee", &dto::Felt(&tx.max_fee.0))?; + s.serialize_field("sender_address", &tx.sender_address)?; + s.serialize_iter("calldata", tx.calldata.len(), &mut tx.calldata.iter())?; + s.serialize_field("max_fee", &tx.max_fee)?; s.serialize_field("version", &"0x1")?; - s.serialize_iter( - "signature", - tx.signature.len(), - &mut tx.signature.iter().map(|v| dto::Felt(&v.0)), - )?; - s.serialize_field("nonce", &dto::Felt(&tx.nonce.0))?; + s.serialize_iter("signature", tx.signature.len(), &mut tx.signature.iter())?; + s.serialize_field("nonce", &tx.nonce)?; } TransactionVariant::InvokeV3(tx) => { s.serialize_field("type", &"INVOKE")?; - s.serialize_field("sender_address", &dto::Felt(&tx.sender_address.0))?; - s.serialize_iter( - "calldata", - tx.calldata.len(), - &mut tx.calldata.iter().map(|v| dto::Felt(&v.0)), - )?; + s.serialize_field("sender_address", &tx.sender_address)?; + s.serialize_iter("calldata", tx.calldata.len(), &mut tx.calldata.iter())?; s.serialize_field("version", &"0x3")?; - s.serialize_iter( - "signature", - tx.signature.len(), - &mut tx.signature.iter().map(|v| dto::Felt(&v.0)), - )?; - s.serialize_field("nonce", &dto::Felt(&tx.nonce.0))?; - s.serialize_field("resource_bounds", &ResourceBounds(&tx.resource_bounds))?; + s.serialize_iter("signature", tx.signature.len(), &mut tx.signature.iter())?; + s.serialize_field("nonce", &tx.nonce)?; + s.serialize_field("resource_bounds", &tx.resource_bounds)?; s.serialize_field("tip", &U64Hex(tx.tip.0))?; s.serialize_iter( "paymaster_data", tx.paymaster_data.len(), - &mut tx.paymaster_data.iter().map(|v| dto::Felt(&v.0)), + &mut tx.paymaster_data.iter(), )?; s.serialize_iter( "account_deployment_data", tx.account_deployment_data.len(), - &mut tx.account_deployment_data.iter().map(|v| dto::Felt(&v.0)), + &mut tx.account_deployment_data.iter(), )?; s.serialize_field( "nonce_data_availability_mode", - &DataAvailabilityMode(&tx.nonce_data_availability_mode), - )?; - s.serialize_field( - "fee_data_availability_mode", - &DataAvailabilityMode(&tx.fee_data_availability_mode), + &tx.nonce_data_availability_mode, )?; + s.serialize_field("fee_data_availability_mode", &tx.fee_data_availability_mode)?; } TransactionVariant::L1Handler(tx) => { s.serialize_field("version", &"0x0")?; s.serialize_field("type", &"L1_HANDLER")?; - s.serialize_field("nonce", &dto::Felt(&tx.nonce.0))?; - s.serialize_field("contract_address", &dto::Felt(&tx.contract_address.0))?; - s.serialize_field( - "entry_point_selector", - &dto::Felt(&tx.entry_point_selector.0), - )?; - s.serialize_iter( - "calldata", - tx.calldata.len(), - &mut tx.calldata.iter().map(|v| dto::Felt(&v.0)), - )?; + s.serialize_field("nonce", &tx.nonce)?; + s.serialize_field("contract_address", &tx.contract_address)?; + s.serialize_field("entry_point_selector", &tx.entry_point_selector)?; + s.serialize_iter("calldata", tx.calldata.len(), &mut tx.calldata.iter())?; } } s.end() @@ -279,33 +191,33 @@ impl SerializeForVersion for Transaction<'_> { impl SerializeForVersion for TransactionWithHash<'_> { fn serialize(&self, serializer: Serializer) -> Result { let mut s = serializer.serialize_struct()?; - s.serialize_field("transaction_hash", &TxnHash(&self.0.hash))?; - s.flatten(&Transaction(self.0))?; + s.serialize_field("transaction_hash", &self.0.hash)?; + s.flatten(self.0)?; s.end() } } -impl SerializeForVersion for ResourceBounds<'_> { +impl SerializeForVersion for pathfinder_common::transaction::ResourceBounds { fn serialize(&self, serializer: Serializer) -> Result { let mut s = serializer.serialize_struct()?; - s.serialize_field("l1_gas", &ResourceBound(&self.0.l1_gas))?; - s.serialize_field("l2_gas", &ResourceBound(&self.0.l2_gas))?; + s.serialize_field("l1_gas", &self.l1_gas)?; + s.serialize_field("l2_gas", &self.l2_gas)?; s.end() } } -impl SerializeForVersion for ResourceBound<'_> { +impl SerializeForVersion for pathfinder_common::transaction::ResourceBound { fn serialize(&self, serializer: Serializer) -> Result { let mut s = serializer.serialize_struct()?; - s.serialize_field("max_amount", &U64Hex(self.0.max_amount.0))?; - s.serialize_field("max_price_per_unit", &U128Hex(self.0.max_price_per_unit.0))?; + s.serialize_field("max_amount", &U64Hex(self.max_amount.0))?; + s.serialize_field("max_price_per_unit", &U128Hex(self.max_price_per_unit.0))?; s.end() } } -impl SerializeForVersion for DataAvailabilityMode<'_> { +impl SerializeForVersion for pathfinder_common::transaction::DataAvailabilityMode { fn serialize(&self, serializer: Serializer) -> Result { - match self.0 { + match self { pathfinder_common::transaction::DataAvailabilityMode::L1 => { serializer.serialize_str("L1") }