Skip to content

Commit

Permalink
rename use_legacy_model_storage() to use_legacy_storage() as it's onl…
Browse files Browse the repository at this point in the history
…y for models
  • Loading branch information
remybar committed Mar 3, 2025
1 parent 35a26b8 commit 7026e34
Show file tree
Hide file tree
Showing 12 changed files with 30 additions and 22 deletions.
2 changes: 1 addition & 1 deletion crates/dojo/core-cairo-test/Scarb.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ version = 1

[[package]]
name = "dojo"
version = "1.2.1"
version = "1.2.2"
dependencies = [
"dojo_plugin",
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,9 @@ pub mod attacker_model {
unpacked_size: Self::unpacked_size(self),
}
}

fn use_legacy_storage(self: @ContractState) -> bool {
false
}
}
}
4 changes: 4 additions & 0 deletions crates/dojo/core-cairo-test/src/tests/helpers/helpers.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ pub mod foo_invalid_name {
unpacked_size: Self::unpacked_size(self),
}
}

fn use_legacy_storage(self: @ContractState) -> bool {
false
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions crates/dojo/core/src/model/component.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub impl IModelImpl<TContractState, M, +Model<M>> of IModel<TContractState> {
Model::<M>::definition()
}

fn use_legacy_model_storage(self: @TContractState) -> bool {
Model::<M>::use_legacy_model_storage()
fn use_legacy_storage(self: @TContractState) -> bool {
Model::<M>::use_legacy_storage()
}
}
2 changes: 1 addition & 1 deletion crates/dojo/core/src/model/definition.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub enum ModelIndex {
pub trait ModelDefinition<T> {
fn name() -> ByteArray;
fn layout() -> Layout;
fn use_legacy_model_storage() -> bool;
fn use_legacy_storage() -> bool;
fn schema() -> Struct;
fn size() -> Option<usize>;
}
Expand Down
2 changes: 1 addition & 1 deletion crates/dojo/core/src/model/interface.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ pub trait IModel<T> {
fn unpacked_size(self: @T) -> Option<usize>;
fn packed_size(self: @T) -> Option<usize>;
fn definition(self: @T) -> dojo::model::ModelDef;
fn use_legacy_model_storage(self: @T) -> bool;
fn use_legacy_storage(self: @T) -> bool;
}
8 changes: 4 additions & 4 deletions crates/dojo/core/src/model/model.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ pub trait Model<M> {
fn layout() -> Layout;
/// Returns the layout of a field in the model.
fn field_layout(field_selector: felt252) -> Option<Layout>;
/// Indicates if the model uses the legacy model storage (true), or
/// Indicates if the model uses the legacy storage (true), or
/// the new one (false).
fn use_legacy_model_storage() -> bool;
fn use_legacy_storage() -> bool;
/// Returns the unpacked size of the model. Only applicable for fixed size models.
fn unpacked_size() -> Option<usize>;
/// Returns the packed size of the model. Only applicable for fixed size models.
Expand Down Expand Up @@ -151,8 +151,8 @@ pub impl ModelImpl<M, +ModelParser<M>, +ModelDefinition<M>, +Serde<M>, +Drop<M>>
find_model_field_layout(Self::layout(), field_selector)
}

fn use_legacy_model_storage() -> bool {
ModelDefinition::<M>::use_legacy_model_storage()
fn use_legacy_storage() -> bool {
ModelDefinition::<M>::use_legacy_storage()
}

fn schema() -> Struct {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub mod m_$model_type$_definition {
}

#[inline(always)]
fn use_legacy_model_storage() -> bool {
fn use_legacy_storage() -> bool {
$use_legacy_storage$
}

Expand Down
8 changes: 4 additions & 4 deletions crates/dojo/world/src/contracts/abigen/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -670,12 +670,12 @@ impl<A: starknet::accounts::ConnectedAccount + Sync> ModelContract<A> {
}
#[allow(clippy::ptr_arg)]
#[allow(clippy::too_many_arguments)]
pub fn use_legacy_model_storage(&self) -> cainome::cairo_serde::call::FCall<A::Provider, bool> {
pub fn use_legacy_storage(&self) -> cainome::cairo_serde::call::FCall<A::Provider, bool> {
use cainome::cairo_serde::CairoSerde;
let mut __calldata = vec![];
let __call = starknet::core::types::FunctionCall {
contract_address: self.address,
entry_point_selector: starknet::macros::selector!("use_legacy_model_storage"),
entry_point_selector: starknet::macros::selector!("use_legacy_storage"),
calldata: __calldata,
};
cainome::cairo_serde::call::FCall::new(__call, self.provider())
Expand Down Expand Up @@ -799,12 +799,12 @@ impl<P: starknet::providers::Provider + Sync> ModelContractReader<P> {
}
#[allow(clippy::ptr_arg)]
#[allow(clippy::too_many_arguments)]
pub fn use_legacy_model_storage(&self) -> cainome::cairo_serde::call::FCall<P, bool> {
pub fn use_legacy_storage(&self) -> cainome::cairo_serde::call::FCall<P, bool> {
use cainome::cairo_serde::CairoSerde;
let mut __calldata = vec![];
let __call = starknet::core::types::FunctionCall {
contract_address: self.address,
entry_point_selector: starknet::macros::selector!("use_legacy_model_storage"),
entry_point_selector: starknet::macros::selector!("use_legacy_storage"),
calldata: __calldata,
};
cainome::cairo_serde::call::FCall::new(__call, self.provider())
Expand Down
6 changes: 3 additions & 3 deletions crates/dojo/world/src/contracts/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ pub trait ModelReader<E> {
async fn packed_size(&self) -> Result<u32, E>;
async fn unpacked_size(&self) -> Result<u32, E>;
async fn layout(&self) -> Result<abigen::model::Layout, E>;
async fn use_legacy_model_storage(&self) -> Result<bool, E>;
async fn use_legacy_storage(&self) -> Result<bool, E>;
}

#[derive(Debug)]
Expand Down Expand Up @@ -206,8 +206,8 @@ where
Ok(self.model_reader.layout().call().await?)
}

async fn use_legacy_model_storage(&self) -> Result<bool, ModelError> {
Ok(self.model_reader.use_legacy_model_storage().call().await?)
async fn use_legacy_storage(&self) -> Result<bool, ModelError> {
Ok(self.model_reader.use_legacy_storage().call().await?)
}
}

Expand Down
8 changes: 4 additions & 4 deletions crates/sozo/ops/src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ where
};
let schema = model.schema().await?;

// in old models, this `use_legacy_model_storage` function does not exist,
// in old models, this `use_legacy_storage` function does not exist,
// so returns true.
// If the error is due to unknown model or whatever, it will be catched by
// a previous model reader call.
let use_legacy_storage = model.use_legacy_model_storage().await.unwrap_or(true);
let use_legacy_storage = model.use_legacy_storage().await.unwrap_or(true);

deep_print_layout(&tag, &layout, &schema, use_legacy_storage);

Expand Down Expand Up @@ -123,11 +123,11 @@ where
let schema = model.schema().await?;
let values = model.entity_storage(&keys).await?;

// in old models, this `use_legacy_model_storage` function does not exist,
// in old models, this `use_legacy_storage` function does not exist,
// so returns true.
// If the error is due to unknown model or whatever, it will be catched by
// a previous model reader call.
let use_legacy_storage = model.use_legacy_model_storage().await.unwrap_or(true);
let use_legacy_storage = model.use_legacy_storage().await.unwrap_or(true);

Ok((format_deep_record(&schema, &keys, &values, use_legacy_storage), schema, values))
}
Expand Down
2 changes: 1 addition & 1 deletion crates/torii/sqlite/src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ impl ModelReader<Error> for ModelSQLReader {
Ok(self.layout.clone())
}

async fn use_legacy_model_storage(&self) -> Result<bool, Error> {
async fn use_legacy_storage(&self) -> Result<bool, Error> {
// TODO: manage the new use_legacy_storage model function
Ok(false)
}
Expand Down

0 comments on commit 7026e34

Please sign in to comment.