Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: change is_dynamic to a const DYNAMIC #99

Merged
merged 1 commit into from
Jun 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 7 additions & 49 deletions crates/sol-types/src/types/data_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,6 @@ impl SolType for Address {
"address".into()
}

#[inline]
fn is_dynamic() -> bool {
false
}

#[inline]
fn detokenize(token: Self::TokenType) -> Self::RustType {
RustAddress::new(token.0[12..].try_into().unwrap())
Expand Down Expand Up @@ -65,10 +60,7 @@ impl SolType for Bytes {
type RustType = Vec<u8>;
type TokenType = PackedSeqToken;

#[inline]
fn is_dynamic() -> bool {
true
}
const DYNAMIC: bool = true;

#[inline]
fn sol_type_name() -> Cow<'static, str> {
Expand Down Expand Up @@ -111,11 +103,6 @@ where
type RustType = <IntBitCount<BITS> as SupportedInt>::Int;
type TokenType = WordToken;

#[inline]
fn is_dynamic() -> bool {
false
}

#[inline]
fn sol_type_name() -> Cow<'static, str> {
IntBitCount::<BITS>::INT_NAME.into()
Expand Down Expand Up @@ -171,11 +158,6 @@ where
type RustType = <IntBitCount<BITS> as SupportedInt>::Uint;
type TokenType = WordToken;

#[inline]
fn is_dynamic() -> bool {
false
}

#[inline]
fn sol_type_name() -> Cow<'static, str> {
IntBitCount::<BITS>::UINT_NAME.into()
Expand Down Expand Up @@ -219,11 +201,6 @@ impl SolType for Bool {
type RustType = bool;
type TokenType = WordToken;

#[inline]
fn is_dynamic() -> bool {
false
}

#[inline]
fn sol_type_name() -> Cow<'static, str> {
"bool".into()
Expand Down Expand Up @@ -269,10 +246,7 @@ where
type RustType = Vec<T::RustType>;
type TokenType = DynSeqToken<T::TokenType>;

#[inline]
fn is_dynamic() -> bool {
true
}
const DYNAMIC: bool = true;

#[inline]
fn sol_type_name() -> Cow<'static, str> {
Expand Down Expand Up @@ -319,10 +293,7 @@ impl SolType for String {
type RustType = RustString;
type TokenType = PackedSeqToken;

#[inline]
fn is_dynamic() -> bool {
true
}
const DYNAMIC: bool = true;

#[inline]
fn sol_type_name() -> Cow<'static, str> {
Expand Down Expand Up @@ -374,11 +345,6 @@ where
type RustType = [u8; N];
type TokenType = WordToken;

#[inline]
fn is_dynamic() -> bool {
false
}

#[inline]
fn sol_type_name() -> Cow<'static, str> {
<ByteCount<N>>::NAME.into()
Expand Down Expand Up @@ -427,10 +393,7 @@ where
type RustType = [T::RustType; N];
type TokenType = FixedSeqToken<T::TokenType, N>;

#[inline]
fn is_dynamic() -> bool {
T::is_dynamic()
}
const DYNAMIC: bool = T::DYNAMIC;

#[inline]
fn sol_type_name() -> Cow<'static, str> {
Expand Down Expand Up @@ -511,9 +474,9 @@ macro_rules! tuple_impls {
type RustType = ($( $ty::RustType, )+);
type TokenType = ($( $ty::TokenType, )+);

fn is_dynamic() -> bool {
$( <$ty as SolType>::is_dynamic() )||+
}
const DYNAMIC: bool = $(
<$ty as SolType>::DYNAMIC
)||+;

fn sol_type_name() -> Cow<'static, str> {
format!(
Expand Down Expand Up @@ -575,11 +538,6 @@ impl SolType for () {
type RustType = ();
type TokenType = FixedSeqToken<(), 0>;

#[inline]
fn is_dynamic() -> bool {
false
}

#[inline]
fn sol_type_name() -> Cow<'static, str> {
"tuple()".into()
Expand Down
5 changes: 1 addition & 4 deletions crates/sol-types/src/types/struct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,7 @@ impl<T: SolStruct> SolType for T {
type RustType = T;
type TokenType = TupleTokenTypeFor<T>;

#[inline]
fn is_dynamic() -> bool {
<<Self as SolStruct>::Tuple as SolType>::is_dynamic()
}
const DYNAMIC: bool = TupleFor::<T>::DYNAMIC;

#[inline]
fn type_check(token: &Self::TokenType) -> crate::Result<()> {
Expand Down
6 changes: 3 additions & 3 deletions crates/sol-types/src/types/type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ pub trait SolType {
/// See implementers of [`TokenType`].
type TokenType: TokenType;

/// True if the type is dynamically sized.
const DYNAMIC: bool = false;

/// The name of the type in Solidity.
fn sol_type_name() -> Cow<'static, str>;

/// True if the type is dynamic according to ABI rules.
fn is_dynamic() -> bool;

/// Check a token to see if it can be detokenized with this type.
fn type_check(token: &Self::TokenType) -> Result<()>;

Expand Down
7 changes: 2 additions & 5 deletions crates/sol-types/src/types/udt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,13 @@ macro_rules! define_udt {
type RustType = <$underlying as $crate::SolType>::RustType;
type TokenType = <$underlying as $crate::SolType>::TokenType;

const DYNAMIC: bool = false;

#[inline]
fn sol_type_name() -> $crate::no_std_prelude::Cow<'static, str> {
Self::NAME.into()
}

#[inline]
fn is_dynamic() -> bool {
false
}

#[inline]
fn type_check(token: &Self::TokenType) -> $crate::Result<()> {
<$underlying as $crate::SolType>::type_check(token)?;
Expand Down