Skip to content
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

Remove u250 type #508

Merged
merged 1 commit into from
Jun 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions crates/dojo-core/src/auth/components.cairo
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
use dojo_core::integer::u250;

#[derive(Component, Copy, Drop, Serde)]
struct AuthStatus {
is_authorized: bool
}

#[derive(Component, Copy, Drop, Serde)]
struct AuthRole {
id: u250
id: felt252
}
42 changes: 20 additions & 22 deletions crates/dojo-core/src/auth/systems.cairo
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
use dojo_core::integer::u250;

#[derive(Drop, Serde)]
struct Route {
target_id: u250,
role_id: u250,
resource_id: u250,
target_id: felt252,
role_id: felt252,
resource_id: felt252,
}

trait RouteTrait {
fn new(target_id: u250, role_id: u250, resource_id: u250) -> Route;
fn new(target_id: felt252, role_id: felt252, resource_id: felt252) -> Route;
}

impl RouteImpl of RouteTrait {
fn new(target_id: u250, role_id: u250, resource_id: u250) -> Route {
fn new(target_id: felt252, role_id: felt252, resource_id: felt252) -> Route {
Route { target_id, role_id, resource_id, }
}
}
Expand Down Expand Up @@ -43,7 +41,7 @@ mod RouteAuth {
mod IsAccountAdmin {
use traits::Into;
use box::BoxTrait;
use dojo_core::{auth::components::{AuthStatus, AuthRole}, integer::u250};
use dojo_core::auth::components::{AuthStatus, AuthRole};
use dojo_core::world::World;

fn execute(ctx: Context) -> bool {
Expand All @@ -58,10 +56,10 @@ mod IsAccountAdmin {
#[system]
mod IsAuthorized {
use traits::Into;
use dojo_core::{auth::components::{AuthStatus, AuthRole}, integer::u250};
use dojo_core::auth::components::{AuthStatus, AuthRole};
use dojo_core::world::World;

fn execute(ctx: Context, target_id: u250, resource_id: u250) -> bool {
fn execute(ctx: Context, target_id: felt252, resource_id: felt252) -> bool {
// Check if execution role is not set
let scoped_role = if ctx.execution_role.id == 0.into() {
// Use default component-scoped role
Expand Down Expand Up @@ -110,9 +108,9 @@ mod IsAuthorized {
mod GrantAuthRole {
use traits::Into;
use array::ArrayTrait;
use dojo_core::{auth::components::AuthRole, integer::u250};
use dojo_core::auth::components::AuthRole;

fn execute(target_id: u250, role_id: u250) {
fn execute(target_id: felt252, role_id: felt252) {
commands::set_entity(target_id.into(), (AuthRole { id: role_id }));
}
}
Expand All @@ -121,20 +119,20 @@ mod GrantAuthRole {
mod GrantScopedAuthRole {
use traits::Into;
use array::ArrayTrait;
use dojo_core::{auth::components::AuthRole, integer::u250};
use dojo_core::auth::components::AuthRole;


fn execute(target_id: u250, role_id: u250, resource_id: u250) {
fn execute(target_id: felt252, role_id: felt252, resource_id: felt252) {
commands::set_entity((target_id, resource_id).into(), (AuthRole { id: role_id }));
}
}

#[system]
mod GrantResource {
use traits::Into;
use dojo_core::{auth::components::AuthStatus, integer::u250};
use dojo_core::auth::components::AuthStatus;

fn execute(role_id: u250, resource_id: u250) {
fn execute(role_id: felt252, resource_id: felt252) {
commands::set_entity((role_id, resource_id).into(), (AuthStatus { is_authorized: true }));
}
}
Expand All @@ -143,9 +141,9 @@ mod GrantResource {
mod RevokeAuthRole {
use traits::Into;
use array::ArrayTrait;
use dojo_core::{auth::components::AuthRole, integer::u250};
use dojo_core::auth::components::AuthRole;

fn execute(target_id: u250) {
fn execute(target_id: felt252) {
commands::set_entity(target_id.into(), (AuthRole { id: 0.into() }));
}
}
Expand All @@ -154,19 +152,19 @@ mod RevokeAuthRole {
mod RevokeScopedAuthRole {
use traits::Into;
use array::ArrayTrait;
use dojo_core::{auth::components::AuthRole, integer::u250};
use dojo_core::auth::components::AuthRole;

fn execute(target_id: u250, resource_id: u250) {
fn execute(target_id: felt252, resource_id: felt252) {
commands::set_entity((target_id, resource_id).into(), (AuthRole { id: 0.into() }));
}
}

#[system]
mod RevokeResource {
use traits::Into;
use dojo_core::{auth::components::AuthStatus, integer::u250};
use dojo_core::auth::components::AuthStatus;

fn execute(role_id: u250, resource_id: u250) {
fn execute(role_id: felt252, resource_id: felt252) {
commands::set_entity((role_id, resource_id).into(), (AuthStatus { is_authorized: false }));
}
}
1 change: 0 additions & 1 deletion crates/dojo-core/src/executor.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ mod Executor {
use box::BoxTrait;
use traits::Into;
use dojo_core::execution_context::Context;
use dojo_core::integer::u250;
use dojo_core::interfaces::{IWorldDispatcher, ISystemLibraryDispatcher, ISystemDispatcherTrait};
use dojo_core::auth::components::AuthRole;
use starknet::contract_address::ContractAddressIntoFelt252;
Expand Down
179 changes: 0 additions & 179 deletions crates/dojo-core/src/integer.cairo

This file was deleted.

8 changes: 4 additions & 4 deletions crates/dojo-core/src/interfaces.cairo
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use dojo_core::{
integer::u250, serde::SpanSerde, storage::query::Query,
serde::SpanSerde, storage::query::Query,
auth::systems::Route, auth::components::AuthRole, execution_context::Context
};
use starknet::{ClassHash, ContractAddress};
Expand All @@ -23,15 +23,15 @@ trait IWorld {
fn set_entity(
context: Context, component: felt252, key: Query, offset: u8, value: Span<felt252>
);
fn entities(component: felt252, partition: u250) -> (Span<u250>, Span<Span<felt252>>);
fn entities(component: felt252, partition: felt252) -> (Span<felt252>, Span<Span<felt252>>);
fn set_executor(contract_address: ContractAddress);
fn is_authorized(system: felt252, component: felt252, execution_role: AuthRole) -> bool;
fn is_account_admin() -> bool;
fn is_system_for_execution(system: felt252) -> bool;
fn delete_entity(context: Context, component: felt252, query: Query);
fn assume_role(role_id: u250, systems: Array<felt252>);
fn assume_role(role_id: felt252, systems: Array<felt252>);
fn clear_role(systems: Array<felt252>);
fn execution_role() -> u250;
fn execution_role() -> felt252;
fn system_components(system: felt252) -> Array<(felt252, bool)>;
}

Expand Down
1 change: 0 additions & 1 deletion crates/dojo-core/src/lib.cairo
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
mod auth;
mod executor;
mod execution_context;
mod integer;
mod interfaces;
mod serde;
mod storage;
Expand Down
Loading