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

feat(if-else): add if-else access control #44

Merged
merged 8 commits into from
Jun 23, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions listings/ch00-introduction/if_else/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
target
8 changes: 8 additions & 0 deletions listings/ch00-introduction/if_else/Scarb.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[package]
name = "if_else"
version = "0.1.0"

[dependencies]
starknet = "1.1.0"

[[target.starknet-contract]]
23 changes: 23 additions & 0 deletions listings/ch00-introduction/if_else/src/access_control.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
use starknet::ContractAddress;

#[contract]
mod SimpleAccessControl {
use starknet::get_caller_address;

struct Storage {
owner: starknet::ContractAddress,
HansBhatia marked this conversation as resolved.
Show resolved Hide resolved
}

#[constructor]
fn constructor(_address: starknet::ContractAddress) {
owner::write(_address);
}

#[external]
HansBhatia marked this conversation as resolved.
Show resolved Hide resolved
fn onlyOwner() -> bool {
HansBhatia marked this conversation as resolved.
Show resolved Hide resolved
if (get_caller_address() == owner::read()) {
HansBhatia marked this conversation as resolved.
Show resolved Hide resolved
return true;
}
return false;
}
}
1 change: 1 addition & 0 deletions listings/ch00-introduction/if_else/src/lib.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mod access_control;