Skip to content

Commit

Permalink
chore: add some TODO comments
Browse files Browse the repository at this point in the history
  • Loading branch information
DaniPopes authored and klkvr committed Aug 4, 2024
1 parent e3228c0 commit 5d4ef59
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
1 change: 1 addition & 0 deletions crates/sol-types/src/abi/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ pub fn decode<'de, T: Token<'de>>(data: &'de [u8], validate: bool) -> Result<T>
/// See the [`abi`](super) module for more information.
#[inline(always)]
pub fn decode_params<'de, T: TokenSeq<'de>>(data: &'de [u8], validate: bool) -> Result<T> {
// TODO(MSRV-1.79): Use `const {}` to select the function at compile time.
if T::IS_TUPLE {
decode_sequence(data, validate)
} else {
Expand Down
1 change: 1 addition & 0 deletions crates/sol-types/src/abi/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ pub fn encode<'a, T: Token<'a>>(token: &T) -> Vec<u8> {
/// See the [`abi`](super) module for more information.
#[inline(always)]
pub fn encode_params<'a, T: TokenSeq<'a>>(token: &T) -> Vec<u8> {
// TODO(MSRV-1.79): Use `const {}` to select the function at compile time.
if T::IS_TUPLE {
encode_sequence(token)
} else {
Expand Down
11 changes: 7 additions & 4 deletions crates/sol-types/src/types/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,8 @@ pub trait SolType: Sized {
/// See the [`abi`] module for more information.
#[inline]
fn abi_decode(data: &[u8], validate: bool) -> Result<Self::RustType> {
abi::decode::<Self::Token<'_>>(data, validate).and_then(check_decode::<Self>(validate))
abi::decode::<Self::Token<'_>>(data, validate)
.and_then(validate_and_detokenize::<Self>(validate))
}

/// Decodes this type's value from an ABI blob by interpreting it as
Expand All @@ -258,7 +259,7 @@ pub trait SolType: Sized {
Self::Token<'de>: TokenSeq<'de>,
{
abi::decode_params::<Self::Token<'_>>(data, validate)
.and_then(check_decode::<Self>(validate))
.and_then(validate_and_detokenize::<Self>(validate))
}

/// Decodes this type's value from an ABI blob by interpreting it as a
Expand All @@ -271,12 +272,14 @@ pub trait SolType: Sized {
Self::Token<'de>: TokenSeq<'de>,
{
abi::decode_sequence::<Self::Token<'_>>(data, validate)
.and_then(check_decode::<Self>(validate))
.and_then(validate_and_detokenize::<Self>(validate))
}
}

#[inline]
fn check_decode<T: SolType>(validate: bool) -> impl FnOnce(T::Token<'_>) -> Result<T::RustType> {
fn validate_and_detokenize<T: SolType>(
validate: bool,
) -> impl FnOnce(T::Token<'_>) -> Result<T::RustType> {
move |token| {
if validate {
T::type_check(&token)?;
Expand Down

0 comments on commit 5d4ef59

Please sign in to comment.