Skip to content

Commit

Permalink
Merge pull request #52 from NoshonNetworks/registry
Browse files Browse the repository at this point in the history
feat: update land
  • Loading branch information
fishonamos authored Oct 13, 2024
2 parents 4dc17f8 + 538e65a commit cee980e
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 15 deletions.
13 changes: 7 additions & 6 deletions land_registry/src/interface.cairo
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
use starknet::ContractAddress;

#[derive(Drop, Serde, starknet::Store)]
struct Land {
#[derive(Drop, Copy, Serde, starknet::Store)]
pub struct Land {
owner: ContractAddress,
location: felt252,
area: u256,
land_use: LandUse,
last_transaction_timestamp: u64,
}

#[derive(Drop, Copy, Clone, Serde, starknet::Store)]
#[derive(Drop, Copy, Clone, Serde, starknet::Store, PartialEq)]
pub enum LandUse {
Residential,
Commercial,
Expand All @@ -29,13 +29,14 @@ impl LandUseIntoFelt252 of Into<LandUse, felt252> {
}

#[starknet::interface]
trait ILandRegistry<TContractState> {
pub trait ILandRegistry<TContractState> {
fn register_land(
ref self: TContractState, location: felt252, area: u256, land_use: LandUse,
) -> u256;
//fn transfer_land(ref self: TContractState, land_id: u256, new_owner: ContractAddress);
fn get_land(self: @TContractState, land_id: u256) -> Land;
//fn get_owner_lands(self: @TContractState, owner_lands: ContractAddress) -> Array<u256>;
//fn get_lands(self: @TContractState, owner: ContractAddress, location: felt252, land_use:
//felt252) -> Array<u256>;
//fn get_lands(self: @TContractState, owner: ContractAddress, location: felt252, land_use:
//felt252) -> Array<u256>;
fn update_land(ref self: TContractState, land_id: u256, area: u256, land_use: LandUse);
}
27 changes: 20 additions & 7 deletions land_registry/src/land_register.cairo
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#[starknet::contract]
mod LandRegistryContract {
pub mod LandRegistryContract {
use starknet::{get_caller_address, get_block_timestamp, ContractAddress};
use land_registry::interface::{ILandRegistry, Land, LandUse};
use core::array::ArrayTrait;
Expand All @@ -13,12 +13,18 @@ mod LandRegistryContract {
land_count: u256,
}


//What are we storing

//lands, owners.

#[event]
#[derive(Drop, starknet::Event)]
enum Event {
LandRegistered: LandRegistered,
LandTransferred: LandTransferred,
LandVerified: LandVerified,
LandUpdated: LandUpdated,
}

#[derive(Drop, starknet::Event)]
Expand All @@ -41,15 +47,21 @@ mod LandRegistryContract {
struct LandVerified {
land_id: u256,
}
#[derive(Drop, Copy, starknet::Event)]
struct LandUpdated {
land_id: u256,
land_use: felt252,
area: u256
}

#[abi(embed_v0)]
impl LandRegistry of ILandRegistry<ContractState> {
fn register_land(
ref self: ContractState, location: felt252, area: u256, land_use: LandUse,
) -> u256 {
let caller = get_caller_address();
let land_id = self.land_count.read() + 1;
let timestamp = get_block_timestamp();
let land_id = timestamp.into() + 1;

let new_land = Land {
owner: caller,
Expand All @@ -62,8 +74,6 @@ mod LandRegistryContract {
self.lands.write(land_id, new_land);
self.land_count.write(land_id);

//ToDo: write to owner lands

self
.emit(
LandRegistered {
Expand All @@ -78,11 +88,14 @@ mod LandRegistryContract {
land_id
}


fn get_land(self: @ContractState, land_id: u256) -> Land {
self.lands.read(land_id)
}
}
//Todo:

fn update_land(ref self: ContractState, land_id: u256, area: u256, land_use: LandUse) {
self.lands.write(land_id, Land { area, land_use, ..self.lands.read(land_id) });

self.emit(LandUpdated { land_id: land_id, area: area, land_use: land_use.into(), });
}
}
}
5 changes: 3 additions & 2 deletions land_registry/src/lib.cairo
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
mod interface;
mod land_register;
pub mod interface;
pub mod land_register;

0 comments on commit cee980e

Please sign in to comment.