Skip to content
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

Merged
merged 16 commits into from
Oct 25, 2024
Merged

Conversation

SoarinSkySagar
Copy link
Contributor

@SoarinSkySagar SoarinSkySagar commented Oct 24, 2024

Detailed Information

Checklist:

  • Implemented create_land_id function to randomize land_id generation (using Cairo inbuilt Poseidon hashing)
  • Modified the snippets where the logic was dependent on the land_id being incremented by 1 when created
  • Created a new test function to test the land_id generation
  • Ensured that all tests are passing

Related Issues

Closes #84


Type of Change

  • 🐛 Bug fix or ⚙️ enhancement
  • ✨ New feature or Chore (change with no new features or fixes)
  • 📚 Documentation update

Checklist (select as many as applicable)

  • The code follows the style guidelines of this project.
  • All new and existing tests pass.
  • This pull request is ready to be merged and reviewed.

@SoarinSkySagar SoarinSkySagar marked this pull request as ready for review October 24, 2024 18:29
@SoarinSkySagar
Copy link
Contributor Author

Hi @fishonamos, please review!

@fishonamos fishonamos self-requested a review October 24, 2024 19:14
Comment on lines 217 to 228
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
}
Copy link
Member

@fishonamos fishonamos Oct 24, 2024

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.

Copy link
Contributor Author

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?

@fishonamos
Copy link
Member

Please update the pr title too.

@SoarinSkySagar
Copy link
Contributor Author

@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.

@SoarinSkySagar SoarinSkySagar changed the title Land id gen Land ID generation and better Location format Oct 24, 2024
@SoarinSkySagar SoarinSkySagar marked this pull request as draft October 24, 2024 20:39
@SoarinSkySagar
Copy link
Contributor Author

@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.

@SoarinSkySagar SoarinSkySagar marked this pull request as ready for review October 24, 2024 23:05
@fishonamos
Copy link
Member

Good. That fits the size for now. Can you move the create_id function outside the contract? Other wise. Looks good.

@fishonamos fishonamos merged commit c97b616 into NoshonNetworks:main Oct 25, 2024
2 checks passed
@fishonamos fishonamos changed the title Land ID generation and better Location format Refac: Fix Land ID Oct 25, 2024
@fishonamos fishonamos changed the title Refac: Fix Land ID refac: Fix Land ID logic Oct 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement Land ID Generation System
2 participants