diff --git a/rpc-state-reader/src/blockifier_state_reader.rs b/rpc-state-reader/src/blockifier_state_reader.rs index 0099fdc..e4c4af3 100644 --- a/rpc-state-reader/src/blockifier_state_reader.rs +++ b/rpc-state-reader/src/blockifier_state_reader.rs @@ -409,10 +409,11 @@ mod tests { use std::num::NonZeroU128; - use crate::rpc_state::{BlockValue, RpcCallInfo}; + use crate::rpc_state::{BlockValue, L2ToL1Msg, RpcCallInfo}; use super::*; use blockifier::execution::call_info::CallInfo; + use cairo_lang_starknet_classes::abi::Event; use pretty_assertions_sorted::assert_eq_sorted; use test_case::test_case; #[test] @@ -642,6 +643,13 @@ mod tests { internal_calls: value.inner_calls.iter().map(|ci| ci.into()).collect(), // We don't have the revert reason string in the trace so we just make sure it doesn't revert revert_reason: value.execution.failed.then_some("Default String".into()), + events: value.execution.events.iter().map(|e| e.into()).collect(), + l2_l1_messages: value + .execution + .l2_to_l1_messages + .iter() + .map(|llm| llm.into()) + .collect(), } } } diff --git a/rpc-state-reader/src/rpc_state.rs b/rpc-state-reader/src/rpc_state.rs index 814ca1c..51e24d1 100644 --- a/rpc-state-reader/src/rpc_state.rs +++ b/rpc-state-reader/src/rpc_state.rs @@ -1,4 +1,7 @@ -use blockifier::blockifier::block::GasPrices; +use blockifier::{ + blockifier::block::GasPrices, + execution::call_info::{OrderedEvent, OrderedL2ToL1Message}, +}; use cairo_vm::vm::runners::{ builtin_runner::{ BITWISE_BUILTIN_NAME, EC_OP_BUILTIN_NAME, HASH_BUILTIN_NAME, KECCAK_BUILTIN_NAME, @@ -14,10 +17,10 @@ use serde_json::json; use starknet::core::types::ContractClass as SNContractClass; use starknet_api::{ block::{BlockNumber, BlockTimestamp}, - core::{ChainId, ClassHash, ContractAddress}, + core::{ChainId, ClassHash, ContractAddress, EthAddress}, hash::{StarkFelt, StarkHash}, state::StorageKey, - transaction::{Transaction as SNTransaction, TransactionHash}, + transaction::{EventContent, L2ToL1Payload, Transaction as SNTransaction, TransactionHash}, }; use std::{collections::HashMap, env, fmt::Display, num::NonZeroU128}; @@ -95,6 +98,38 @@ pub enum BlockValue { Hash(StarkHash), } +#[derive(Debug, Clone, Eq, PartialEq, Deserialize)] +pub struct Event { + pub order: usize, + pub event: EventContent +} + +#[derive(Debug, Clone, Eq, PartialEq, Deserialize)] +pub struct L2ToL1Msg { + pub order: usize, + pub to_address: EthAddress, + pub payload: L2ToL1Payload, +} + +impl From<&OrderedL2ToL1Message> for L2ToL1Msg { + fn from(value: &OrderedL2ToL1Message) -> Self { + Self { + order: value.order, + to_address: value.message.to_address, + payload: value.message.payload.clone(), + } + } +} + +impl From<&OrderedEvent> for Event { + fn from(value: &OrderedEvent) -> Self { + Self { + order: value.order, + event: value.event.clone(), + } + } +} + impl From for BlockValue { fn from(value: BlockTag) -> Self { BlockValue::Tag(value) @@ -167,6 +202,8 @@ pub struct RpcCallInfo { pub calldata: Option>, pub internal_calls: Vec, pub revert_reason: Option, + pub events: Vec, + pub l2_l1_messages: Vec, } #[derive(Debug, Deserialize)] @@ -303,11 +340,42 @@ impl<'de> Deserialize<'de> for RpcCallInfo { .push(serde_json::from_value(call.clone()).map_err(serde::de::Error::custom)?); } + let events_value = value + .get("events") + .ok_or(serde::de::Error::custom( + RpcStateError::MissingRpcResponseField("events".to_string()), + ))? + .clone(); + let mut events = vec![]; + + for event in events_value.as_array().ok_or(serde::de::Error::custom( + RpcStateError::RpcResponseWrongType("events".to_string()), + ))? { + events.push(serde_json::from_value(event.clone()).map_err(serde::de::Error::custom)?) + } + + let msg_l1_l2_value = value + .get("l2_l1_messages") + .ok_or(serde::de::Error::custom( + RpcStateError::MissingRpcResponseField("l2_l1_messages".to_string()), + ))? + .clone(); + let mut l2_l1_messages = vec![]; + + for msg in msg_l1_l2_value.as_array().ok_or(serde::de::Error::custom( + RpcStateError::RpcResponseWrongType("l2_l1_messages".to_string()), + ))? { + l2_l1_messages + .push(serde_json::from_value(msg.clone()).map_err(serde::de::Error::custom)?) + } + Ok(RpcCallInfo { retdata, calldata, internal_calls, revert_reason: None, + events, + l2_l1_messages, }) } }