-
Notifications
You must be signed in to change notification settings - Fork 1k
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
base: main
Are you sure you want to change the base?
Conversation
@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(')') { |
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.
don't we also need to be able to calculate when the layout is not mapping but an array?
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.
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> { |
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.
@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.
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.
I highly recommend peg for this usecase, it makes it very trivial to define recursive grammars: https://docs.rs/peg/latest/peg/
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.
i'll give it a shot, thanks for the feedback guys
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