diff --git a/crates/dojo-client/src/contract/component.rs b/crates/dojo-client/src/contract/component.rs index 60b1db6e46..f88f5207e9 100644 --- a/crates/dojo-client/src/contract/component.rs +++ b/crates/dojo-client/src/contract/component.rs @@ -80,29 +80,27 @@ impl<'a, P: Provider + Sync> ComponentReader<'a, P> { .map_err(ComponentError::ContractReaderError)?; let mut members = vec![]; - for chunk in res[3..].chunks(4) { - if chunk.len() != 4 { + for chunk in res[3..].chunks(3) { + if chunk.len() != 3 { return Err(ComponentError::InvalidSchemaLength); } + let is_key: u8 = chunk[2].try_into().map_err(|_| ComponentError::ConvertingFelt)?; + members.push(Member { name: parse_cairo_short_string(&chunk[0]) .map_err(ComponentError::ParseCairoShortStringError)?, ty: parse_cairo_short_string(&chunk[1]) .map_err(ComponentError::ParseCairoShortStringError)?, - slot: chunk[2].try_into().map_err(|_| ComponentError::ConvertingFelt)?, - offset: chunk[3].try_into().map_err(|_| ComponentError::ConvertingFelt)?, + key: is_key == 1, }); } Ok(members) } - pub async fn length( - &self, - block_id: BlockId, - ) -> Result> { - let entrypoint = get_selector_from_name("length").unwrap(); + pub async fn size(&self, block_id: BlockId) -> Result> { + let entrypoint = get_selector_from_name("size").unwrap(); let res = self .world @@ -119,30 +117,16 @@ impl<'a, P: Provider + Sync> ComponentReader<'a, P> { pub async fn entity( &self, - partition_id: FieldElement, keys: Vec, block_id: BlockId, ) -> Result, ComponentError> { - let length: u8 = self.length(block_id).await?.try_into().unwrap(); - - let table = if partition_id == FieldElement::ZERO { - self.name - } else { - poseidon_hash_many(&[self.name, partition_id]) - }; - - let id = if keys.len() == 1 { - keys[0] - } else { - let mut keys = keys; - keys.insert(0, keys.len().into()); - poseidon_hash_many(&keys) - }; + let size: u8 = self.size(block_id).await?.try_into().unwrap(); - let key = poseidon_hash_many(&[short_string!("dojo_storage"), table, id]); + let key = poseidon_hash_many(&keys); + let key = poseidon_hash_many(&[short_string!("dojo_storage"), self.name, key]); let mut values = vec![]; - for slot in 0..length { + for slot in 0..size { let value = self .world .provider diff --git a/crates/dojo-client/src/contract/component_test.rs b/crates/dojo-client/src/contract/component_test.rs index 0204bc3976..1000748c82 100644 --- a/crates/dojo-client/src/contract/component_test.rs +++ b/crates/dojo-client/src/contract/component_test.rs @@ -28,7 +28,7 @@ async fn test_component() { assert_eq!( component.class_hash(), FieldElement::from_hex_be( - "0x02da8fb6056624dd6fa7070497350a13914a21e2a53f171271f72721c5448912" + "0x04caa1806451739b6fb470652b8066a11f80e847d49003b43cca75a2fd7647b6" ) .unwrap() ); @@ -38,8 +38,9 @@ async fn test_component() { assert_eq!( members, vec![ - Member { name: "x".into(), ty: "u32".into(), slot: 0, offset: 0 }, - Member { name: "y".into(), ty: "u32".into(), slot: 1, offset: 0 } + Member { name: "player".into(), ty: "ContractAddress".into(), key: true }, + Member { name: "x".into(), ty: "u32".into(), key: false }, + Member { name: "y".into(), ty: "u32".into(), key: false } ] ) } diff --git a/crates/dojo-client/src/contract/system.rs b/crates/dojo-client/src/contract/system.rs index ede2fa4a1e..9717beb8a5 100644 --- a/crates/dojo-client/src/contract/system.rs +++ b/crates/dojo-client/src/contract/system.rs @@ -65,13 +65,6 @@ impl<'a, A: ConnectedAccount + Sync> System<'a, A> { self.reader.call(calldata, block_id).await.map_err(SystemError::ReaderError) } - pub async fn dependencies( - &self, - block_id: BlockId, - ) -> Result, SystemError::Error>> { - self.reader.dependencies(block_id).await.map_err(SystemError::ReaderError) - } - pub async fn execute( &self, calldata: Vec, @@ -115,8 +108,10 @@ impl<'a, P: Provider + Sync> SystemReader<'a, P> { .call( FunctionCall { contract_address: world.address, - calldata: vec![cairo_short_string_to_felt(&name) - .map_err(SystemReaderError::CairoShortStringToFeltError)?], + calldata: vec![ + cairo_short_string_to_felt(&name) + .map_err(SystemReaderError::CairoShortStringToFeltError)?, + ], entry_point_selector: get_selector_from_name("system").unwrap(), }, block_id, diff --git a/crates/dojo-client/src/contract/system_test.rs b/crates/dojo-client/src/contract/system_test.rs index 30dd783932..fc13e07e79 100644 --- a/crates/dojo-client/src/contract/system_test.rs +++ b/crates/dojo-client/src/contract/system_test.rs @@ -2,7 +2,6 @@ use camino::Utf8PathBuf; use dojo_test_utils::sequencer::{ get_default_test_starknet_config, SequencerConfig, TestSequencer, }; -use dojo_types::system::Dependency; use starknet::accounts::Account; use starknet::core::types::{BlockId, BlockTag}; use starknet_crypto::FieldElement; @@ -24,20 +23,11 @@ async fn test_system() { let block_id: BlockId = BlockId::Tag(BlockTag::Latest); let world = WorldContract::new(world_address, &account); let spawn = world.system("spawn", block_id).await.unwrap(); - let dependencies = spawn.dependencies(block_id).await.unwrap(); - assert_eq!( - dependencies, - vec![ - Dependency { name: "Moves".into(), read: false, write: true }, - Dependency { name: "Position".into(), read: false, write: true } - ] - ); let _ = spawn.execute(vec![]).await.unwrap(); let component = world.component("Moves", block_id).await.unwrap(); - let moves = - component.entity(FieldElement::ZERO, vec![account.address()], block_id).await.unwrap(); + let moves = component.entity(vec![account.address()], block_id).await.unwrap(); assert_eq!(moves, vec![10_u8.into()]); @@ -46,17 +36,13 @@ async fn test_system() { let _ = move_system.execute(vec![FieldElement::ONE]).await.unwrap(); let _ = move_system.execute(vec![FieldElement::THREE]).await.unwrap(); - let moves = - component.entity(FieldElement::ZERO, vec![account.address()], block_id).await.unwrap(); + let moves = component.entity(vec![account.address()], block_id).await.unwrap(); assert_eq!(moves, vec![8_u8.into()]); let position_component = world.component("Position", block_id).await.unwrap(); - let position = position_component - .entity(FieldElement::ZERO, vec![account.address()], block_id) - .await - .unwrap(); + let position = position_component.entity(vec![account.address()], block_id).await.unwrap(); assert_eq!(position, vec![1_u8.into(), 1_u8.into()]); } diff --git a/crates/dojo-lang/src/component.rs b/crates/dojo-lang/src/component.rs index b995de4d7e..6471dc3183 100644 --- a/crates/dojo-lang/src/component.rs +++ b/crates/dojo-lang/src/component.rs @@ -28,9 +28,8 @@ pub fn handle_component_struct( .members(db) .elements(db) .iter() - .enumerate() - .map(|(slot, member)| { - (member.name(db).text(db), member.type_clause(db).ty(db), slot as u64, 0) + .map(|member| { + (member.name(db).text(db), member.type_clause(db).ty(db), member.has_attr(db, "key")) }) .collect::<_>(); @@ -104,16 +103,38 @@ pub fn handle_component_struct( }) .collect::<_>(); + let schema = elements + .iter() + .map(|member| { + RewriteNode::interpolate_patched( + "array::ArrayTrait::append(ref arr, ('$name$', '$typ$', $is_key$));", + UnorderedHashMap::from([ + ( + "name".to_string(), + RewriteNode::new_trimmed(member.name(db).as_syntax_node()), + ), + ( + "typ".to_string(), + RewriteNode::new_trimmed(member.type_clause(db).ty(db).as_syntax_node()), + ), + ( + "is_key".to_string(), + RewriteNode::Text(member.has_attr(db, "key").to_string()), + ), + ]), + ) + }) + .collect::<_>(); + let name = struct_ast.name(db).text(db); aux_data.components.push(Component { name: name.to_string(), members: members .iter() - .map(|(name, ty, slot, offset)| Member { + .map(|(name, ty, key)| Member { name: name.to_string(), ty: ty.as_syntax_node().get_text(db).trim().to_string(), - slot: *slot, - offset: *offset, + key: *key, }) .collect(), }); @@ -167,6 +188,13 @@ pub fn handle_component_struct( fn size(self: @ContractState) -> usize { dojo::SerdeLen::<$type_name$>::len() } + + #[external(v0)] + fn schema(self: @ContractState) -> Array<(felt252, felt252, bool)> { + let mut arr = array::ArrayTrait::new(); + $schema$ + arr + } } ", UnorderedHashMap::from([ @@ -190,6 +218,7 @@ pub fn handle_component_struct( "component_serialized_values".to_string(), RewriteNode::new_modified(component_serialized_values), ), + ("schema".to_string(), RewriteNode::new_modified(schema)), ]), ), diagnostics, diff --git a/crates/dojo-lang/src/plugin_test_data/component b/crates/dojo-lang/src/plugin_test_data/component index ae66fc7ffb..d9c5904b3c 100644 --- a/crates/dojo-lang/src/plugin_test_data/component +++ b/crates/dojo-lang/src/plugin_test_data/component @@ -111,6 +111,15 @@ mod position { fn size(self: @ContractState) -> usize { dojo::SerdeLen::::len() } + + #[external(v0)] + fn schema(self: @ContractState) -> Array<(felt252, felt252, bool)> { + let mut arr = array::ArrayTrait::new(); + array::ArrayTrait::append(ref arr, ('id', 'felt252', true)); + array::ArrayTrait::append(ref arr, ('x', 'felt252', false)); + array::ArrayTrait::append(ref arr, ('y', 'felt252', false)); + arr + } } impl SerdeLenPosition of dojo::SerdeLen { @@ -187,6 +196,13 @@ mod roles { fn size(self: @ContractState) -> usize { dojo::SerdeLen::::len() } + + #[external(v0)] + fn schema(self: @ContractState) -> Array<(felt252, felt252, bool)> { + let mut arr = array::ArrayTrait::new(); + array::ArrayTrait::append(ref arr, ('role_ids', 'Array', false)); + arr + } } @@ -254,6 +270,15 @@ mod player { fn size(self: @ContractState) -> usize { dojo::SerdeLen::::len() } + + #[external(v0)] + fn schema(self: @ContractState) -> Array<(felt252, felt252, bool)> { + let mut arr = array::ArrayTrait::new(); + array::ArrayTrait::append(ref arr, ('game', 'felt252', true)); + array::ArrayTrait::append(ref arr, ('player', 'ContractAddress', true)); + array::ArrayTrait::append(ref arr, ('name', 'felt252', false)); + arr + } } impl SerdeLenPlayer of dojo::SerdeLen { diff --git a/crates/dojo-types/src/component.rs b/crates/dojo-types/src/component.rs index 7e2bb8d8ba..766f5d2084 100644 --- a/crates/dojo-types/src/component.rs +++ b/crates/dojo-types/src/component.rs @@ -8,6 +8,5 @@ pub struct Member { /// Type of the member. #[serde(rename = "type")] pub ty: String, - pub slot: u64, - pub offset: u8, + pub key: bool, } diff --git a/crates/dojo-types/src/storage.rs b/crates/dojo-types/src/storage.rs index f1bcdc12ec..037d8a85fa 100644 --- a/crates/dojo-types/src/storage.rs +++ b/crates/dojo-types/src/storage.rs @@ -3,6 +3,5 @@ use starknet::core::types::FieldElement; #[derive(Clone, Debug)] pub struct Query { pub address_domain: u32, - pub partition: FieldElement, pub keys: Vec, } diff --git a/crates/sozo/src/commands/component.rs b/crates/sozo/src/commands/component.rs index 04fbbd84fe..1d9a6ed6df 100644 --- a/crates/sozo/src/commands/component.rs +++ b/crates/sozo/src/commands/component.rs @@ -54,10 +54,6 @@ pub enum ComponentCommands { #[arg(help = "Comma seperated values e.g., 0x12345,0x69420,...")] keys: Vec, - #[arg(long = "partition_id", default_value = "0x0")] - #[arg(help = "Entity query partition id.")] - partition_id: FieldElement, - #[command(flatten)] world: WorldOptions, diff --git a/crates/sozo/src/ops/component.rs b/crates/sozo/src/ops/component.rs index c262d6291d..d2aa75a109 100644 --- a/crates/sozo/src/ops/component.rs +++ b/crates/sozo/src/ops/component.rs @@ -44,15 +44,14 @@ pub async fn execute(command: ComponentCommands, env_metadata: Option) -> } } - ComponentCommands::Entity { name, partition_id, keys, starknet, world, .. } => { + ComponentCommands::Entity { name, keys, starknet, world, .. } => { let world_address = world.address(env_metadata.as_ref())?; let provider = starknet.provider(env_metadata.as_ref())?; let world = WorldContractReader::new(world_address, &provider); let component = world.component(&name, BlockId::Tag(BlockTag::Pending)).await?; - let entity = - component.entity(partition_id, keys, BlockId::Tag(BlockTag::Pending)).await?; + let entity = component.entity(keys, BlockId::Tag(BlockTag::Pending)).await?; println!( "{}", diff --git a/crates/sozo/src/ops/system.rs b/crates/sozo/src/ops/system.rs index 81559b55b6..7235c81a80 100644 --- a/crates/sozo/src/ops/system.rs +++ b/crates/sozo/src/ops/system.rs @@ -34,11 +34,7 @@ pub async fn execute(command: SystemCommands, env_metadata: Option) -> Re .iter() .enumerate() .filter_map(|(i, d)| { - if d.read { - Some(format!("{}.{}", i + 1, d.name.clone())) - } else { - None - } + if d.read { Some(format!("{}.{}", i + 1, d.name.clone())) } else { None } }) .collect::>(); @@ -46,11 +42,7 @@ pub async fn execute(command: SystemCommands, env_metadata: Option) -> Re .iter() .enumerate() .filter_map(|(i, d)| { - if d.write { - Some(format!("{}. {}", i + 1, d.name.clone())) - } else { - None - } + if d.write { Some(format!("{}. {}", i + 1, d.name.clone())) } else { None } }) .collect::>(); diff --git a/crates/torii/migrations/20230316154230_setup.sql b/crates/torii/migrations/20230316154230_setup.sql index e59f21dbc1..5de6e88144 100644 --- a/crates/torii/migrations/20230316154230_setup.sql +++ b/crates/torii/migrations/20230316154230_setup.sql @@ -27,8 +27,7 @@ CREATE TABLE component_members( component_id TEXT NOT NULL, name TEXT NOT NULL, type TEXT NOT NULL, - slot INTEGER NOT NULL, - offset INTEGER NOT NULL, + key BOOLEAN NOT NULL, created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (component_id, name), FOREIGN KEY (component_id) REFERENCES components(id) @@ -57,14 +56,12 @@ CREATE INDEX idx_systems_created_at ON systems (created_at); CREATE TABLE entities ( id TEXT NOT NULL PRIMARY KEY, - partition TEXT NOT NULL, keys TEXT, component_names TEXT, created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ); -CREATE INDEX idx_entities_partition ON entities (partition); CREATE INDEX idx_entities_keys ON entities (keys); CREATE INDEX idx_entities_keys_create_on ON entities (keys, created_at); diff --git a/crates/torii/src/graphql/object/component_state.rs b/crates/torii/src/graphql/object/component_state.rs index 7e2b031a10..5d504cfc95 100644 --- a/crates/torii/src/graphql/object/component_state.rs +++ b/crates/torii/src/graphql/object/component_state.rs @@ -28,8 +28,7 @@ pub struct ComponentMembers { pub name: String, #[serde(rename = "type")] pub ty: String, - pub slot: i64, - pub offset: i64, + pub key: bool, pub created_at: DateTime, } @@ -236,8 +235,7 @@ pub async fn type_mapping_from( component_id, name, type AS ty, - slot, - offset, + key, created_at FROM component_members WHERE component_id = ? "#, diff --git a/crates/torii/src/graphql/object/entity.rs b/crates/torii/src/graphql/object/entity.rs index 389aeac401..a9a3747814 100644 --- a/crates/torii/src/graphql/object/entity.rs +++ b/crates/torii/src/graphql/object/entity.rs @@ -18,7 +18,6 @@ use crate::graphql::utils::extract_value::extract; #[serde(rename_all = "camelCase")] pub struct Entity { pub id: String, - pub partition: String, pub keys: Option, pub component_names: String, pub created_at: DateTime, diff --git a/crates/torii/src/processors/store_set_record.rs b/crates/torii/src/processors/store_set_record.rs index ff37c2128c..43b6a104e5 100644 --- a/crates/torii/src/processors/store_set_record.rs +++ b/crates/torii/src/processors/store_set_record.rs @@ -35,10 +35,7 @@ impl EventProcessor for StoreSetReco let keys = values_at(&event.data, NUM_KEYS_INDEX)?; let values_index = keys.len() + NUM_KEYS_INDEX + 2; let values = values_at(&event.data, values_index)?; - // TODO: are we removing partitions? - let partition = FieldElement::ZERO; - - storage.set_entity(name, partition, keys, values).await?; + storage.set_entity(name, keys, values).await?; Ok(()) } } diff --git a/crates/torii/src/state/memory.rs b/crates/torii/src/state/memory.rs index 3884e5d6f0..d874cf1e3f 100644 --- a/crates/torii/src/state/memory.rs +++ b/crates/torii/src/state/memory.rs @@ -47,7 +47,6 @@ impl State for InMemory { async fn set_entity( &mut self, component: String, - partition: FieldElement, key: FieldElement, values: HashMap, ) -> Result<()> { @@ -58,12 +57,7 @@ impl State for InMemory { Ok(()) } - async fn delete_entity( - &mut self, - component: String, - partition: FieldElement, - key: FieldElement, - ) -> Result<()> { + async fn delete_entity(&mut self, component: String, key: FieldElement) -> Result<()> { if let Some(component_data) = self.components_to_entites.get_mut(&component) { if let Some(partition_data) = component_data.get_mut(&partition) { partition_data.remove(&key); @@ -72,12 +66,7 @@ impl State for InMemory { Ok(()) } - async fn entity( - &self, - component: String, - partition: FieldElement, - key: FieldElement, - ) -> Result> { + async fn entity(&self, component: String, key: FieldElement) -> Result> { if let Some(component_data) = self.components_to_entites.get(&component) { if let Some(partition_data) = component_data.get(&partition) { if let Some(entity) = partition_data.get(&key) { @@ -88,11 +77,7 @@ impl State for InMemory { Ok(vec![]) } - async fn entities( - &self, - component: String, - partition: FieldElement, - ) -> Result>> { + async fn entities(&self, component: String) -> Result>> { let mut result = Vec::new(); if let Some(component_data) = self.components_to_entites.get(&component) { if let Some(partition_data) = component_data.get(&partition) { diff --git a/crates/torii/src/state/mod.rs b/crates/torii/src/state/mod.rs index 76e8799909..cf6825e909 100644 --- a/crates/torii/src/state/mod.rs +++ b/crates/torii/src/state/mod.rs @@ -34,25 +34,10 @@ pub trait State { async fn set_entity( &self, component: String, - partition: FieldElement, keys: Vec, values: Vec, ) -> Result<()>; - async fn delete_entity( - &self, - component: String, - partition: FieldElement, - key: FieldElement, - ) -> Result<()>; - async fn entity( - &self, - component: String, - partition: FieldElement, - key: FieldElement, - ) -> Result>; - async fn entities( - &self, - component: String, - partition: FieldElement, - ) -> Result>>; + async fn delete_entity(&self, component: String, key: FieldElement) -> Result<()>; + async fn entity(&self, component: String, key: FieldElement) -> Result>; + async fn entities(&self, component: String) -> Result>>; } diff --git a/crates/torii/src/state/sql.rs b/crates/torii/src/state/sql.rs index 9fc9ead4c8..f1cf6ac97d 100644 --- a/crates/torii/src/state/sql.rs +++ b/crates/torii/src/state/sql.rs @@ -163,8 +163,7 @@ impl State for Sql { )]; let mut component_table_query = format!( - "CREATE TABLE IF NOT EXISTS external_{} (entity_id TEXT NOT NULL PRIMARY KEY, \ - partition TEXT NOT NULL, ", + "CREATE TABLE IF NOT EXISTS external_{} (entity_id TEXT NOT NULL PRIMARY KEY, ", component.name.to_lowercase() ); @@ -181,9 +180,9 @@ impl State for Sql { for member in component.members { queries.push(format!( - "INSERT OR IGNORE INTO component_members (component_id, name, type, slot, offset) \ - VALUES ('{}', '{}', '{}', '{}', '{}')", - component_id, member.name, member.ty, member.slot, member.offset, + "INSERT OR IGNORE INTO component_members (component_id, name, type, key) VALUES \ + ('{}', '{}', '{}', '{}')", + component_id, member.name, member.ty, member.key, )); } @@ -207,7 +206,6 @@ impl State for Sql { async fn set_entity( &self, component: String, - partition: FieldElement, keys: Vec, values: Vec, ) -> Result<()> { @@ -221,27 +219,24 @@ impl State for Sql { let keys_str = keys.iter().map(|k| format!("{:#x},", k)).collect::>().join(""); let component_names = component_names(entity_result, &component)?; let insert_entities = format!( - "INSERT INTO entities (id, partition, keys, component_names) VALUES ('{}', '{:#x}', \ - '{}', '{}') ON CONFLICT(id) DO UPDATE SET + "INSERT INTO entities (id, keys, component_names) VALUES ('{}', '{}', '{}') ON \ + CONFLICT(id) DO UPDATE SET component_names=excluded.component_names, updated_at=CURRENT_TIMESTAMP", - entity_id, partition, keys_str, component_names + entity_id, keys_str, component_names ); - let member_results = - sqlx::query("SELECT * FROM component_members WHERE component_id = ? ORDER BY slot") - .bind(component.to_lowercase()) - .fetch_all(&self.pool) - .await?; + let member_results = sqlx::query("SELECT * FROM component_members WHERE component_id = ?") + .bind(component.to_lowercase()) + .fetch_all(&self.pool) + .await?; let (names_str, values_str) = format_values(member_results, values)?; let insert_components = format!( - "INSERT OR REPLACE INTO external_{} (entity_id, partition {}) VALUES ('{}', '{:#x}' \ - {})", + "INSERT OR REPLACE INTO external_{} (entity_id {}) VALUES ('{}' {})", component.to_lowercase(), names_str, entity_id, - partition, values_str ); @@ -251,36 +246,21 @@ impl State for Sql { Ok(()) } - async fn delete_entity( - &self, - component: String, - partition: FieldElement, - key: FieldElement, - ) -> Result<()> { - let query = format!("DELETE FROM {component} WHERE id = {key} AND partition = {partition}"); + async fn delete_entity(&self, component: String, key: FieldElement) -> Result<()> { + let query = format!("DELETE FROM {component} WHERE id = {key}"); self.queue(vec![query]).await; Ok(()) } - async fn entity( - &self, - component: String, - partition: FieldElement, - key: FieldElement, - ) -> Result> { - let query = - format!("SELECT * FROM {component} WHERE id = {key} AND partition = {partition}"); + async fn entity(&self, component: String, key: FieldElement) -> Result> { + let query = format!("SELECT * FROM {component} WHERE id = {key}"); let mut conn: PoolConnection = self.pool.acquire().await?; let row: (i32, String, String) = sqlx::query_as(&query).fetch_one(&mut conn).await?; Ok(serde_json::from_str(&row.2).unwrap()) } - async fn entities( - &self, - component: String, - partition: FieldElement, - ) -> Result>> { - let query = format!("SELECT * FROM {component} WHERE partition = {partition}"); + async fn entities(&self, component: String) -> Result>> { + let query = format!("SELECT * FROM {component}"); let mut conn: PoolConnection = self.pool.acquire().await?; let mut rows = sqlx::query_as::<_, (i32, String, String)>(&query).fetch_all(&mut conn).await?; diff --git a/crates/torii/src/state/sql_test.rs b/crates/torii/src/state/sql_test.rs index 75a368d8ce..edf779568d 100644 --- a/crates/torii/src/state/sql_test.rs +++ b/crates/torii/src/state/sql_test.rs @@ -53,7 +53,7 @@ async fn test_load_from_manifest(pool: SqlitePool) { state .register_component(Component { name: "Test".into(), - members: vec![Member { name: "test".into(), ty: "u32".into(), slot: 0, offset: 1 }], + members: vec![Member { name: "test".into(), ty: "u32".into(), key: false }], class_hash: FieldElement::TWO, }) .await @@ -99,7 +99,6 @@ async fn test_load_from_manifest(pool: SqlitePool) { state .set_entity( "Position".to_string(), - FieldElement::ZERO, vec![FieldElement::ONE], vec![ FieldElement::from_dec_str("42").unwrap(), diff --git a/crates/torii/src/tests/common/mod.rs b/crates/torii/src/tests/common/mod.rs index c44fdfc58e..5c8c4f5238 100644 --- a/crates/torii/src/tests/common/mod.rs +++ b/crates/torii/src/tests/common/mod.rs @@ -48,27 +48,25 @@ pub async fn entity_fixtures(pool: &SqlitePool) { // Set entity with one moves component let key = vec![FieldElement::ONE]; - let partition = FieldElement::from_hex_be("0x0").unwrap(); - let moves_values = vec![FieldElement::from_hex_be("0xa").unwrap()]; - state.set_entity("Moves".to_string(), partition, key, moves_values.clone()).await.unwrap(); + let moves_values = vec![ + FieldElement::from_hex_be("0xbeef").unwrap(), + FieldElement::from_hex_be("0xa").unwrap(), + ]; + state.set_entity("Moves".to_string(), key, moves_values.clone()).await.unwrap(); // Set entity with one position component let key = vec![FieldElement::TWO]; - let partition = FieldElement::from_hex_be("0x0").unwrap(); let position_values = vec![ + FieldElement::from_hex_be("0xbeef").unwrap(), FieldElement::from_hex_be("0x2a").unwrap(), FieldElement::from_hex_be("0x45").unwrap(), ]; - state - .set_entity("Position".to_string(), partition, key, position_values.clone()) - .await - .unwrap(); + state.set_entity("Position".to_string(), key, position_values.clone()).await.unwrap(); // Set an entity with both moves and position components let key = vec![FieldElement::THREE]; - let partition = FieldElement::from_hex_be("0x0").unwrap(); - state.set_entity("Moves".to_string(), partition, key.clone(), moves_values).await.unwrap(); - state.set_entity("Position".to_string(), partition, key, position_values).await.unwrap(); + state.set_entity("Moves".to_string(), key.clone(), moves_values).await.unwrap(); + state.set_entity("Position".to_string(), key, position_values).await.unwrap(); state.execute().await.unwrap(); } diff --git a/packages/core/src/provider/RPCProvider.ts b/packages/core/src/provider/RPCProvider.ts index 7d19ac3282..35bfb7d953 100644 --- a/packages/core/src/provider/RPCProvider.ts +++ b/packages/core/src/provider/RPCProvider.ts @@ -37,7 +37,6 @@ export class RPCProvider extends Provider { calldata: [ strTofelt252Felt(component), query.address_domain, - query.partition, query.keys.length, ...query.keys as any, offset, @@ -56,12 +55,12 @@ export class RPCProvider extends Provider { } } - public async entities(component: string, partition: string, length: number): Promise> { + public async entities(component: string, length: number): Promise> { const call: Call = { entrypoint: WorldEntryPoints.entities, contractAddress: this.getWorldAddress(), - calldata: [strTofelt252Felt(component), partition, length] + calldata: [strTofelt252Felt(component), length] } console.log(call) diff --git a/packages/core/src/provider/provider.ts b/packages/core/src/provider/provider.ts index 6ee27b2b0f..0465422c1e 100644 --- a/packages/core/src/provider/provider.ts +++ b/packages/core/src/provider/provider.ts @@ -11,7 +11,7 @@ export abstract class Provider extends EventEmitter implements ICommands { public abstract entity(component: string, query: Query, offset: number, length: number): Promise>; - public abstract entities(component: string, partition: string, length: number): Promise>; + public abstract entities(component: string, length: number): Promise>; public getWorldAddress(): string { return this.worldAddress; diff --git a/packages/core/src/provider/tests/RPCProvider.test.ts b/packages/core/src/provider/tests/RPCProvider.test.ts index 3b147074d8..49bba85fc8 100644 --- a/packages/core/src/provider/tests/RPCProvider.test.ts +++ b/packages/core/src/provider/tests/RPCProvider.test.ts @@ -18,7 +18,7 @@ describe('RPCProvider', () => { rpcProvider.entity = jest.fn().mockResolvedValue(mockResponse); const component = 'testComponent'; - const query: Query = { partition: 'testPartition', keys: ['key1', 'key2'] }; + const query: Query = { keys: ['key1', 'key2'] }; const offset = 0; const length = 3; @@ -40,7 +40,6 @@ describe('RPCProvider', () => { // { // component: "component1", // query: { - // partition: "partition1", // keys: ["key1", "key2"], // }, // offset: 0, @@ -49,7 +48,6 @@ describe('RPCProvider', () => { // { // component: "component2", // query: { - // partition: "partition2", // keys: ["key3", "key4"], // }, // offset: 0, diff --git a/packages/core/src/types/index.ts b/packages/core/src/types/index.ts index 4dc38f9b78..dd7b88e51a 100644 --- a/packages/core/src/types/index.ts +++ b/packages/core/src/types/index.ts @@ -11,14 +11,13 @@ export enum WorldEntryPoints { export interface Query { address_domain: string, - partition: string, keys: bigint[] } export interface ICommands { entity?(component: string, query: Query, offset: number, length: number): Promise>; - entities?(component: string, partition: string, length: number): Promise>; + entities?(component: string, length: number): Promise>; execute?(name: bigint, execute_calldata: Array): Promise>; register_component?(class_hash: string): Promise; @@ -47,8 +46,7 @@ export type ExecuteState = 'idle' | 'loading' | 'done' | 'error' export interface Members { name: string; type: string; - slot: number; - offset: number; + key: bool; } export interface RegisteredComponent { diff --git a/packages/examples/react-example/src/dojo/setupNetwork.ts b/packages/examples/react-example/src/dojo/setupNetwork.ts index fec0fb537a..b7dd676295 100644 --- a/packages/examples/react-example/src/dojo/setupNetwork.ts +++ b/packages/examples/react-example/src/dojo/setupNetwork.ts @@ -2,7 +2,7 @@ import { defineContractComponents } from "./contractComponents"; import { world } from "./world"; import { number } from 'starknet'; -import { Providers, Query, SyncWorker} from "@dojoengine/core"; +import { Providers, Query, SyncWorker } from "@dojoengine/core"; import { Account, ec } from "starknet"; export const KATANA_ACCOUNT_1_ADDRESS = "0x06f62894bfd81d2e396ce266b2ad0f21e0668d604e5bb1077337b6d570a54aea" @@ -29,7 +29,7 @@ export async function setupNetwork() { signer, execute: async (system: string, call_data: number.BigNumberish[]) => provider.execute(signer, system, call_data), entity: async (component: string, query: Query) => provider.entity(component, query), - entities: async (component: string, partition: string) => provider.entities(component, partition), + entities: async (component: string) => provider.entities(component), world, syncWorker };