diff --git a/land_registry/src/contracts/LandRegistry.cairo b/land_registry/src/contracts/LandRegistry.cairo index e9ee065f..221c5485 100644 --- a/land_registry/src/contracts/LandRegistry.cairo +++ b/land_registry/src/contracts/LandRegistry.cairo @@ -35,7 +35,7 @@ mod LandRegistry { owner: ContractAddress, location: felt252, area: u256, - land_use: felt252, + land_use: LandUse, is_verified: bool, last_transaction_timestamp: u64, } @@ -72,4 +72,62 @@ mod LandRegistry { to_owner: ContractAddress, } -} \ No newline at end of file + #[Contructor] + fn contructor(ref self: TContractSatate, deployer: ContractAddress) { + let deployer_address = get_caller_address(); + emit!(ContractDeployed { deployer: deployer_address, }); + } + #[derive(Drop)] + struct Location { + latitude: f64, + longitude: f64, + } + + #[abi(embed_v0)] + impl LandRegistryImpl of ILandRegistry { + fn register_land( + ref self: TContractState, + owner: OwnerAddress, + location: Location, + area: u256, + land_use: LandUse, + ) -> u256 { + //we will use the block time stamp as the landid for now. + let mut timestamp = get_block_timestamp(); + let land_id: u256 = timestamp.into(); + let new_land = Land { + owner: OwnerAddress, + location: location, + area: area, + land_use: LandUse, + landid: landid, + }; + + //store the land in the lands map.. + let result = self.lands.insert(land_id, new_land); + + // Add the land Id the list of owner lands by for an owner such that we can retrieve all + // the lands for a specific owner + let owner_lands = self.owner_lands.entry(owner).or_insert(Vec::new()); + + //Emit events for land registered. This will help use to track registered lands + + //How can we get owner lands? + + emit!( + LandRegistered { + land_id: u256, + owner: ContractAddress, + location: felt252, + area: u256, + land_use: felt252, + } + ); + + //finally return the landID + land_id + + println!('You land has been succcessfully registered {:?}', result) + } + } +} diff --git a/land_registry/src/lib.cairo b/land_registry/src/lib.cairo index e69de29b..8b137891 100644 --- a/land_registry/src/lib.cairo +++ b/land_registry/src/lib.cairo @@ -0,0 +1 @@ + diff --git a/land_registry/src/tests/test_land_registry.cairo b/land_registry/src/tests/test_land_registry.cairo index e69de29b..8b137891 100644 --- a/land_registry/src/tests/test_land_registry.cairo +++ b/land_registry/src/tests/test_land_registry.cairo @@ -0,0 +1 @@ +