-
Notifications
You must be signed in to change notification settings - Fork 175
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: generate contracts for Dojo events #2431
Closed
Closed
Changes from 2 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,65 @@ | ||
use starknet::SyscallResult; | ||
|
||
use dojo::meta::Layout; | ||
use dojo::meta::introspect::Ty; | ||
use dojo::world::IWorldDispatcher; | ||
|
||
pub trait Event<T> { | ||
fn name() -> ByteArray; | ||
fn namespace() -> ByteArray; | ||
fn tag() -> ByteArray; | ||
|
||
fn version() -> u8; | ||
|
||
fn selector() -> felt252; | ||
fn instance_selector(self: @T) -> felt252; | ||
|
||
fn name_hash() -> felt252; | ||
fn namespace_hash() -> felt252; | ||
|
||
fn layout() -> Layout; | ||
fn schema(self: @T) -> Ty; | ||
|
||
fn packed_size() -> Option<usize>; | ||
fn unpacked_size() -> Option<usize>; | ||
} | ||
|
||
#[starknet::interface] | ||
pub trait IEvent<T> { | ||
fn name(self: @T) -> ByteArray; | ||
fn namespace(self: @T) -> ByteArray; | ||
fn tag(self: @T) -> ByteArray; | ||
|
||
fn version(self: @T) -> u8; | ||
|
||
fn selector(self: @T) -> felt252; | ||
fn name_hash(self: @T) -> felt252; | ||
fn namespace_hash(self: @T) -> felt252; | ||
|
||
fn packed_size(self: @T) -> Option<usize>; | ||
fn unpacked_size(self: @T) -> Option<usize>; | ||
|
||
fn layout(self: @T) -> Layout; | ||
fn schema(self: @T) -> Ty; | ||
} | ||
|
||
/// Deploys an event with the given [`ClassHash`] and retrieves it's name. | ||
/// Currently, the event is expected to already be declared by `sozo`. | ||
/// | ||
/// # Arguments | ||
/// | ||
/// * `salt` - A salt used to uniquely deploy the event. | ||
/// * `class_hash` - Class Hash of the event. | ||
pub fn deploy_and_get_metadata( | ||
salt: felt252, class_hash: starknet::ClassHash | ||
) -> SyscallResult<(starknet::ContractAddress, ByteArray, felt252, ByteArray, felt252)> { | ||
let (contract_address, _) = starknet::syscalls::deploy_syscall( | ||
class_hash, salt, [].span(), false, | ||
)?; | ||
let event = IEventDispatcher { contract_address }; | ||
let name = event.name(); | ||
let selector = event.selector(); | ||
let namespace = event.namespace(); | ||
let namespace_hash = event.namespace_hash(); | ||
Result::Ok((contract_address, name, selector, namespace, namespace_hash)) | ||
} |
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
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 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
4 changes: 2 additions & 2 deletions
4
...ojo-core/src/tests/model/introspect.cairo → ...dojo-core/src/tests/meta/introspect.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
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 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider handling deserialization failure without panicking, sensei.
Currently, the code panics if deserialization fails. To enhance resilience, consider propagating the
Option::None
to the caller instead of panicking.Apply this diff to modify the error handling: