use primitives::{Address, B256, U256};
pub trait IntoU256 {
fn into_u256(self) -> U256;
}
impl IntoU256 for Address {
fn into_u256(self) -> U256 {
self.into_word().into_u256()
}
}
impl IntoU256 for B256 {
fn into_u256(self) -> U256 {
U256::from_be_bytes(self.0)
}
}
pub trait IntoAddress {
fn into_address(self) -> Address;
}
impl IntoAddress for U256 {
fn into_address(self) -> Address {
Address::from_word(B256::from(self.to_be_bytes()))
}
}
#[cfg(test)]
mod tests {
use primitives::address;
use super::*;
#[test]
fn test_into_u256() {
let addr = address!("0x0000000000000000000000000000000000000001");
let u256 = addr.into_u256();
assert_eq!(u256, U256::from(0x01));
assert_eq!(u256.into_address(), addr);
}
}