-
Notifications
You must be signed in to change notification settings - Fork 191
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(lang): reduce events generated code (#2662)
* Updated functions to clear up naming with serialized * Removed some redundecies in the code * Removed some redundecies in the code * updated benchmarks * Reduced events geenrated code and updated to match model convention * feat: add EventValue for ABI * fix: tests --------- Co-authored-by: glihm <[email protected]>
- Loading branch information
1 parent
8ed5e72
commit cd7b3ca
Showing
11 changed files
with
93 additions
and
61 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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,20 +1,52 @@ | ||
use dojo::meta::Layout; | ||
use dojo::meta::introspect::Struct; | ||
use dojo::meta::{Introspect, introspect::{Struct, Ty}}; | ||
use dojo::model::model::ModelParser; | ||
|
||
#[derive(Drop, Serde, Debug, PartialEq)] | ||
pub struct EventDefinition { | ||
pub struct EventDef { | ||
pub name: ByteArray, | ||
pub layout: Layout, | ||
pub schema: Struct | ||
} | ||
|
||
pub trait EventDefinition<E> { | ||
fn name() -> ByteArray; | ||
} | ||
|
||
pub trait Event<T> { | ||
fn name() -> ByteArray; | ||
fn definition() -> EventDefinition; | ||
fn definition() -> EventDef; | ||
fn layout() -> Layout; | ||
fn schema() -> Struct; | ||
fn serialized_keys(self: @T) -> Span<felt252>; | ||
fn serialized_values(self: @T) -> Span<felt252>; | ||
/// Returns the selector of the event computed for the given namespace hash. | ||
fn selector(namespace_hash: felt252) -> felt252; | ||
} | ||
|
||
pub impl EventImpl<E, +ModelParser<E>, +EventDefinition<E>, +Serde<E>, +Introspect<E>> of Event<E> { | ||
fn name() -> ByteArray { | ||
EventDefinition::<E>::name() | ||
} | ||
fn definition() -> EventDef { | ||
EventDef { name: Self::name(), layout: Self::layout(), schema: Self::schema() } | ||
} | ||
fn layout() -> Layout { | ||
Introspect::<E>::layout() | ||
} | ||
fn schema() -> Struct { | ||
match Introspect::<E>::ty() { | ||
Ty::Struct(s) => s, | ||
_ => panic!("Event: invalid schema.") | ||
} | ||
} | ||
fn serialized_keys(self: @E) -> Span<felt252> { | ||
ModelParser::<E>::serialize_keys(self) | ||
} | ||
fn serialized_values(self: @E) -> Span<felt252> { | ||
ModelParser::<E>::serialize_values(self) | ||
} | ||
fn selector(namespace_hash: felt252) -> felt252 { | ||
dojo::utils::selector_from_namespace_and_name(namespace_hash, @Self::name()) | ||
} | ||
} |
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,4 +1,4 @@ | ||
#[starknet::interface] | ||
pub trait IEvent<T> { | ||
fn definition(self: @T) -> super::EventDefinition; | ||
fn definition(self: @T) -> super::EventDef; | ||
} |
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
Binary file not shown.
Binary file not shown.