Skip to content
Open
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
2 changes: 1 addition & 1 deletion Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ edition = "2023_11"


[dependencies]
starknet = "2.8.2"
starknet = "2.8.0"

[dev-dependencies]
snforge_std = { git = "https://github.com/foundry-rs/starknet-foundry", tag = "v0.27.0" }
Expand Down
8 changes: 7 additions & 1 deletion snfoundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,10 @@ url = "https://free-rpc.nethermind.io/sepolia-juno/"
[sncast.deploy_dev]
account = "deploy_dev"
accounts-file = "~/.starknet_accounts/starknet_open_zeppelin_accounts.json"
url = "https://free-rpc.nethermind.io/sepolia-juno/"
url = "https://free-rpc.nethermind.io/sepolia-juno/"

[sncast.steph]
account = "steph"
accounts-file = "~/.starknet_accounts/starknet_open_zeppelin_accounts.json"
url = "https://free-rpc.nethermind.io/sepolia-juno/"

8 changes: 8 additions & 0 deletions src/errors.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,12 @@ pub mod Errors {
pub const ZERO_ADDRESS: felt252 = 'ZERO ADDRESS!';
pub const SAME_ADDRESS: felt252 = 'CANNOT BE SAME ADDRESS!';
pub const ZERO_VALUE: felt252 = 'CANNOT BE ZERO_VALUE!';
pub const EMPTY_NAME: felt252 = 'NAME CAN NOT BE EMPTY!';
pub const ADMIN_NOT_ALLOWED: felt252 = 'ADMIN CAN NOT BE A STUDENT';
}
// sncast --profile intro account deploy --name intro --fee-token eth
// sncast --account intro declare --url https://free-rpc.nethermind.io/sepolia-juno --fee-token eth --contract-name Counter
// sncast --account intro deploy --url https://free-rpc.nethermind.io/sepolia-juno --fee-token eth --class-hash 0x2ed891bb2417107e425e9c1d1f3ef13bec730d21d3340099de685c52679eaea


// 0x6067f56674b7b566c299d2e076d452cc0d6d28bde699247138ca09d125a6926
17 changes: 17 additions & 0 deletions src/events.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
use starknet::ContractAddress;
#[event]
#[derive(Copy, Drop, Debug, PartialEq, starknet::Event)]
pub enum Event {

StudentAdded: StudentAdded,
}

#[derive(Copy, Drop, Debug, PartialEq, starknet::Event)]
pub struct StudentAdded {
#[key]
pub name: felt252,
pub account: ContractAddress,
pub age: u8,
pub xp: u16,
pub is_active: bool
}
6 changes: 6 additions & 0 deletions src/lib.cairo
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@

// trait - blueprint which specifies the function signatures we intend to build
// module - which houses:
// - storage Struct
// - impl block
mod counter_v1;
mod counter_v2;
mod student_registry;
pub mod student_struct;
pub mod errors;
pub mod events;
26 changes: 24 additions & 2 deletions src/student_registry.cairo
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use starknet::ContractAddress;
use crate::student_struct::Student;
use crate::events::{Event, StudentAdded};

#[starknet::interface]
trait IStudentRegistry<T> {
Expand All @@ -10,6 +11,8 @@ trait IStudentRegistry<T> {

// read-only function to get student
fn get_student(self: @T, account: ContractAddress) -> (felt252, ContractAddress, u8, u16, bool);

fn update_student(ref self: T, _name: felt252, _account: ContractAddress, _age: u8);
}


Expand All @@ -18,11 +21,13 @@ mod StudentRegistry {
use starknet::{ContractAddress, get_caller_address};
use super::{IStudentRegistry, Student};
use core::num::traits::Zero;

#[event]
use crate::events::{Event, StudentAdded};

use starknet::storage::{
StoragePointerReadAccess, StoragePointerWriteAccess, StoragePathEntry, Map
};
use crate::errors::Errors::{NOT_ADMIN, ZERO_ADDRESS};
use crate::errors::Errors::{NOT_ADMIN, ZERO_ADDRESS, EMPTY_NAME, ADMIN_NOT_ALLOWED};

#[storage]
struct Storage {
Expand Down Expand Up @@ -50,12 +55,16 @@ mod StudentRegistry {
_is_active: bool
) {
// validation to check if student account is valid address and not a 0 address
let admin = self.admin.read();
assert(!self.is_zero_address(_account), ZERO_ADDRESS);
assert(_account != admin, ADMIN_NOT_ALLOWED);
assert(_name != '', EMPTY_NAME);
assert(_age > 0, 'age cannot be 0');
let student = Student {
name: _name, account: _account, age: _age, xp: _xp, is_active: _is_active
};
self.students_map.entry(_account).write(student);
//TODO: student is not surposed to input _is_active
}

// read-only function to get student
Expand All @@ -67,6 +76,19 @@ mod StudentRegistry {
let student = self.students_map.entry(account).read();
(student.name, student.account, student.age, student.xp, student.is_active)
}

fn update_student(
ref self: ContractState,
_name: felt252,
_account: ContractAddress,
_age: u8,
) {
let admin = self.admin.read();
assert(!self.is_zero_address(_account), ZERO_ADDRESS);


}

}


Expand Down