#[cfg(test)]
#[macro_use]
extern crate pretty_assertions;
pub mod erc20;
pub mod gas;
pub mod rpc;
pub mod services;
#[cfg(test)]
pub mod test_fixtures;
use alloy::primitives::{Address, B256, U256};
pub(crate) use rpc::errors::*;
use tycho_common::Bytes;
pub trait BytesCodec {
fn to_bytes(self) -> Bytes;
fn from_bytes(bytes: &Bytes) -> Self;
}
impl BytesCodec for Address {
fn to_bytes(self) -> Bytes {
Bytes::from(self.0.to_vec())
}
fn from_bytes(bytes: &Bytes) -> Self {
Address::from_slice(bytes.as_ref())
}
}
impl BytesCodec for B256 {
fn to_bytes(self) -> Bytes {
Bytes::from(self.0.to_vec())
}
fn from_bytes(bytes: &Bytes) -> Self {
B256::from_slice(bytes.as_ref())
}
}
impl BytesCodec for U256 {
fn to_bytes(self) -> Bytes {
let buf = self.to_be_bytes::<32>();
Bytes::from(buf.to_vec())
}
fn from_bytes(bytes: &Bytes) -> Self {
let bytes_slice = bytes.as_ref();
let mut u256_bytes: [u8; 32] = [0; 32];
u256_bytes[32 - bytes_slice.len()..].copy_from_slice(bytes_slice);
U256::from_be_bytes(u256_bytes)
}
}