-
Notifications
You must be signed in to change notification settings - Fork 152
Migrate get_total_surplus_endpoint to alloy #3886
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
Conversation
| let surplus = fetch_total_surplus(&mut ex, &ByteArray(user.0)).await?; | ||
| Ok(U256::from_f64_lossy(surplus)) | ||
| let surplus = fetch_total_surplus(&mut ex, &ByteArray(user.0.0)).await?; | ||
| Ok(U256::from(surplus)) |
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.
Can You provide more information backing this is a drop-in replacement? I looked around alloy's docs but couldn't untangle it.
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 alloy::primitives::U256;
fn main() {
let mut buffer = vec![0; 32];
ethcontract::U256::from_f64_lossy(3.3).to_big_endian(&mut buffer);
assert_eq!(U256::from(3.3f64).to_be_bytes_vec(), buffer);
println!(
"{} {}",
U256::from(3.3f64),
ethcontract::U256::from_f64_lossy(3.3)
);
}
I think that in ethcontract they explicitly state that the conversion is lossy because you're bound to lose decimals, in alloy they make it implicit because you shouldn't really expect the decimals to keep when converting to an integer type.
Hope this helps
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.
Perfect! Thanks!
m-sz
left a comment
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.
LGTM
Description
Migrate get_total_surplus_endpoint to alloy
Changes
How to test
Existing tests