-
Notifications
You must be signed in to change notification settings - Fork 182
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cleaning/Refactoring of the dojo-core crate. (#2187)
* chore: cleaning/refactoring dojo-core * move to edition 2024_07 * fix: fix test --------- Co-authored-by: glihm <[email protected]>
- Loading branch information
Showing
150 changed files
with
43,249 additions
and
3,764 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
scarb 2.6.4 | ||
scarb 2.7.0-rc.3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
10 changes: 4 additions & 6 deletions
10
crates/dojo-core/src/base.cairo → ...ojo-core/src/contract/base_contract.cairo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,81 @@ | ||
pub mod base; | ||
#[cfg(test)] | ||
mod base_test; | ||
pub mod config; | ||
pub mod database; | ||
#[cfg(test)] | ||
mod database_test; | ||
pub mod interfaces; | ||
pub mod model; | ||
#[cfg(test)] | ||
mod model_test; | ||
pub mod contract; | ||
pub mod packing; | ||
#[cfg(test)] | ||
mod packing_test; | ||
pub mod world; | ||
#[cfg(test)] | ||
mod world_test; | ||
pub mod utils; | ||
#[cfg(test)] | ||
mod utils_test; | ||
|
||
// Since Scarb 2.6.0 there's an optimization that does not | ||
// build tests for dependencies and it's not configurable. | ||
// | ||
// To expose correctly the test utils for a package using dojo-core, | ||
// we need to it in the `lib` target or using the `#[cfg(target: "test")]` | ||
// attribute. | ||
// | ||
// Since `test_utils` is using `TEST_CLASS_HASH` to factorize some deployment | ||
// core, we place it under the test target manually. | ||
#[cfg(target: "test")] | ||
pub mod test_utils; | ||
pub mod contract { | ||
mod base_contract; | ||
pub use base_contract::base; | ||
pub mod contract; | ||
pub use contract::{IContract, IContractDispatcher, IContractDispatcherTrait}; | ||
pub mod upgradeable; | ||
} | ||
|
||
#[cfg(test)] | ||
mod benchmarks; | ||
pub mod model { | ||
pub mod introspect; | ||
pub mod layout; | ||
pub use layout::{Layout, FieldLayout}; | ||
|
||
pub mod model; | ||
pub use model::{ | ||
Model, ModelIndex, ModelEntity, IModel, IModelDispatcher, IModelDispatcherTrait, | ||
deploy_and_get_metadata | ||
}; | ||
|
||
pub mod components; | ||
pub mod resource_metadata; | ||
pub mod metadata; | ||
pub use metadata::{ResourceMetadata, ResourceMetadataTrait, resource_metadata}; | ||
pub(crate) use metadata::{initial_address, initial_class_hash}; | ||
} | ||
|
||
pub(crate) mod storage { | ||
pub(crate) mod database; | ||
pub(crate) mod packing; | ||
pub(crate) mod layout; | ||
pub(crate) mod storage; | ||
} | ||
|
||
pub mod utils { | ||
// Since Scarb 2.6.0 there's an optimization that does not | ||
// build tests for dependencies and it's not configurable. | ||
// | ||
// To expose correctly the test utils for a package using dojo-core, | ||
// we need to it in the `lib` target or using the `#[cfg(target: "test")]` | ||
// attribute. | ||
// | ||
// Since `test_utils` is using `TEST_CLASS_HASH` to factorize some deployment | ||
// core, we place it under the test target manually. | ||
#[cfg(target: "test")] | ||
pub mod test; | ||
|
||
pub mod utils; | ||
pub use utils::{ | ||
bytearray_hash, entity_id_from_keys, find_field_layout, find_model_field_layout, any_none, | ||
sum, combine_key | ||
}; | ||
} | ||
|
||
pub mod world { | ||
pub(crate) mod update; | ||
pub(crate) mod config; | ||
|
||
mod world_contract; | ||
pub use world_contract::{ | ||
world, IWorld, IWorldDispatcher, IWorldDispatcherTrait, IWorldProvider, | ||
IWorldProviderDispatcher, IWorldProviderDispatcherTrait | ||
}; | ||
pub(crate) use world_contract::{ | ||
IUpgradeableWorld, IUpgradeableWorldDispatcher, IUpgradeableWorldDispatcherTrait | ||
}; | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
mod model { | ||
mod introspect; | ||
mod model; | ||
} | ||
mod storage { | ||
mod database; | ||
mod packing; | ||
mod storage; | ||
} | ||
mod base; | ||
mod benchmarks; | ||
mod world; | ||
mod utils; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
use dojo::storage::packing::calculate_packed_size; | ||
|
||
#[derive(Copy, Drop, Serde, Debug, PartialEq)] | ||
pub struct FieldLayout { | ||
pub selector: felt252, | ||
pub layout: Layout | ||
} | ||
|
||
#[derive(Copy, Drop, Serde, Debug, PartialEq)] | ||
pub enum Layout { | ||
Fixed: Span<u8>, | ||
Struct: Span<FieldLayout>, | ||
Tuple: Span<Layout>, | ||
// We can't have `Layout` here as it will cause infinite recursion. | ||
// And `Box` is not serializable. So using a Span, even if it's to have | ||
// one element, does the trick. | ||
Array: Span<Layout>, | ||
ByteArray, | ||
// there is one layout per variant. | ||
// the `selector` field identifies the variant | ||
// the `layout` defines the variant data (could be empty for variant without data). | ||
Enum: Span<FieldLayout>, | ||
} | ||
|
||
/// Compute the full size in bytes of a layout, when all the fields | ||
/// are bit-packed. | ||
/// Could be None if at least a field has a dynamic size. | ||
pub fn compute_packed_size(layout: Layout) -> Option<usize> { | ||
if let Layout::Fixed(layout) = layout { | ||
let mut span_layout = layout; | ||
Option::Some(calculate_packed_size(ref span_layout)) | ||
} else { | ||
Option::None | ||
} | ||
} |
Oops, something went wrong.