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(dyn-abi): DynSolType::coerce_str #380

Merged
merged 12 commits into from
Oct 24, 2023
Merged

feat(dyn-abi): DynSolType::coerce_str #380

merged 12 commits into from
Oct 24, 2023

Conversation

DaniPopes
Copy link
Member

@DaniPopes DaniPopes commented Oct 20, 2023

Motivation

Port of ethabi::Tokenizer, with extra features

Solution

PR Checklist

  • Added Tests
  • Added Documentation
  • Breaking changes

Copy link
Member

@mattsse mattsse left a comment

Choose a reason for hiding this comment

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

amazing work!

it's been a while since I read some nom code but I still love how readable this is.

test coverage looks decent.

this will simplify so much

Comment on lines +327 to +328
// TODO: escapes?
let min = if has_delim { 0 } else { 1 };
Copy link
Member

Choose a reason for hiding this comment

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

hmm, good question, maybe this could happen with same escaped json inputs, but I think we can ignore that

Copy link
Contributor

@Evalir Evalir left a comment

Choose a reason for hiding this comment

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

Super readable! This is gonna be super handy—love it

Comment on lines 254 to 263
fn uint_units(input: &mut &str) -> PResult<usize> {
alpha0(input).and_then(|s| {
Ok(match s {
"ether" => 18,
"gwei" | "nano" | "nanoether" => 9,
"" | "wei" => 0,
_ => return Err(ErrMode::from_error_kind(input, ErrorKind::Fail)),
})
})
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This is super handy, lets us replace a few utilities we have in foundry

wdyt about adding more units?

Copy link
Member Author

Choose a reason for hiding this comment

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

Do you have anything in mind? Solidity only supports wei, gwei, and ether


assert_eq!(
DynSolType::Uint(256)
.coerce_str("0.000000000000000001ether")
Copy link
Contributor

Choose a reason for hiding this comment

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

nice

Copy link
Member

@prestwich prestwich left a comment

Choose a reason for hiding this comment

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

do we have documentation of all the formats supported?

@DaniPopes
Copy link
Member Author

Added in 0e974a1 @prestwich

@prestwich
Copy link
Member

perfection

@DaniPopes DaniPopes merged commit 8971476 into main Oct 24, 2023
20 checks passed
@DaniPopes DaniPopes deleted the dani/coerce-str branch October 24, 2023 14:54
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.

4 participants