-
Notifications
You must be signed in to change notification settings - Fork 152
Migrate the native price estimation endpoint and trait to alloy #3882
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
squadgazzz
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 assuming the new conversion logic is tested.
| fn token(u: u64) -> Address { | ||
| Address::left_padding_from(&u.to_be_bytes()) | ||
| } |
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 am always afraid of this kind of changes. Did you test it somehow?
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.
left_padding_from docs
Create a new byte array from the given slice src, left-padding it with zeroes if necessary.
Note
The given bytes are interpreted in big endian order.
Panics
Panics if src.len() > N.
H160::from_low_u64_be behaviour, where B is BigEndian
fn from_low_u64_with_byteorder<B>(val: u64) -> Self
where
B: $crate::byteorder::ByteOrder,
{
let mut buf = [0x0; 8];
B::write_u64(&mut buf, val);
let capped = $crate::core_::cmp::min(Self::len_bytes(), 8);
let mut bytes = [0x0; $crate::core_::mem::size_of::<Self>()];
bytes[(Self::len_bytes() - capped)..].copy_from_slice(&buf[..capped]);
Self::from_slice(&bytes)
}The byte order is preserved and H160's function 0 pads the result to the desired size.
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 runs just fine
use alloy::primitives::Address;
use ethcontract::H160;
fn main() {
assert_eq!(
Address::left_padding_from(&1024u64.to_be_bytes()).0.0,
H160::from_low_u64_be(1024u64).0
);
}
As an extra note, in certain places I use "with_last_byte" instead because the number fits in a byte, thus it doesn't need the fancy u64::to_be_bytes(), etc
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
| fn token(u: u64) -> Address { | ||
| Address::left_padding_from(&u.to_be_bytes()) | ||
| } |
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.
left_padding_from docs
Create a new byte array from the given slice src, left-padding it with zeroes if necessary.
Note
The given bytes are interpreted in big endian order.
Panics
Panics if src.len() > N.
H160::from_low_u64_be behaviour, where B is BigEndian
fn from_low_u64_with_byteorder<B>(val: u64) -> Self
where
B: $crate::byteorder::ByteOrder,
{
let mut buf = [0x0; 8];
B::write_u64(&mut buf, val);
let capped = $crate::core_::cmp::min(Self::len_bytes(), 8);
let mut bytes = [0x0; $crate::core_::mem::size_of::<Self>()];
bytes[(Self::len_bytes() - capped)..].copy_from_slice(&buf[..capped]);
Self::from_slice(&bytes)
}The byte order is preserved and H160's function 0 pads the result to the desired size.
Description
Migrate the native price estimation endpoint and trait to alloy
Changes
How to test
Existing tests