-
Notifications
You must be signed in to change notification settings - Fork 188
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
Improve dojo contract syntax #1458
Comments
Amazing proposal, having a dojo syntax being consistent and even more simpler for devs is very important and good to have.
But my guess is that you aim at having something less cryptic to read the world address inside a system, right?
This should not be an issue as components are usually imported outside of the system. And the system uses the storage access of the contract to interact with it. Or at least on my end I don't see something that may clash here at the first glance. |
It's a good concern. I think in this case it is a bit more intuitive on the contract syntax side, since you only need to define |
isnt it an issue to 'hide' self type, it can be for world, i would prefer to use |
hmm i feel like |
Hi @tarrencev ! I would really appreciate working on a task involving Cairo to put into practice what I've learnt so far :) So, can I work on this task please ? Edit: In fact, it's more Rust development than Cairo but anyway, I'm still motivated to work on this task ;-) |
Let's go for it! You already have an idea on how to tackle this? |
Hi ! Some questions, just to be sure about modifications to be done on #[starknet::interface]
trait IPlayerActions<TContractState> {
fn jump(self: @TContractState, distance: u8);
}
trait IMath {
fn operation(a: felt252, b: felt252);
}
#[dojo::contract]
mod MyContract {
impl PlayerActions of super::IPlayerActions<ContractState> {
fn jump(self: @ContractState, distance: u8) {}
}
impl Math of super::IMath {
fn operation(a: felt252, b: felt252) {}
}
fn free_function_with_state(self: @ContractState){}
fn free_function(name: felt252) {
}
} In this snippet:
In brief, that means that we can automatically add missing Are you ok with that ? @tarrencev @glihm |
Solved by #1594. |
Dojo defines its own native storage model. When using a
dojo::contract
the expectation is that a developer does not use the native starknet storage model. Currently,dojo::contract
syntax leaks the nativestarknet::storage
implementation in the contract interface.This proposal is to modify the
dojo::contract
code expansion and to introduce a newdojo::interface
macro.[dojo::interface]
This macro expands the succinct dojo interface definition into the
starknet::interface
definition, removing the need to pass theContractState
parameters.Old:
New:
[dojo::contract]
This modifies the dojo syntax to remove references to
ContractState
, enabling more succinct and idiomatic dojo implementations. The existing contract code expansion should be updated to expand to the existing syntax. The modifications should be made backward compatible, allowing developers to still pass aContractState
parameter manually.Old:
New:
In addition, the syntax should be modified to enable passing a
world: IWorldDispatcher
argument. In the case it is passed, the macro should remove the arg from the function parameters and inline thelet world = self.world_dispatcher.read();
call.Old:
New:
Open questions
Approach
The implementation should modify the existing contract expansion code here: https://github.com/dojoengine/dojo/blob/main/crates/dojo-lang/src/contract.rs and introduce a similar
interface
expansion implementation.The proposed syntax diff can be seen here: #1457
The text was updated successfully, but these errors were encountered: