diff --git a/Cargo.lock b/Cargo.lock index a7198925a6..f68506cc0d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4831,15 +4831,6 @@ dependencies = [ "url", ] -[[package]] -name = "dojo-language-server" -version = "1.0.5" -dependencies = [ - "cairo-lang-language-server", - "clap", - "dojo-macros", -] - [[package]] name = "dojo-macros" version = "0.1.0" @@ -13752,12 +13743,6 @@ dependencies = [ "anyhow", "async-trait", "cainome 0.4.8", - "cairo-lang-compiler", - "cairo-lang-filesystem", - "cairo-lang-project", - "cairo-lang-starknet", - "cairo-lang-test-plugin", - "cairo-lang-test-runner", "camino", "clap", "clap-verbosity-flag", diff --git a/crates/dojo/world/src/contracts/abigen/world.rs b/crates/dojo/world/src/contracts/abigen/world.rs index eec0cfc5bf..c18410c20d 100644 --- a/crates/dojo/world/src/contracts/abigen/world.rs +++ b/crates/dojo/world/src/contracts/abigen/world.rs @@ -1215,889 +1215,9 @@ impl cainome::cairo_serde::CairoSerde for Event { } } } -impl TryFrom<&starknet::core::types::EmittedEvent> for Event { +impl TryFrom for Event { type Error = String; - fn try_from(event: &starknet::core::types::EmittedEvent) -> Result { - use cainome::cairo_serde::CairoSerde; - if event.keys.is_empty() { - return Err("Event has no key".to_string()); - } - let selector = event.keys[0]; - if selector - == starknet::core::utils::get_selector_from_name("WorldSpawned") - .unwrap_or_else(|_| panic!("Invalid selector for {}", "WorldSpawned")) - { - let mut key_offset = 0 + 1; - let mut data_offset = 0; - let creator = match cainome::cairo_serde::ContractAddress::cairo_deserialize( - &event.data, - data_offset, - ) { - Ok(v) => v, - Err(e) => { - return Err(format!( - "Could not deserialize field {} for {}: {:?}", - "creator", "WorldSpawned", e - )); - } - }; - data_offset += cainome::cairo_serde::ContractAddress::cairo_serialized_size(&creator); - let class_hash = match cainome::cairo_serde::ClassHash::cairo_deserialize( - &event.data, - data_offset, - ) { - Ok(v) => v, - Err(e) => { - return Err(format!( - "Could not deserialize field {} for {}: {:?}", - "class_hash", "WorldSpawned", e - )); - } - }; - data_offset += cainome::cairo_serde::ClassHash::cairo_serialized_size(&class_hash); - return Ok(Event::WorldSpawned(WorldSpawned { creator, class_hash })); - } - let selector = event.keys[0]; - if selector - == starknet::core::utils::get_selector_from_name("WorldUpgraded") - .unwrap_or_else(|_| panic!("Invalid selector for {}", "WorldUpgraded")) - { - let mut key_offset = 0 + 1; - let mut data_offset = 0; - let class_hash = match cainome::cairo_serde::ClassHash::cairo_deserialize( - &event.data, - data_offset, - ) { - Ok(v) => v, - Err(e) => { - return Err(format!( - "Could not deserialize field {} for {}: {:?}", - "class_hash", "WorldUpgraded", e - )); - } - }; - data_offset += cainome::cairo_serde::ClassHash::cairo_serialized_size(&class_hash); - return Ok(Event::WorldUpgraded(WorldUpgraded { class_hash })); - } - let selector = event.keys[0]; - if selector - == starknet::core::utils::get_selector_from_name("NamespaceRegistered") - .unwrap_or_else(|_| panic!("Invalid selector for {}", "NamespaceRegistered")) - { - let mut key_offset = 0 + 1; - let mut data_offset = 0; - let namespace = - match cainome::cairo_serde::ByteArray::cairo_deserialize(&event.keys, key_offset) { - Ok(v) => v, - Err(e) => { - return Err(format!( - "Could not deserialize field {} for {}: {:?}", - "namespace", "NamespaceRegistered", e - )); - } - }; - key_offset += cainome::cairo_serde::ByteArray::cairo_serialized_size(&namespace); - let hash = - match starknet::core::types::Felt::cairo_deserialize(&event.data, data_offset) { - Ok(v) => v, - Err(e) => { - return Err(format!( - "Could not deserialize field {} for {}: {:?}", - "hash", "NamespaceRegistered", e - )); - } - }; - data_offset += starknet::core::types::Felt::cairo_serialized_size(&hash); - return Ok(Event::NamespaceRegistered(NamespaceRegistered { namespace, hash })); - } - let selector = event.keys[0]; - if selector - == starknet::core::utils::get_selector_from_name("ModelRegistered") - .unwrap_or_else(|_| panic!("Invalid selector for {}", "ModelRegistered")) - { - let mut key_offset = 0 + 1; - let mut data_offset = 0; - let name = - match cainome::cairo_serde::ByteArray::cairo_deserialize(&event.keys, key_offset) { - Ok(v) => v, - Err(e) => { - return Err(format!( - "Could not deserialize field {} for {}: {:?}", - "name", "ModelRegistered", e - )); - } - }; - key_offset += cainome::cairo_serde::ByteArray::cairo_serialized_size(&name); - let namespace = - match cainome::cairo_serde::ByteArray::cairo_deserialize(&event.keys, key_offset) { - Ok(v) => v, - Err(e) => { - return Err(format!( - "Could not deserialize field {} for {}: {:?}", - "namespace", "ModelRegistered", e - )); - } - }; - key_offset += cainome::cairo_serde::ByteArray::cairo_serialized_size(&namespace); - let class_hash = match cainome::cairo_serde::ClassHash::cairo_deserialize( - &event.data, - data_offset, - ) { - Ok(v) => v, - Err(e) => { - return Err(format!( - "Could not deserialize field {} for {}: {:?}", - "class_hash", "ModelRegistered", e - )); - } - }; - data_offset += cainome::cairo_serde::ClassHash::cairo_serialized_size(&class_hash); - let address = match cainome::cairo_serde::ContractAddress::cairo_deserialize( - &event.data, - data_offset, - ) { - Ok(v) => v, - Err(e) => { - return Err(format!( - "Could not deserialize field {} for {}: {:?}", - "address", "ModelRegistered", e - )); - } - }; - data_offset += cainome::cairo_serde::ContractAddress::cairo_serialized_size(&address); - return Ok(Event::ModelRegistered(ModelRegistered { - name, - namespace, - class_hash, - address, - })); - } - let selector = event.keys[0]; - if selector - == starknet::core::utils::get_selector_from_name("EventRegistered") - .unwrap_or_else(|_| panic!("Invalid selector for {}", "EventRegistered")) - { - let mut key_offset = 0 + 1; - let mut data_offset = 0; - let name = - match cainome::cairo_serde::ByteArray::cairo_deserialize(&event.keys, key_offset) { - Ok(v) => v, - Err(e) => { - return Err(format!( - "Could not deserialize field {} for {}: {:?}", - "name", "EventRegistered", e - )); - } - }; - key_offset += cainome::cairo_serde::ByteArray::cairo_serialized_size(&name); - let namespace = - match cainome::cairo_serde::ByteArray::cairo_deserialize(&event.keys, key_offset) { - Ok(v) => v, - Err(e) => { - return Err(format!( - "Could not deserialize field {} for {}: {:?}", - "namespace", "EventRegistered", e - )); - } - }; - key_offset += cainome::cairo_serde::ByteArray::cairo_serialized_size(&namespace); - let class_hash = match cainome::cairo_serde::ClassHash::cairo_deserialize( - &event.data, - data_offset, - ) { - Ok(v) => v, - Err(e) => { - return Err(format!( - "Could not deserialize field {} for {}: {:?}", - "class_hash", "EventRegistered", e - )); - } - }; - data_offset += cainome::cairo_serde::ClassHash::cairo_serialized_size(&class_hash); - let address = match cainome::cairo_serde::ContractAddress::cairo_deserialize( - &event.data, - data_offset, - ) { - Ok(v) => v, - Err(e) => { - return Err(format!( - "Could not deserialize field {} for {}: {:?}", - "address", "EventRegistered", e - )); - } - }; - data_offset += cainome::cairo_serde::ContractAddress::cairo_serialized_size(&address); - return Ok(Event::EventRegistered(EventRegistered { - name, - namespace, - class_hash, - address, - })); - } - let selector = event.keys[0]; - if selector - == starknet::core::utils::get_selector_from_name("ContractRegistered") - .unwrap_or_else(|_| panic!("Invalid selector for {}", "ContractRegistered")) - { - let mut key_offset = 0 + 1; - let mut data_offset = 0; - let name = - match cainome::cairo_serde::ByteArray::cairo_deserialize(&event.keys, key_offset) { - Ok(v) => v, - Err(e) => { - return Err(format!( - "Could not deserialize field {} for {}: {:?}", - "name", "ContractRegistered", e - )); - } - }; - key_offset += cainome::cairo_serde::ByteArray::cairo_serialized_size(&name); - let namespace = - match cainome::cairo_serde::ByteArray::cairo_deserialize(&event.keys, key_offset) { - Ok(v) => v, - Err(e) => { - return Err(format!( - "Could not deserialize field {} for {}: {:?}", - "namespace", "ContractRegistered", e - )); - } - }; - key_offset += cainome::cairo_serde::ByteArray::cairo_serialized_size(&namespace); - let address = match cainome::cairo_serde::ContractAddress::cairo_deserialize( - &event.data, - data_offset, - ) { - Ok(v) => v, - Err(e) => { - return Err(format!( - "Could not deserialize field {} for {}: {:?}", - "address", "ContractRegistered", e - )); - } - }; - data_offset += cainome::cairo_serde::ContractAddress::cairo_serialized_size(&address); - let class_hash = match cainome::cairo_serde::ClassHash::cairo_deserialize( - &event.data, - data_offset, - ) { - Ok(v) => v, - Err(e) => { - return Err(format!( - "Could not deserialize field {} for {}: {:?}", - "class_hash", "ContractRegistered", e - )); - } - }; - data_offset += cainome::cairo_serde::ClassHash::cairo_serialized_size(&class_hash); - let salt = - match starknet::core::types::Felt::cairo_deserialize(&event.data, data_offset) { - Ok(v) => v, - Err(e) => { - return Err(format!( - "Could not deserialize field {} for {}: {:?}", - "salt", "ContractRegistered", e - )); - } - }; - data_offset += starknet::core::types::Felt::cairo_serialized_size(&salt); - return Ok(Event::ContractRegistered(ContractRegistered { - name, - namespace, - address, - class_hash, - salt, - })); - } - let selector = event.keys[0]; - if selector - == starknet::core::utils::get_selector_from_name("ModelUpgraded") - .unwrap_or_else(|_| panic!("Invalid selector for {}", "ModelUpgraded")) - { - let mut key_offset = 0 + 1; - let mut data_offset = 0; - let selector = - match starknet::core::types::Felt::cairo_deserialize(&event.keys, key_offset) { - Ok(v) => v, - Err(e) => { - return Err(format!( - "Could not deserialize field {} for {}: {:?}", - "selector", "ModelUpgraded", e - )); - } - }; - key_offset += starknet::core::types::Felt::cairo_serialized_size(&selector); - let class_hash = match cainome::cairo_serde::ClassHash::cairo_deserialize( - &event.data, - data_offset, - ) { - Ok(v) => v, - Err(e) => { - return Err(format!( - "Could not deserialize field {} for {}: {:?}", - "class_hash", "ModelUpgraded", e - )); - } - }; - data_offset += cainome::cairo_serde::ClassHash::cairo_serialized_size(&class_hash); - let address = match cainome::cairo_serde::ContractAddress::cairo_deserialize( - &event.data, - data_offset, - ) { - Ok(v) => v, - Err(e) => { - return Err(format!( - "Could not deserialize field {} for {}: {:?}", - "address", "ModelUpgraded", e - )); - } - }; - data_offset += cainome::cairo_serde::ContractAddress::cairo_serialized_size(&address); - let prev_address = match cainome::cairo_serde::ContractAddress::cairo_deserialize( - &event.data, - data_offset, - ) { - Ok(v) => v, - Err(e) => { - return Err(format!( - "Could not deserialize field {} for {}: {:?}", - "prev_address", "ModelUpgraded", e - )); - } - }; - data_offset += - cainome::cairo_serde::ContractAddress::cairo_serialized_size(&prev_address); - return Ok(Event::ModelUpgraded(ModelUpgraded { - selector, - class_hash, - address, - prev_address, - })); - } - let selector = event.keys[0]; - if selector - == starknet::core::utils::get_selector_from_name("EventUpgraded") - .unwrap_or_else(|_| panic!("Invalid selector for {}", "EventUpgraded")) - { - let mut key_offset = 0 + 1; - let mut data_offset = 0; - let selector = - match starknet::core::types::Felt::cairo_deserialize(&event.keys, key_offset) { - Ok(v) => v, - Err(e) => { - return Err(format!( - "Could not deserialize field {} for {}: {:?}", - "selector", "EventUpgraded", e - )); - } - }; - key_offset += starknet::core::types::Felt::cairo_serialized_size(&selector); - let class_hash = match cainome::cairo_serde::ClassHash::cairo_deserialize( - &event.data, - data_offset, - ) { - Ok(v) => v, - Err(e) => { - return Err(format!( - "Could not deserialize field {} for {}: {:?}", - "class_hash", "EventUpgraded", e - )); - } - }; - data_offset += cainome::cairo_serde::ClassHash::cairo_serialized_size(&class_hash); - let address = match cainome::cairo_serde::ContractAddress::cairo_deserialize( - &event.data, - data_offset, - ) { - Ok(v) => v, - Err(e) => { - return Err(format!( - "Could not deserialize field {} for {}: {:?}", - "address", "EventUpgraded", e - )); - } - }; - data_offset += cainome::cairo_serde::ContractAddress::cairo_serialized_size(&address); - let prev_address = match cainome::cairo_serde::ContractAddress::cairo_deserialize( - &event.data, - data_offset, - ) { - Ok(v) => v, - Err(e) => { - return Err(format!( - "Could not deserialize field {} for {}: {:?}", - "prev_address", "EventUpgraded", e - )); - } - }; - data_offset += - cainome::cairo_serde::ContractAddress::cairo_serialized_size(&prev_address); - return Ok(Event::EventUpgraded(EventUpgraded { - selector, - class_hash, - address, - prev_address, - })); - } - let selector = event.keys[0]; - if selector - == starknet::core::utils::get_selector_from_name("ContractUpgraded") - .unwrap_or_else(|_| panic!("Invalid selector for {}", "ContractUpgraded")) - { - let mut key_offset = 0 + 1; - let mut data_offset = 0; - let selector = - match starknet::core::types::Felt::cairo_deserialize(&event.keys, key_offset) { - Ok(v) => v, - Err(e) => { - return Err(format!( - "Could not deserialize field {} for {}: {:?}", - "selector", "ContractUpgraded", e - )); - } - }; - key_offset += starknet::core::types::Felt::cairo_serialized_size(&selector); - let class_hash = match cainome::cairo_serde::ClassHash::cairo_deserialize( - &event.data, - data_offset, - ) { - Ok(v) => v, - Err(e) => { - return Err(format!( - "Could not deserialize field {} for {}: {:?}", - "class_hash", "ContractUpgraded", e - )); - } - }; - data_offset += cainome::cairo_serde::ClassHash::cairo_serialized_size(&class_hash); - return Ok(Event::ContractUpgraded(ContractUpgraded { selector, class_hash })); - } - let selector = event.keys[0]; - if selector - == starknet::core::utils::get_selector_from_name("ContractInitialized") - .unwrap_or_else(|_| panic!("Invalid selector for {}", "ContractInitialized")) - { - let mut key_offset = 0 + 1; - let mut data_offset = 0; - let selector = - match starknet::core::types::Felt::cairo_deserialize(&event.keys, key_offset) { - Ok(v) => v, - Err(e) => { - return Err(format!( - "Could not deserialize field {} for {}: {:?}", - "selector", "ContractInitialized", e - )); - } - }; - key_offset += starknet::core::types::Felt::cairo_serialized_size(&selector); - let init_calldata = match Vec::::cairo_deserialize( - &event.data, - data_offset, - ) { - Ok(v) => v, - Err(e) => { - return Err(format!( - "Could not deserialize field {} for {}: {:?}", - "init_calldata", "ContractInitialized", e - )); - } - }; - data_offset += - Vec::::cairo_serialized_size(&init_calldata); - return Ok(Event::ContractInitialized(ContractInitialized { selector, init_calldata })); - } - let selector = event.keys[0]; - if selector - == starknet::core::utils::get_selector_from_name("EventEmitted") - .unwrap_or_else(|_| panic!("Invalid selector for {}", "EventEmitted")) - { - let mut key_offset = 0 + 1; - let mut data_offset = 0; - let selector = - match starknet::core::types::Felt::cairo_deserialize(&event.keys, key_offset) { - Ok(v) => v, - Err(e) => { - return Err(format!( - "Could not deserialize field {} for {}: {:?}", - "selector", "EventEmitted", e - )); - } - }; - key_offset += starknet::core::types::Felt::cairo_serialized_size(&selector); - let system_address = match cainome::cairo_serde::ContractAddress::cairo_deserialize( - &event.keys, - key_offset, - ) { - Ok(v) => v, - Err(e) => { - return Err(format!( - "Could not deserialize field {} for {}: {:?}", - "system_address", "EventEmitted", e - )); - } - }; - key_offset += - cainome::cairo_serde::ContractAddress::cairo_serialized_size(&system_address); - let keys = match Vec::::cairo_deserialize( - &event.data, - data_offset, - ) { - Ok(v) => v, - Err(e) => { - return Err(format!( - "Could not deserialize field {} for {}: {:?}", - "keys", "EventEmitted", e - )); - } - }; - data_offset += Vec::::cairo_serialized_size(&keys); - let values = match Vec::::cairo_deserialize( - &event.data, - data_offset, - ) { - Ok(v) => v, - Err(e) => { - return Err(format!( - "Could not deserialize field {} for {}: {:?}", - "values", "EventEmitted", e - )); - } - }; - data_offset += Vec::::cairo_serialized_size(&values); - return Ok(Event::EventEmitted(EventEmitted { - selector, - system_address, - keys, - values, - })); - } - let selector = event.keys[0]; - if selector - == starknet::core::utils::get_selector_from_name("MetadataUpdate") - .unwrap_or_else(|_| panic!("Invalid selector for {}", "MetadataUpdate")) - { - let mut key_offset = 0 + 1; - let mut data_offset = 0; - let resource = - match starknet::core::types::Felt::cairo_deserialize(&event.keys, key_offset) { - Ok(v) => v, - Err(e) => { - return Err(format!( - "Could not deserialize field {} for {}: {:?}", - "resource", "MetadataUpdate", e - )); - } - }; - key_offset += starknet::core::types::Felt::cairo_serialized_size(&resource); - let uri = match cainome::cairo_serde::ByteArray::cairo_deserialize( - &event.data, - data_offset, - ) { - Ok(v) => v, - Err(e) => { - return Err(format!( - "Could not deserialize field {} for {}: {:?}", - "uri", "MetadataUpdate", e - )); - } - }; - data_offset += cainome::cairo_serde::ByteArray::cairo_serialized_size(&uri); - let hash = - match starknet::core::types::Felt::cairo_deserialize(&event.data, data_offset) { - Ok(v) => v, - Err(e) => { - return Err(format!( - "Could not deserialize field {} for {}: {:?}", - "hash", "MetadataUpdate", e - )); - } - }; - data_offset += starknet::core::types::Felt::cairo_serialized_size(&hash); - return Ok(Event::MetadataUpdate(MetadataUpdate { resource, uri, hash })); - } - let selector = event.keys[0]; - if selector - == starknet::core::utils::get_selector_from_name("StoreSetRecord") - .unwrap_or_else(|_| panic!("Invalid selector for {}", "StoreSetRecord")) - { - let mut key_offset = 0 + 1; - let mut data_offset = 0; - let selector = - match starknet::core::types::Felt::cairo_deserialize(&event.keys, key_offset) { - Ok(v) => v, - Err(e) => { - return Err(format!( - "Could not deserialize field {} for {}: {:?}", - "selector", "StoreSetRecord", e - )); - } - }; - key_offset += starknet::core::types::Felt::cairo_serialized_size(&selector); - let entity_id = - match starknet::core::types::Felt::cairo_deserialize(&event.keys, key_offset) { - Ok(v) => v, - Err(e) => { - return Err(format!( - "Could not deserialize field {} for {}: {:?}", - "entity_id", "StoreSetRecord", e - )); - } - }; - key_offset += starknet::core::types::Felt::cairo_serialized_size(&entity_id); - let keys = match Vec::::cairo_deserialize( - &event.data, - data_offset, - ) { - Ok(v) => v, - Err(e) => { - return Err(format!( - "Could not deserialize field {} for {}: {:?}", - "keys", "StoreSetRecord", e - )); - } - }; - data_offset += Vec::::cairo_serialized_size(&keys); - let values = match Vec::::cairo_deserialize( - &event.data, - data_offset, - ) { - Ok(v) => v, - Err(e) => { - return Err(format!( - "Could not deserialize field {} for {}: {:?}", - "values", "StoreSetRecord", e - )); - } - }; - data_offset += Vec::::cairo_serialized_size(&values); - return Ok(Event::StoreSetRecord(StoreSetRecord { selector, entity_id, keys, values })); - } - let selector = event.keys[0]; - if selector - == starknet::core::utils::get_selector_from_name("StoreUpdateRecord") - .unwrap_or_else(|_| panic!("Invalid selector for {}", "StoreUpdateRecord")) - { - let mut key_offset = 0 + 1; - let mut data_offset = 0; - let selector = - match starknet::core::types::Felt::cairo_deserialize(&event.keys, key_offset) { - Ok(v) => v, - Err(e) => { - return Err(format!( - "Could not deserialize field {} for {}: {:?}", - "selector", "StoreUpdateRecord", e - )); - } - }; - key_offset += starknet::core::types::Felt::cairo_serialized_size(&selector); - let entity_id = - match starknet::core::types::Felt::cairo_deserialize(&event.keys, key_offset) { - Ok(v) => v, - Err(e) => { - return Err(format!( - "Could not deserialize field {} for {}: {:?}", - "entity_id", "StoreUpdateRecord", e - )); - } - }; - key_offset += starknet::core::types::Felt::cairo_serialized_size(&entity_id); - let values = match Vec::::cairo_deserialize( - &event.data, - data_offset, - ) { - Ok(v) => v, - Err(e) => { - return Err(format!( - "Could not deserialize field {} for {}: {:?}", - "values", "StoreUpdateRecord", e - )); - } - }; - data_offset += Vec::::cairo_serialized_size(&values); - return Ok(Event::StoreUpdateRecord(StoreUpdateRecord { selector, entity_id, values })); - } - let selector = event.keys[0]; - if selector - == starknet::core::utils::get_selector_from_name("StoreUpdateMember") - .unwrap_or_else(|_| panic!("Invalid selector for {}", "StoreUpdateMember")) - { - let mut key_offset = 0 + 1; - let mut data_offset = 0; - let selector = - match starknet::core::types::Felt::cairo_deserialize(&event.keys, key_offset) { - Ok(v) => v, - Err(e) => { - return Err(format!( - "Could not deserialize field {} for {}: {:?}", - "selector", "StoreUpdateMember", e - )); - } - }; - key_offset += starknet::core::types::Felt::cairo_serialized_size(&selector); - let entity_id = - match starknet::core::types::Felt::cairo_deserialize(&event.keys, key_offset) { - Ok(v) => v, - Err(e) => { - return Err(format!( - "Could not deserialize field {} for {}: {:?}", - "entity_id", "StoreUpdateMember", e - )); - } - }; - key_offset += starknet::core::types::Felt::cairo_serialized_size(&entity_id); - let member_selector = - match starknet::core::types::Felt::cairo_deserialize(&event.keys, key_offset) { - Ok(v) => v, - Err(e) => { - return Err(format!( - "Could not deserialize field {} for {}: {:?}", - "member_selector", "StoreUpdateMember", e - )); - } - }; - key_offset += starknet::core::types::Felt::cairo_serialized_size(&member_selector); - let values = match Vec::::cairo_deserialize( - &event.data, - data_offset, - ) { - Ok(v) => v, - Err(e) => { - return Err(format!( - "Could not deserialize field {} for {}: {:?}", - "values", "StoreUpdateMember", e - )); - } - }; - data_offset += Vec::::cairo_serialized_size(&values); - return Ok(Event::StoreUpdateMember(StoreUpdateMember { - selector, - entity_id, - member_selector, - values, - })); - } - let selector = event.keys[0]; - if selector - == starknet::core::utils::get_selector_from_name("StoreDelRecord") - .unwrap_or_else(|_| panic!("Invalid selector for {}", "StoreDelRecord")) - { - let mut key_offset = 0 + 1; - let mut data_offset = 0; - let selector = - match starknet::core::types::Felt::cairo_deserialize(&event.keys, key_offset) { - Ok(v) => v, - Err(e) => { - return Err(format!( - "Could not deserialize field {} for {}: {:?}", - "selector", "StoreDelRecord", e - )); - } - }; - key_offset += starknet::core::types::Felt::cairo_serialized_size(&selector); - let entity_id = - match starknet::core::types::Felt::cairo_deserialize(&event.keys, key_offset) { - Ok(v) => v, - Err(e) => { - return Err(format!( - "Could not deserialize field {} for {}: {:?}", - "entity_id", "StoreDelRecord", e - )); - } - }; - key_offset += starknet::core::types::Felt::cairo_serialized_size(&entity_id); - return Ok(Event::StoreDelRecord(StoreDelRecord { selector, entity_id })); - } - let selector = event.keys[0]; - if selector - == starknet::core::utils::get_selector_from_name("WriterUpdated") - .unwrap_or_else(|_| panic!("Invalid selector for {}", "WriterUpdated")) - { - let mut key_offset = 0 + 1; - let mut data_offset = 0; - let resource = - match starknet::core::types::Felt::cairo_deserialize(&event.keys, key_offset) { - Ok(v) => v, - Err(e) => { - return Err(format!( - "Could not deserialize field {} for {}: {:?}", - "resource", "WriterUpdated", e - )); - } - }; - key_offset += starknet::core::types::Felt::cairo_serialized_size(&resource); - let contract = match cainome::cairo_serde::ContractAddress::cairo_deserialize( - &event.keys, - key_offset, - ) { - Ok(v) => v, - Err(e) => { - return Err(format!( - "Could not deserialize field {} for {}: {:?}", - "contract", "WriterUpdated", e - )); - } - }; - key_offset += cainome::cairo_serde::ContractAddress::cairo_serialized_size(&contract); - let value = match bool::cairo_deserialize(&event.data, data_offset) { - Ok(v) => v, - Err(e) => { - return Err(format!( - "Could not deserialize field {} for {}: {:?}", - "value", "WriterUpdated", e - )); - } - }; - data_offset += bool::cairo_serialized_size(&value); - return Ok(Event::WriterUpdated(WriterUpdated { resource, contract, value })); - } - let selector = event.keys[0]; - if selector - == starknet::core::utils::get_selector_from_name("OwnerUpdated") - .unwrap_or_else(|_| panic!("Invalid selector for {}", "OwnerUpdated")) - { - let mut key_offset = 0 + 1; - let mut data_offset = 0; - let resource = - match starknet::core::types::Felt::cairo_deserialize(&event.keys, key_offset) { - Ok(v) => v, - Err(e) => { - return Err(format!( - "Could not deserialize field {} for {}: {:?}", - "resource", "OwnerUpdated", e - )); - } - }; - key_offset += starknet::core::types::Felt::cairo_serialized_size(&resource); - let contract = match cainome::cairo_serde::ContractAddress::cairo_deserialize( - &event.keys, - key_offset, - ) { - Ok(v) => v, - Err(e) => { - return Err(format!( - "Could not deserialize field {} for {}: {:?}", - "contract", "OwnerUpdated", e - )); - } - }; - key_offset += cainome::cairo_serde::ContractAddress::cairo_serialized_size(&contract); - let value = match bool::cairo_deserialize(&event.data, data_offset) { - Ok(v) => v, - Err(e) => { - return Err(format!( - "Could not deserialize field {} for {}: {:?}", - "value", "OwnerUpdated", e - )); - } - }; - data_offset += bool::cairo_serialized_size(&value); - return Ok(Event::OwnerUpdated(OwnerUpdated { resource, contract, value })); - } - Err(format!("Could not match any event from keys {:?}", event.keys)) - } -} -impl TryFrom<&starknet::core::types::Event> for Event { - type Error = String; - fn try_from(event: &starknet::core::types::Event) -> Result { + fn try_from(event: starknet::core::types::EmittedEvent) -> Result { use cainome::cairo_serde::CairoSerde; if event.keys.is_empty() { return Err("Event has no key".to_string()); diff --git a/examples/spawn-and-move/Scarb.lock b/examples/spawn-and-move/Scarb.lock index 01be8f7c23..596dd3f9c8 100644 --- a/examples/spawn-and-move/Scarb.lock +++ b/examples/spawn-and-move/Scarb.lock @@ -24,7 +24,7 @@ dependencies = [ [[package]] name = "dojo_examples" -version = "1.0.4" +version = "1.0.5" dependencies = [ "armory", "bestiary", @@ -40,16 +40,6 @@ dependencies = [ "dojo", ] -[[package]] -name = "dojo_examples" -version = "1.0.5" -dependencies = [ - "armory", - "bestiary", - "dojo", - "dojo_cairo_test", -] - [[package]] name = "dojo_macros" version = "0.1.0"