-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #51 from NoshonNetworks/registry
feat: remove unused impls and update egistry
- Loading branch information
Showing
5 changed files
with
131 additions
and
173 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
use starknet::ContractAddress; | ||
|
||
#[derive(Drop, Serde, starknet::Store)] | ||
struct Land { | ||
owner: ContractAddress, | ||
location: felt252, | ||
area: u256, | ||
land_use: LandUse, | ||
last_transaction_timestamp: u64, | ||
} | ||
|
||
#[derive(Drop, Copy, Clone, Serde, starknet::Store)] | ||
pub enum LandUse { | ||
Residential, | ||
Commercial, | ||
Industrial, | ||
Agricultural, | ||
} | ||
|
||
impl LandUseIntoFelt252 of Into<LandUse, felt252> { | ||
fn into(self: LandUse) -> felt252 { | ||
match self { | ||
LandUse::Residential => 1, | ||
LandUse::Commercial => 2, | ||
LandUse::Industrial => 3, | ||
LandUse::Agricultural => 4, | ||
} | ||
} | ||
} | ||
|
||
#[starknet::interface] | ||
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>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
#[starknet::contract] | ||
mod LandRegistryContract { | ||
use starknet::{get_caller_address, get_block_timestamp, ContractAddress}; | ||
use land_registry::interface::{ILandRegistry, Land, LandUse}; | ||
use core::array::ArrayTrait; | ||
use core::array::SpanTrait; | ||
use starknet::storage::{Map, StorageMapWriteAccess}; | ||
|
||
#[storage] | ||
struct Storage { | ||
lands: Map::<u256, Land>, | ||
owner_lands: Map::<ContractAddress, Span<u256>>, | ||
land_count: u256, | ||
} | ||
|
||
#[event] | ||
#[derive(Drop, starknet::Event)] | ||
enum Event { | ||
LandRegistered: LandRegistered, | ||
LandTransferred: LandTransferred, | ||
LandVerified: LandVerified, | ||
} | ||
|
||
#[derive(Drop, starknet::Event)] | ||
struct LandRegistered { | ||
land_id: u256, | ||
owner: ContractAddress, | ||
location: felt252, | ||
area: u256, | ||
land_use: felt252, | ||
} | ||
|
||
#[derive(Drop, starknet::Event)] | ||
struct LandTransferred { | ||
land_id: u256, | ||
from_owner: ContractAddress, | ||
to_owner: ContractAddress, | ||
} | ||
|
||
#[derive(Drop, starknet::Event)] | ||
struct LandVerified { | ||
land_id: 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 new_land = Land { | ||
owner: caller, | ||
location: location, | ||
area: area, | ||
land_use: land_use, | ||
last_transaction_timestamp: timestamp, | ||
}; | ||
|
||
self.lands.write(land_id, new_land); | ||
self.land_count.write(land_id); | ||
|
||
//ToDo: write to owner lands | ||
|
||
self | ||
.emit( | ||
LandRegistered { | ||
land_id: land_id, | ||
owner: caller, | ||
location: location, | ||
area: area, | ||
land_use: land_use.into(), | ||
} | ||
); | ||
|
||
land_id | ||
} | ||
|
||
|
||
fn get_land(self: @ContractState, land_id: u256) -> Land { | ||
self.lands.read(land_id) | ||
} | ||
} | ||
//Todo: | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
|
||
mod interface; | ||
mod land_register; |
File renamed without changes.