-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #87 from Vid201/feat/codehash
Feat/codehash
- Loading branch information
Showing
13 changed files
with
706 additions
and
511 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,60 @@ | ||
use ethers::types::Address; | ||
use reth_db::table::{Decode, Encode}; | ||
use ethers::{ | ||
types::{Address, Bytes}, | ||
utils::to_checksum, | ||
}; | ||
use reth_db::table::{Compress, Decode, Decompress, Encode}; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
#[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()) | ||
} | ||
pub fn as_checksum<S>(val: &Address, serializer: S) -> Result<S::Ok, S::Error> | ||
where | ||
S: serde::Serializer, | ||
{ | ||
serializer.serialize_str(&to_checksum(val, None)) | ||
} | ||
|
||
impl Encode for WrapAddress { | ||
type Encoded = [u8; 20]; | ||
fn encode(self) -> Self::Encoded { | ||
*self.0.as_fixed_bytes() | ||
} | ||
} | ||
macro_rules! construct_wrap_hash { | ||
($type:ty, $name:ident, $n_bytes:expr ) => { | ||
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Serialize, Deserialize)] | ||
pub struct $name($type); | ||
|
||
impl From<Address> for WrapAddress { | ||
fn from(value: Address) -> Self { | ||
Self(value) | ||
} | ||
} | ||
impl Decode for $name { | ||
fn decode<B: Into<prost::bytes::Bytes>>(value: B) -> Result<Self, reth_db::Error> { | ||
Ok(<$type>::from_slice(value.into().as_ref()).into()) | ||
} | ||
} | ||
|
||
impl Encode for $name { | ||
type Encoded = [u8; $n_bytes]; | ||
fn encode(self) -> Self::Encoded { | ||
*self.0.as_fixed_bytes() | ||
} | ||
} | ||
|
||
impl From<WrapAddress> for Address { | ||
fn from(value: WrapAddress) -> Self { | ||
value.0 | ||
} | ||
impl From<$type> for $name { | ||
fn from(value: $type) -> Self { | ||
Self(value) | ||
} | ||
} | ||
|
||
impl From<$name> for $type { | ||
fn from(value: $name) -> Self { | ||
value.0 | ||
} | ||
} | ||
|
||
impl Compress for $name { | ||
type Compressed = Bytes; | ||
fn compress(self) -> Self::Compressed { | ||
Bytes::from(self.encode()) | ||
} | ||
} | ||
|
||
impl Decompress for $name { | ||
fn decompress<B: Into<prost::bytes::Bytes>>(value: B) -> Result<Self, reth_db::Error> { | ||
Self::decode(value.into()).map_err(|_e| reth_db::Error::DecodeError) | ||
} | ||
} | ||
}; | ||
} | ||
|
||
construct_wrap_hash!(Address, WrapAddress, 20); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.