diff --git a/land_registry/src/interface.cairo b/land_registry/src/interface.cairo index 688f88e3..cac74521 100644 --- a/land_registry/src/interface.cairo +++ b/land_registry/src/interface.cairo @@ -1,7 +1,7 @@ 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, @@ -9,7 +9,7 @@ struct Land { last_transaction_timestamp: u64, } -#[derive(Drop, Copy, Clone, Serde, starknet::Store)] +#[derive(Drop, Copy, Clone, Serde, starknet::Store, PartialEq)] pub enum LandUse { Residential, Commercial, @@ -29,13 +29,14 @@ impl LandUseIntoFelt252 of Into { } #[starknet::interface] -trait ILandRegistry { +pub trait ILandRegistry { 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; -//fn get_lands(self: @TContractState, owner: ContractAddress, location: felt252, land_use: -//felt252) -> Array; + //fn get_lands(self: @TContractState, owner: ContractAddress, location: felt252, land_use: + //felt252) -> Array; + fn update_land(ref self: TContractState, land_id: u256, area: u256, land_use: LandUse); } diff --git a/land_registry/src/land_register.cairo b/land_registry/src/land_register.cairo index 1e98b4bf..92f99c03 100644 --- a/land_registry/src/land_register.cairo +++ b/land_registry/src/land_register.cairo @@ -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; @@ -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)] @@ -41,6 +47,12 @@ 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 { @@ -48,8 +60,8 @@ mod LandRegistryContract { 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, @@ -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 { @@ -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(), }); + } + } } diff --git a/land_registry/src/lib.cairo b/land_registry/src/lib.cairo index c0431ad2..6c8513b1 100644 --- a/land_registry/src/lib.cairo +++ b/land_registry/src/lib.cairo @@ -1,2 +1,3 @@ -mod interface; -mod land_register; +pub mod interface; +pub mod land_register; +