From 711f73b904c1465278ccc6b53a97dd2f4d4919c3 Mon Sep 17 00:00:00 2001 From: Jonathan LEI Date: Sun, 22 Oct 2023 17:17:53 +0800 Subject: [PATCH] feat: generate models for trace methods (#480) --- starknet-core/src/types/codegen.rs | 514 ++++++++++++++++++++++++- starknet-core/src/types/mod.rs | 49 ++- starknet-core/src/types/requests.rs | 4 +- starknet-core/src/types/serde_impls.rs | 20 + 4 files changed, 567 insertions(+), 20 deletions(-) diff --git a/starknet-core/src/types/codegen.rs b/starknet-core/src/types/codegen.rs index 7cd5cac0..efa01001 100644 --- a/starknet-core/src/types/codegen.rs +++ b/starknet-core/src/types/codegen.rs @@ -3,7 +3,7 @@ // https://github.com/xJonathanLEI/starknet-jsonrpc-codegen // Code generated with version: -// https://github.com/xJonathanLEI/starknet-jsonrpc-codegen#ef08a908672c574c4cde6b10bb11eb84054d0885 +// https://github.com/xJonathanLEI/starknet-jsonrpc-codegen#8c7cf4308e9925665679ec05c42b120b6bfa3719 // Code generation requested but not implemented for these types: // - `BLOCK_ID` @@ -12,8 +12,10 @@ // - `CONTRACT_ABI_ENTRY` // - `CONTRACT_CLASS` // - `DECLARE_TXN` +// - `EXECUTE_INVOCATION` // - `INVOKE_TXN` // - `PENDING_TXN_RECEIPT` +// - `TRANSACTION_TRACE` // - `TXN` // - `TXN_RECEIPT` @@ -207,6 +209,14 @@ pub struct BroadcastedInvokeTransaction { pub is_query: bool, } +#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)] +pub enum CallType { + #[serde(rename = "LIBRARY_CALL")] + LibraryCall, + #[serde(rename = "CALL")] + Call, +} + /// Deprecated contract class. /// /// The definition of a legacy (cairo 0) Starknet contract class. @@ -255,6 +265,16 @@ pub struct DeclareTransactionReceipt { pub execution_result: ExecutionResult, } +/// The execution trace of a declare transaction. +#[derive(Debug, Clone, Serialize, Deserialize)] +#[cfg_attr(feature = "no_unknown_fields", serde(deny_unknown_fields))] +pub struct DeclareTransactionTrace { + #[serde(skip_serializing_if = "Option::is_none")] + pub validate_invocation: Option, + #[serde(skip_serializing_if = "Option::is_none")] + pub fee_transfer_invocation: Option, +} + /// Declare contract transaction v0. /// /// Declare contract transaction v0. @@ -369,6 +389,19 @@ pub struct DeployAccountTransactionReceipt { pub contract_address: FieldElement, } +/// The execution trace of a deploy account transaction. +#[derive(Debug, Clone, Serialize, Deserialize)] +#[cfg_attr(feature = "no_unknown_fields", serde(deny_unknown_fields))] +pub struct DeployAccountTransactionTrace { + #[serde(skip_serializing_if = "Option::is_none")] + pub validate_invocation: Option, + /// The trace of the __execute__ call or constructor call, depending on the transaction type + /// (none for declare transactions) + pub constructor_invocation: FunctionInvocation, + #[serde(skip_serializing_if = "Option::is_none")] + pub fee_transfer_invocation: Option, +} + /// Deploy contract transaction. /// /// The structure of a deploy transaction. Note that this transaction type is deprecated and will no @@ -450,6 +483,16 @@ pub struct EmittedEvent { pub transaction_hash: FieldElement, } +#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)] +pub enum EntryPointType { + #[serde(rename = "EXTERNAL")] + External, + #[serde(rename = "L1_HANDLER")] + L1Handler, + #[serde(rename = "CONSTRUCTOR")] + Constructor, +} + #[derive(Debug, Clone, Serialize, Deserialize)] #[cfg_attr(feature = "no_unknown_fields", serde(deny_unknown_fields))] pub struct EntryPointsByType { @@ -482,6 +525,21 @@ pub struct Event { pub data: Vec, } +/// Event content. +/// +/// The content of an event. +#[serde_as] +#[derive(Debug, Clone, Serialize, Deserialize)] +#[cfg_attr(feature = "no_unknown_fields", serde(deny_unknown_fields))] +pub struct EventContent { + /// Keys + #[serde_as(as = "Vec")] + pub keys: Vec, + /// Data + #[serde_as(as = "Vec")] + pub data: Vec, +} + /// Event filter. /// /// An event filter/query. @@ -577,6 +635,38 @@ pub struct FunctionCall { pub calldata: Vec, } +#[serde_as] +#[derive(Debug, Clone, Serialize, Deserialize)] +#[cfg_attr(feature = "no_unknown_fields", serde(deny_unknown_fields))] +pub struct FunctionInvocation { + /// Contract address + #[serde_as(as = "UfeHex")] + pub contract_address: FieldElement, + /// Entry point selector + #[serde_as(as = "UfeHex")] + pub entry_point_selector: FieldElement, + /// The parameters passed to the function + #[serde_as(as = "Vec")] + pub calldata: Vec, + /// The address of the invoking contract. 0 for the root invocation + #[serde_as(as = "UfeHex")] + pub caller_address: FieldElement, + /// The hash of the class being called + #[serde_as(as = "UfeHex")] + pub class_hash: FieldElement, + pub entry_point_type: EntryPointType, + pub call_type: CallType, + /// The value returned from the function invocation + #[serde_as(as = "Vec")] + pub result: Vec, + /// The calls made by this invocation + pub calls: Vec, + /// The events emitted in this invocation + pub events: Vec, + /// The messages sent by this invocation to L1 + pub messages: Vec, +} + /// Function state mutability type. #[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)] pub enum FunctionStateMutability { @@ -605,6 +695,17 @@ pub struct InvokeTransactionReceipt { pub execution_result: ExecutionResult, } +/// The execution trace of an invoke transaction. +#[derive(Debug, Clone, Serialize, Deserialize)] +#[cfg_attr(feature = "no_unknown_fields", serde(deny_unknown_fields))] +pub struct InvokeTransactionTrace { + #[serde(skip_serializing_if = "Option::is_none")] + pub validate_invocation: Option, + pub execute_invocation: ExecuteInvocation, + #[serde(skip_serializing_if = "Option::is_none")] + pub fee_transfer_invocation: Option, +} + /// Invoke transaction v0. /// /// Invokes a specific function in the desired contract (not necessarily an account). @@ -685,6 +786,15 @@ pub struct L1HandlerTransactionReceipt { pub execution_result: ExecutionResult, } +/// The execution trace of an L1 handler transaction. +#[derive(Debug, Clone, Serialize, Deserialize)] +#[cfg_attr(feature = "no_unknown_fields", serde(deny_unknown_fields))] +pub struct L1HandlerTransactionTrace { + /// The trace of the __execute__ call or constructor call, depending on the transaction type + /// (none for declare transactions) + pub function_invocation: FunctionInvocation, +} + /// Deprecated cairo entry point. #[serde_as] #[derive(Debug, Clone, Serialize, Deserialize)] @@ -1009,6 +1119,13 @@ pub struct ResultPageRequest { pub chunk_size: u64, } +#[derive(Debug, Clone, Serialize, Deserialize)] +#[cfg_attr(feature = "no_unknown_fields", serde(deny_unknown_fields))] +pub struct RevertedInvocation { + /// The revert reason for the failed execution + pub revert_reason: String, +} + /// Sierra entry point. #[serde_as] #[derive(Debug, Clone, Serialize, Deserialize)] @@ -1021,6 +1138,27 @@ pub struct SierraEntryPoint { pub function_idx: u64, } +#[derive(Debug, Clone, Serialize, Deserialize)] +#[cfg_attr(feature = "no_unknown_fields", serde(deny_unknown_fields))] +pub struct SimulatedTransaction { + /// The transaction's trace + pub transaction_trace: TransactionTrace, + /// The transaction's resources and fee + pub fee_estimation: FeeEstimate, +} + +/// Flags that indicate how to simulate a given transaction. By default, the sequencer behavior is +/// replicated locally (enough funds are expected to be in the account, and fee will be deducted +/// from the balance before the simulation of the next transaction). To skip the fee charge, use the +/// skip_fee_charge flag. +#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)] +pub enum SimulationFlag { + #[serde(rename = "SKIP_VALIDATE")] + SkipValidate, + #[serde(rename = "SKIP_FEE_CHARGE")] + SkipFeeCharge, +} + /// JSON-RPC error codes #[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)] pub enum StarknetError { @@ -1072,6 +1210,12 @@ pub enum StarknetError { UnsupportedContractClassVersion, /// An unexpected error occured UnexpectedError, + /// No trace available for transaction + NoTraceAvailable, + /// Invalid transaction hash + InvalidTransactionHash, + /// Invalid block hash + InvalidBlockHash, } #[cfg(feature = "std")] @@ -1104,6 +1248,9 @@ impl core::fmt::Display for StarknetError { Self::UnsupportedTxVersion => write!(f, "UnsupportedTxVersion"), Self::UnsupportedContractClassVersion => write!(f, "UnsupportedContractClassVersion"), Self::UnexpectedError => write!(f, "UnexpectedError"), + Self::NoTraceAvailable => write!(f, "NoTraceAvailable"), + Self::InvalidTransactionHash => write!(f, "InvalidTransactionHash"), + Self::InvalidBlockHash => write!(f, "InvalidBlockHash"), } } } @@ -1204,6 +1351,16 @@ pub enum TransactionFinalityStatus { AcceptedOnL1, } +/// A single pair of transaction hash and corresponding trace. +#[serde_as] +#[derive(Debug, Clone, Serialize, Deserialize)] +#[cfg_attr(feature = "no_unknown_fields", serde(deny_unknown_fields))] +pub struct TransactionTraceWithHash { + #[serde_as(as = "UfeHex")] + pub transaction_hash: FieldElement, + pub trace_root: TransactionTrace, +} + /// Request for method starknet_addDeclareTransaction #[derive(Debug, Clone)] pub struct AddDeclareTransactionRequest { @@ -1494,10 +1651,54 @@ pub struct GetTransactionReceiptRequestRef<'a> { #[derive(Debug, Clone)] pub struct PendingTransactionsRequest; +/// Request for method starknet_simulateTransactions +#[derive(Debug, Clone)] +pub struct SimulateTransactionsRequest { + /// The hash of the requested block, or number (height) of the requested block, or a block tag, + /// for the block referencing the state or call the transaction on. + pub block_id: BlockId, + /// The transactions to simulate + pub transactions: Vec, + /// describes what parts of the transaction should be executed + pub simulation_flags: Vec, +} + +/// Reference version of [SimulateTransactionsRequest]. +#[derive(Debug, Clone)] +pub struct SimulateTransactionsRequestRef<'a> { + pub block_id: &'a BlockId, + pub transactions: &'a [BroadcastedTransaction], + pub simulation_flags: &'a [SimulationFlag], +} + /// Request for method starknet_syncing #[derive(Debug, Clone)] pub struct SyncingRequest; +/// Request for method starknet_traceBlockTransactions +#[derive(Debug, Clone)] +pub struct TraceBlockTransactionsRequest { + pub block_hash: FieldElement, +} + +/// Reference version of [TraceBlockTransactionsRequest]. +#[derive(Debug, Clone)] +pub struct TraceBlockTransactionsRequestRef<'a> { + pub block_hash: &'a FieldElement, +} + +/// Request for method starknet_traceTransaction +#[derive(Debug, Clone)] +pub struct TraceTransactionRequest { + pub transaction_hash: FieldElement, +} + +/// Reference version of [TraceTransactionRequest]. +#[derive(Debug, Clone)] +pub struct TraceTransactionRequestRef<'a> { + pub transaction_hash: &'a FieldElement, +} + impl Serialize for BroadcastedDeclareTransactionV1 { fn serialize(&self, serializer: S) -> Result { #[serde_as] @@ -5262,6 +5463,149 @@ impl<'de> Deserialize<'de> for PendingTransactionsRequest { } } +impl Serialize for SimulateTransactionsRequest { + fn serialize(&self, serializer: S) -> Result { + #[derive(Serialize)] + #[serde(transparent)] + struct Field0<'a> { + pub block_id: &'a BlockId, + } + + #[derive(Serialize)] + #[serde(transparent)] + struct Field1<'a> { + pub transactions: &'a [BroadcastedTransaction], + } + + #[derive(Serialize)] + #[serde(transparent)] + struct Field2<'a> { + pub simulation_flags: &'a [SimulationFlag], + } + + use serde::ser::SerializeSeq; + + let mut seq = serializer.serialize_seq(None)?; + + seq.serialize_element(&Field0 { + block_id: &self.block_id, + })?; + seq.serialize_element(&Field1 { + transactions: &self.transactions, + })?; + seq.serialize_element(&Field2 { + simulation_flags: &self.simulation_flags, + })?; + + seq.end() + } +} + +impl<'a> Serialize for SimulateTransactionsRequestRef<'a> { + fn serialize(&self, serializer: S) -> Result { + #[derive(Serialize)] + #[serde(transparent)] + struct Field0<'a> { + pub block_id: &'a BlockId, + } + + #[derive(Serialize)] + #[serde(transparent)] + struct Field1<'a> { + pub transactions: &'a [BroadcastedTransaction], + } + + #[derive(Serialize)] + #[serde(transparent)] + struct Field2<'a> { + pub simulation_flags: &'a [SimulationFlag], + } + + use serde::ser::SerializeSeq; + + let mut seq = serializer.serialize_seq(None)?; + + seq.serialize_element(&Field0 { + block_id: self.block_id, + })?; + seq.serialize_element(&Field1 { + transactions: self.transactions, + })?; + seq.serialize_element(&Field2 { + simulation_flags: self.simulation_flags, + })?; + + seq.end() + } +} + +impl<'de> Deserialize<'de> for SimulateTransactionsRequest { + fn deserialize>(deserializer: D) -> Result { + #[serde_as] + #[derive(Deserialize)] + struct AsObject { + pub block_id: BlockId, + pub transactions: Vec, + pub simulation_flags: Vec, + } + + #[derive(Deserialize)] + #[serde(transparent)] + struct Field0 { + pub block_id: BlockId, + } + + #[derive(Deserialize)] + #[serde(transparent)] + struct Field1 { + pub transactions: Vec, + } + + #[derive(Deserialize)] + #[serde(transparent)] + struct Field2 { + pub simulation_flags: Vec, + } + + let temp = serde_json::Value::deserialize(deserializer)?; + + if let Ok(mut elements) = Vec::::deserialize(&temp) { + let field2 = serde_json::from_value::( + elements + .pop() + .ok_or_else(|| serde::de::Error::custom("invalid sequence length"))?, + ) + .map_err(|err| serde::de::Error::custom(format!("failed to parse element: {}", err)))?; + let field1 = serde_json::from_value::( + elements + .pop() + .ok_or_else(|| serde::de::Error::custom("invalid sequence length"))?, + ) + .map_err(|err| serde::de::Error::custom(format!("failed to parse element: {}", err)))?; + let field0 = serde_json::from_value::( + elements + .pop() + .ok_or_else(|| serde::de::Error::custom("invalid sequence length"))?, + ) + .map_err(|err| serde::de::Error::custom(format!("failed to parse element: {}", err)))?; + + Ok(Self { + block_id: field0.block_id, + transactions: field1.transactions, + simulation_flags: field2.simulation_flags, + }) + } else if let Ok(object) = AsObject::deserialize(&temp) { + Ok(Self { + block_id: object.block_id, + transactions: object.transactions, + simulation_flags: object.simulation_flags, + }) + } else { + Err(serde::de::Error::custom("invalid sequence length")) + } + } +} + impl Serialize for SyncingRequest { fn serialize(&self, serializer: S) -> Result { use serde::ser::SerializeSeq; @@ -5280,3 +5624,171 @@ impl<'de> Deserialize<'de> for SyncingRequest { Ok(Self) } } + +impl Serialize for TraceBlockTransactionsRequest { + fn serialize(&self, serializer: S) -> Result { + #[serde_as] + #[derive(Serialize)] + #[serde(transparent)] + struct Field0<'a> { + #[serde_as(as = "UfeHex")] + pub block_hash: &'a FieldElement, + } + + use serde::ser::SerializeSeq; + + let mut seq = serializer.serialize_seq(None)?; + + seq.serialize_element(&Field0 { + block_hash: &self.block_hash, + })?; + + seq.end() + } +} + +impl<'a> Serialize for TraceBlockTransactionsRequestRef<'a> { + fn serialize(&self, serializer: S) -> Result { + #[serde_as] + #[derive(Serialize)] + #[serde(transparent)] + struct Field0<'a> { + #[serde_as(as = "UfeHex")] + pub block_hash: &'a FieldElement, + } + + use serde::ser::SerializeSeq; + + let mut seq = serializer.serialize_seq(None)?; + + seq.serialize_element(&Field0 { + block_hash: self.block_hash, + })?; + + seq.end() + } +} + +impl<'de> Deserialize<'de> for TraceBlockTransactionsRequest { + fn deserialize>(deserializer: D) -> Result { + #[serde_as] + #[derive(Deserialize)] + struct AsObject { + #[serde_as(as = "UfeHex")] + pub block_hash: FieldElement, + } + + #[serde_as] + #[derive(Deserialize)] + #[serde(transparent)] + struct Field0 { + #[serde_as(as = "UfeHex")] + pub block_hash: FieldElement, + } + + let temp = serde_json::Value::deserialize(deserializer)?; + + if let Ok(mut elements) = Vec::::deserialize(&temp) { + let field0 = serde_json::from_value::( + elements + .pop() + .ok_or_else(|| serde::de::Error::custom("invalid sequence length"))?, + ) + .map_err(|err| serde::de::Error::custom(format!("failed to parse element: {}", err)))?; + + Ok(Self { + block_hash: field0.block_hash, + }) + } else if let Ok(object) = AsObject::deserialize(&temp) { + Ok(Self { + block_hash: object.block_hash, + }) + } else { + Err(serde::de::Error::custom("invalid sequence length")) + } + } +} + +impl Serialize for TraceTransactionRequest { + fn serialize(&self, serializer: S) -> Result { + #[serde_as] + #[derive(Serialize)] + #[serde(transparent)] + struct Field0<'a> { + #[serde_as(as = "UfeHex")] + pub transaction_hash: &'a FieldElement, + } + + use serde::ser::SerializeSeq; + + let mut seq = serializer.serialize_seq(None)?; + + seq.serialize_element(&Field0 { + transaction_hash: &self.transaction_hash, + })?; + + seq.end() + } +} + +impl<'a> Serialize for TraceTransactionRequestRef<'a> { + fn serialize(&self, serializer: S) -> Result { + #[serde_as] + #[derive(Serialize)] + #[serde(transparent)] + struct Field0<'a> { + #[serde_as(as = "UfeHex")] + pub transaction_hash: &'a FieldElement, + } + + use serde::ser::SerializeSeq; + + let mut seq = serializer.serialize_seq(None)?; + + seq.serialize_element(&Field0 { + transaction_hash: self.transaction_hash, + })?; + + seq.end() + } +} + +impl<'de> Deserialize<'de> for TraceTransactionRequest { + fn deserialize>(deserializer: D) -> Result { + #[serde_as] + #[derive(Deserialize)] + struct AsObject { + #[serde_as(as = "UfeHex")] + pub transaction_hash: FieldElement, + } + + #[serde_as] + #[derive(Deserialize)] + #[serde(transparent)] + struct Field0 { + #[serde_as(as = "UfeHex")] + pub transaction_hash: FieldElement, + } + + let temp = serde_json::Value::deserialize(deserializer)?; + + if let Ok(mut elements) = Vec::::deserialize(&temp) { + let field0 = serde_json::from_value::( + elements + .pop() + .ok_or_else(|| serde::de::Error::custom("invalid sequence length"))?, + ) + .map_err(|err| serde::de::Error::custom(format!("failed to parse element: {}", err)))?; + + Ok(Self { + transaction_hash: field0.transaction_hash, + }) + } else if let Ok(object) = AsObject::deserialize(&temp) { + Ok(Self { + transaction_hash: object.transaction_hash, + }) + } else { + Err(serde::de::Error::custom("invalid sequence length")) + } + } +} diff --git a/starknet-core/src/types/mod.rs b/starknet-core/src/types/mod.rs index bee171a6..dcb698db 100644 --- a/starknet-core/src/types/mod.rs +++ b/starknet-core/src/types/mod.rs @@ -16,21 +16,24 @@ mod codegen; pub use codegen::{ BlockStatus, BlockTag, BlockWithTxHashes, BlockWithTxs, BroadcastedDeclareTransactionV1, BroadcastedDeclareTransactionV2, BroadcastedDeployAccountTransaction, - BroadcastedInvokeTransaction, CompressedLegacyContractClass, ContractStorageDiffItem, - DeclareTransactionReceipt, DeclareTransactionV0, DeclareTransactionV1, DeclareTransactionV2, - DeclaredClassItem, DeployAccountTransaction, DeployAccountTransactionReceipt, - DeployTransaction, DeployTransactionReceipt, DeployedContractItem, EmittedEvent, - EntryPointsByType, Event, EventFilter, EventFilterWithPage, EventsChunk, FeeEstimate, - FlattenedSierraClass, FunctionCall, FunctionStateMutability, InvokeTransactionReceipt, - InvokeTransactionV0, InvokeTransactionV1, L1HandlerTransaction, L1HandlerTransactionReceipt, + BroadcastedInvokeTransaction, CallType, CompressedLegacyContractClass, ContractStorageDiffItem, + DeclareTransactionReceipt, DeclareTransactionTrace, DeclareTransactionV0, DeclareTransactionV1, + DeclareTransactionV2, DeclaredClassItem, DeployAccountTransaction, + DeployAccountTransactionReceipt, DeployAccountTransactionTrace, DeployTransaction, + DeployTransactionReceipt, DeployedContractItem, EmittedEvent, EntryPointType, + EntryPointsByType, Event, EventContent, EventFilter, EventFilterWithPage, EventsChunk, + FeeEstimate, FlattenedSierraClass, FunctionCall, FunctionInvocation, FunctionStateMutability, + InvokeTransactionReceipt, InvokeTransactionTrace, InvokeTransactionV0, InvokeTransactionV1, + L1HandlerTransaction, L1HandlerTransactionReceipt, L1HandlerTransactionTrace, LegacyContractEntryPoint, LegacyEntryPointsByType, LegacyEventAbiEntry, LegacyEventAbiType, LegacyFunctionAbiEntry, LegacyFunctionAbiType, LegacyStructAbiEntry, LegacyStructAbiType, LegacyStructMember, LegacyTypedParameter, MsgFromL1, MsgToL1, NonceUpdate, PendingBlockWithTxHashes, PendingBlockWithTxs, PendingDeclareTransactionReceipt, PendingDeployAccountTransactionReceipt, PendingDeployTransactionReceipt, PendingInvokeTransactionReceipt, PendingL1HandlerTransactionReceipt, PendingStateUpdate, - ReplacedClassItem, ResultPageRequest, SierraEntryPoint, StarknetError, StateDiff, StateUpdate, - StorageEntry, SyncStatus, TransactionExecutionStatus, TransactionFinalityStatus, + ReplacedClassItem, ResultPageRequest, RevertedInvocation, SierraEntryPoint, + SimulatedTransaction, SimulationFlag, StarknetError, StateDiff, StateUpdate, StorageEntry, + SyncStatus, TransactionExecutionStatus, TransactionFinalityStatus, TransactionTraceWithHash, }; pub mod eth_address; @@ -243,6 +246,22 @@ pub enum LegacyContractAbiEntry { Struct(LegacyStructAbiEntry), } +#[derive(Debug, Clone, Deserialize)] +#[serde(untagged)] +pub enum TransactionTrace { + Invoke(InvokeTransactionTrace), + DeployAccount(DeployAccountTransactionTrace), + L1Handler(L1HandlerTransactionTrace), + Declare(DeclareTransactionTrace), +} + +#[derive(Debug, Clone, Deserialize)] +#[serde(untagged)] +pub enum ExecuteInvocation { + Success(FunctionInvocation), + Reverted(RevertedInvocation), +} + impl MaybePendingBlockWithTxHashes { pub fn transactions(&self) -> &[FieldElement] { match self { @@ -425,15 +444,6 @@ impl TryFrom for StarknetError { 24 => StarknetError::BlockNotFound, 27 => StarknetError::InvalidTransactionIndex, 28 => StarknetError::ClassHashNotFound, - // JSON-RPC v0.4.0 changes this error code from 25 to 29. Technically we should just - // ignore 25 for good, but since most methods are otherwise identical to v0.3.0, - // accepting the value of 25 here allows some degree of compatibility, meaning some use - // cases can still be run against a v0.3.0 endpoint even though the library itself only - // officially supports v0.4.0. This can be beneficial as v0.3.0 is still widely - // deployed. - // - // TODO: remove this line once JSON-RPC v0.3.0 is phased out - 25 => StarknetError::TransactionHashNotFound, 29 => StarknetError::TransactionHashNotFound, 31 => StarknetError::PageSizeTooBig, 32 => StarknetError::NoBlocks, @@ -453,6 +463,9 @@ impl TryFrom for StarknetError { 61 => StarknetError::UnsupportedTxVersion, 62 => StarknetError::UnsupportedContractClassVersion, 63 => StarknetError::UnexpectedError, + 10 => StarknetError::NoTraceAvailable, + 25 => StarknetError::InvalidTransactionHash, + 26 => StarknetError::InvalidBlockHash, _ => return Err(()), }) } diff --git a/starknet-core/src/types/requests.rs b/starknet-core/src/types/requests.rs index c6bbe8a5..caf7e071 100644 --- a/starknet-core/src/types/requests.rs +++ b/starknet-core/src/types/requests.rs @@ -12,5 +12,7 @@ pub use super::codegen::{ GetStateUpdateRequestRef, GetStorageAtRequest, GetStorageAtRequestRef, GetTransactionByBlockIdAndIndexRequest, GetTransactionByBlockIdAndIndexRequestRef, GetTransactionByHashRequest, GetTransactionByHashRequestRef, GetTransactionReceiptRequest, - GetTransactionReceiptRequestRef, PendingTransactionsRequest, SyncingRequest, + GetTransactionReceiptRequestRef, PendingTransactionsRequest, SimulateTransactionsRequest, + SimulateTransactionsRequestRef, SyncingRequest, TraceBlockTransactionsRequest, + TraceBlockTransactionsRequestRef, TraceTransactionRequest, TraceTransactionRequestRef, }; diff --git a/starknet-core/src/types/serde_impls.rs b/starknet-core/src/types/serde_impls.rs index 3cc1361f..ac959764 100644 --- a/starknet-core/src/types/serde_impls.rs +++ b/starknet-core/src/types/serde_impls.rs @@ -207,6 +207,26 @@ mod enum_ser_impls { } } } + + impl Serialize for TransactionTrace { + fn serialize(&self, serializer: S) -> Result { + match self { + Self::Invoke(variant) => variant.serialize(serializer), + Self::DeployAccount(variant) => variant.serialize(serializer), + Self::L1Handler(variant) => variant.serialize(serializer), + Self::Declare(variant) => variant.serialize(serializer), + } + } + } + + impl Serialize for ExecuteInvocation { + fn serialize(&self, serializer: S) -> Result { + match self { + Self::Success(variant) => variant.serialize(serializer), + Self::Reverted(variant) => variant.serialize(serializer), + } + } + } } #[cfg(test)]