dojo icon indicating copy to clipboard operation
dojo copied to clipboard

Add name hash as const

Open bengineer42 opened this issue 4 months ago • 2 comments
trafficstars

Description

THIS WILL NEED AN UPDATE TO THE SCARB REPO

https://github.com/dojoengine/scarb/blob/fix-unit-type/scarb/Cargo.toml#L49

Before the hash of the model name was computed everyt time it was called, this has been moved to compile time and is now part of the ModelDefinition

pub trait ModelDefinition<T> {
    const NAME_HASH: felt252;
    fn name() -> ByteArray;
    fn layout() -> Layout;
    fn schema() -> Struct;
    fn size() -> Option<usize>;
}

Related issue

Tests

  • [ ] Yes
  • [ ] No, because they aren't needed
  • [ ] No, because I need help

Added to documentation?

  • [ ] README.md
  • [ ] Dojo Book
  • [ ] No documentation needed

Checklist

  • [ ] I've formatted my code (scripts/rust_fmt.sh, scripts/cairo_fmt.sh)
  • [ ] I've linted my code (scripts/clippy.sh, scripts/docs.sh)
  • [ ] I've commented my code
  • [ ] I've requested a review after addressing the comments

Summary by CodeRabbit

  • New Features

    • Introduced a new constant representing a hash of the event or model name, making it accessible in event and model definitions.
  • Refactor

    • Updated selector computations for events and models to use the new name hash constant instead of relying on name strings.

bengineer42 avatar Jul 11 '25 10:07 bengineer42