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

feat: move Slot type into it's own library #3639

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

cozfuttu
Copy link

Closes #3417

Created a small binary for slot calculation as well. Usage:
cargo run --bin slot-calculator --layout "mapping(uint256 => mapping(uint256 => uint256)[])" --keys 100 1 123

Copy link

vercel bot commented Jan 24, 2025

@cozfuttu is attempting to deploy a commit to the unionbuild Team on Vercel.

A member of the Team first needs to authorize it.

// mapping(uint256 => mapping(uint256 => uint256)[]) => ["uint256", "mapping[]", "uint256"]
fn parse_layout(layout: &str) -> Result<Vec<String>, String> {
// 1. Basic validation
if !layout.starts_with("mapping(") || !layout.ends_with(')') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't we also need to be able to calculate when the layout is not mapping but an array?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, I'll add support for arrays as well.

// mapping(uint256 => mapping(uint256 => mapping(uint256 => uint256)[])[]) => ["uint256", "mapping[]", "uint256", "mapping[]", "uint256"]
// mapping(uint256 => mapping(uint256 => mapping(uint256 => mapping(uint256 => uint256)[]))[]) => ["uint256", "mapping[]", "uint256", "uint256", "mapping[]", "uint256"]
// mapping(uint256 => mapping(uint256 => uint256)[]) => ["uint256", "mapping[]", "uint256"]
fn parse_layout(layout: &str) -> Result<Vec<String>, String> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@benluelo Do you know of a simple parsing lib for rust where we can define the grammar and do the parsing? It would be cleaner and safer to use a well tested parser.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I highly recommend peg for this usecase, it makes it very trivial to define recursive grammars: https://docs.rs/peg/latest/peg/

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'll give it a shot, thanks for the feedback guys

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.

Move Slot type into it's own library
3 participants