Skip to content

Instantly share code, notes, and snippets.

@wangshouh
Last active October 5, 2023 09:08
Show Gist options
  • Save wangshouh/73435344171b1a276828ff13cca1f5fa to your computer and use it in GitHub Desktop.
Save wangshouh/73435344171b1a276828ff13cca1f5fa to your computer and use it in GitHub Desktop.
user: User {
shape: Person
}
exector: Executor {
code: |rust
fn call(
self: @ContractState,
class_hash: ClassHash,
entrypoint: felt252,
calldata: Span<felt252>
) -> Span<felt252> {
starknet::syscalls::library_call_syscall(class_hash, entrypoint, calldata)
.unwrap_syscall()
}
|
}
system: System {
code: |rust
fn execute(ctx: Context, direction: Direction) {
let (mut position, mut moves) = get!(ctx.world, ctx.origin, (Position, Moves));
moves.remaining -= 1;
let next = next_position(position, direction);
set!(ctx.world, (moves, next));
emit!(ctx.world, Moved { player: ctx.origin, x: next.x, y: next.y, });
return ();
}
|
}
world: World {
component: Component {
code: |rust
#[derive(Component, Copy, Drop, Serde, SerdeLen)]
struct Position {
#[key]
player: ContractAddress,
x: u32,
y: u32
}
|
}
auth: Auth {
code: |||rust
fn assert_can_write(self: @ContractState, model: felt252, caller: ContractAddress) {
assert(
IWorld::is_writer(self, model, caller)
|| IWorld::is_owner(self, get_tx_info().unbox().account_contract_address, model)
|| IWorld::is_owner(self, get_tx_info().unbox().account_contract_address, WORLD),
'not writer'
);
}
|||
}
}
user -> exector -> system: execute
system -> world.component: get
system -> world.auth -> world.component: set
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment