-
Notifications
You must be signed in to change notification settings - Fork 1.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. |
@@ -176,6 +177,7 @@ members = [ | |||
"lib/state-lens-light-client-types", | |||
"lib/create3", | |||
"lib/linea-types", | |||
"lib/slotlib", |
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.
another small comment: please call this library unionlabs-slot
fn parse_mapping_key<'a>(key_type: &'a Type, key: &'a str) -> MappingKey<'a> { | ||
match key_type { | ||
Type::Uint(_, size) => { | ||
let size = size.and_then(|s| Some(s.get())).unwrap_or(256); |
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.
instead of .and_then with Some(), just use .map
let size = size.and_then(|s| Some(s.get())).unwrap_or(256); | ||
match size { | ||
256 => MappingKey::Uint256(U256::from( | ||
key.parse::<u64>().expect("Invalid uint256 key"), |
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.
parsing as u64 when this is a u256?
} | ||
|
||
fn main() { | ||
let matches = Command::new("Slot Calculator (post-order)") |
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.
use clap derive instead of the builder api
match &parsed_layout.items[0] { | ||
Item::Variable(var) => match &var.ty { | ||
Type::Mapping(map) => Ok(Type::Mapping(map.clone())), | ||
Type::Array(arr) => Ok(Type::Array(arr.clone())), | ||
_ => return Err("Unsupported type".to_string()), | ||
}, | ||
_ => return Err("Unsupported item".to_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.
why not just parse directly into Type
?
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.
then you could skip the visibility & name logic entirely
)), | ||
Type::Array(arr) => arena.alloc(Slot::Array( | ||
build_slot(arr.ty.as_ref(), keys, arena), | ||
U256::from(key.parse::<u64>().expect("Invalid array index")), |
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.
parse as u256
) -> &'a Slot<'a> { | ||
let key: &str = match keys.pop_front() { | ||
Some(k) => k, | ||
None => return arena.alloc(Slot::Offset(U256::from(0u32))), |
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.
what's the reasoning behind defaulting to a 0 slot here?
if split_keys.len() != 0 { | ||
eprintln!( | ||
"Warning: Unused keys: {:?}. The calculated slot might be wrong. Please check the layout and keys you provided.", | ||
split_keys | ||
); | ||
} |
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.
this should be a hard error
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