Skip to content

Commit

Permalink
chore: move WrapAddress in utils
Browse files Browse the repository at this point in the history
  • Loading branch information
zsluedem committed Feb 13, 2023
1 parent dc5b3b4 commit a5f014b
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 32 deletions.
32 changes: 1 addition & 31 deletions src/types/mod.rs
Original file line number Diff line number Diff line change
@@ -1,33 +1,3 @@
use ethers::types::Address;
use reth_db::table::{Decode, Encode};

pub mod reputation;
pub mod user_operation;

#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone)]
pub struct WrapAddress(Address);

impl Decode for WrapAddress {
fn decode<B: Into<prost::bytes::Bytes>>(value: B) -> Result<Self, reth_db::Error> {
Ok(Address::from_slice(value.into().as_ref()).into())
}
}

impl Encode for WrapAddress {
type Encoded = [u8; 20];
fn encode(self) -> Self::Encoded {
*self.0.as_fixed_bytes()
}
}

impl From<Address> for WrapAddress {
fn from(value: Address) -> Self {
Self(value)
}
}

impl From<WrapAddress> for Address {
fn from(value: WrapAddress) -> Self {
value.0
}
}
pub mod utils;
30 changes: 30 additions & 0 deletions src/types/utils.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
use ethers::types::Address;
use reth_db::table::{Decode, Encode};

#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone)]
pub struct WrapAddress(Address);

impl Decode for WrapAddress {
fn decode<B: Into<prost::bytes::Bytes>>(value: B) -> Result<Self, reth_db::Error> {
Ok(Address::from_slice(value.into().as_ref()).into())
}
}

impl Encode for WrapAddress {
type Encoded = [u8; 20];
fn encode(self) -> Self::Encoded {
*self.0.as_fixed_bytes()
}
}

impl From<Address> for WrapAddress {
fn from(value: Address) -> Self {
Self(value)
}
}

impl From<WrapAddress> for Address {
fn from(value: WrapAddress) -> Self {
value.0
}
}
2 changes: 1 addition & 1 deletion src/uopool/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::path::PathBuf;
use super::Mempool;
use crate::types::{
user_operation::{UserOperation, UserOperationHash},
WrapAddress,
utils::WrapAddress,
};
use ethers::types::{Address, U256};
use reth_db::{
Expand Down

0 comments on commit a5f014b

Please sign in to comment.