Skip to content

Commit

Permalink
feat: land regsitry -- register land function
Browse files Browse the repository at this point in the history
  • Loading branch information
fishonamos committed Oct 10, 2024
1 parent 7edc501 commit 0619532
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 2 deletions.
62 changes: 60 additions & 2 deletions land_registry/src/contracts/LandRegistry.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down Expand Up @@ -72,4 +72,62 @@ mod LandRegistry {
to_owner: ContractAddress,
}

}
#[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<TContractState> {
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)
}
}
}
1 change: 1 addition & 0 deletions land_registry/src/lib.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

1 change: 1 addition & 0 deletions land_registry/src/tests/test_land_registry.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

0 comments on commit 0619532

Please sign in to comment.