-
Notifications
You must be signed in to change notification settings - Fork 60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refac: Fix Land ID logic #99
Conversation
Hi @fishonamos, please review! |
fn create_land_id(self: @ContractState, location: felt252) -> u256 { | ||
let caller = get_caller_address(); | ||
let timestamp = get_block_timestamp(); | ||
|
||
let caller_hash = PoseidonTrait::new().update_with(caller).finalize(); | ||
let timestamp_hash = PoseidonTrait::new().update_with(timestamp).finalize(); | ||
let location_hash = PoseidonTrait::new().update_with(location).finalize(); | ||
|
||
let felt_land_id = caller_hash + timestamp_hash + location_hash; | ||
let land_id: u256 = felt_land_id.into(); | ||
land_id | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Can you update the location from the contract to have latitude and longitude fields? That's more unique. So instead of using felt252 for location, we can use a struct with two fields. Latitude and Longitude.
struct Location {
latitude
longitude
}
Then an impl function that take latitude and longitude in a new method and returns an instance of the location. Then update everyother functions as needed. Thank you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
struct Location {
latitude: f64,
longitude: f64,
}
But Cairo uses field elements so we can't store decimals/float values, what should I do in this case?
Please update the pr title too. |
@fishonamos okay, doing that. On an other note, I can't access the telegram group of landver, it says its a private group and now its not in my chats list as well. |
@fishonamos, since there aren't any float values in Cairo I have used felt252 values for latitude and longitude and refactored codebase wherever required to achieve the same functionality throughout the codebase. |
Good. That fits the size for now. Can you move the create_id function outside the contract? Other wise. Looks good. |
Detailed Information
Checklist:
create_land_id
function to randomizeland_id
generation (using Cairo inbuilt Poseidon hashing)land_id
being incremented by 1 when createdland_id
generationRelated Issues
Closes #84
Type of Change
Checklist (select as many as applicable)