-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove event topics length limit; refactor tuple code into separate f…
…ile (#1263) ### What Resolves #480 Plus a minor enhancement to `impl_topics_for_tuple` for tuple up to size 13. ### Why The event topics length limit was a residual from an earlier design, where the limit was set to 4, matching with what's in Ethereum. Since then the length limit has been removed, but sdk has not been updated, so the user still can only submit events with topic length <=4. Expanding `impl_topics_for_tuple` makes it more convenient to construct longer topics (up to 13). Constructing topics from a `Vec<T>` does not subject to any length limit. ### Known limitations [TODO or N/A]
- Loading branch information
Showing
4 changed files
with
73 additions
and
55 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -0,0 +1,65 @@ | ||
//! This module contains conversion helpers for tuple | ||
use crate::{vec, ConversionError, Env, IntoVal, Topics, TryFromVal, Val, Vec}; | ||
|
||
impl TryFromVal<Env, ()> for Vec<Val> { | ||
type Error = ConversionError; | ||
|
||
fn try_from_val(env: &Env, _v: &()) -> Result<Self, Self::Error> { | ||
Ok(Vec::<Val>::new(env)) | ||
} | ||
} | ||
|
||
macro_rules! impl_into_vec_for_tuple { | ||
( $($typ:ident $idx:tt)* ) => { | ||
impl<$($typ),*> TryFromVal<Env, ($($typ,)*)> for Vec<Val> | ||
where | ||
$($typ: IntoVal<Env, Val>),* | ||
{ | ||
type Error = ConversionError; | ||
fn try_from_val(env: &Env, v: &($($typ,)*)) -> Result<Self, Self::Error> { | ||
Ok(vec![&env, $(v.$idx.into_val(env), )*]) | ||
} | ||
} | ||
}; | ||
} | ||
impl_into_vec_for_tuple! { T0 0 } | ||
impl_into_vec_for_tuple! { T0 0 T1 1 } | ||
impl_into_vec_for_tuple! { T0 0 T1 1 T2 2 } | ||
impl_into_vec_for_tuple! { T0 0 T1 1 T2 2 T3 3 } | ||
impl_into_vec_for_tuple! { T0 0 T1 1 T2 2 T3 3 T4 4 } | ||
impl_into_vec_for_tuple! { T0 0 T1 1 T2 2 T3 3 T4 4 T5 5 } | ||
impl_into_vec_for_tuple! { T0 0 T1 1 T2 2 T3 3 T4 4 T5 5 T6 6 } | ||
impl_into_vec_for_tuple! { T0 0 T1 1 T2 2 T3 3 T4 4 T5 5 T6 6 T7 7 } | ||
impl_into_vec_for_tuple! { T0 0 T1 1 T2 2 T3 3 T4 4 T5 5 T6 6 T7 7 T8 8 } | ||
impl_into_vec_for_tuple! { T0 0 T1 1 T2 2 T3 3 T4 4 T5 5 T6 6 T7 7 T8 8 T9 9 } | ||
impl_into_vec_for_tuple! { T0 0 T1 1 T2 2 T3 3 T4 4 T5 5 T6 6 T7 7 T8 8 T9 9 T10 10 } | ||
impl_into_vec_for_tuple! { T0 0 T1 1 T2 2 T3 3 T4 4 T5 5 T6 6 T7 7 T8 8 T9 9 T10 10 T11 11 } | ||
impl_into_vec_for_tuple! { T0 0 T1 1 T2 2 T3 3 T4 4 T5 5 T6 6 T7 7 T8 8 T9 9 T10 10 T11 11 T12 12 } | ||
|
||
macro_rules! impl_topics_for_tuple { | ||
( $($typ:ident $idx:tt)* ) => { | ||
impl<$($typ),*> Topics for ($($typ,)*) | ||
where | ||
$($typ: IntoVal<Env, Val>),* | ||
{ | ||
} | ||
}; | ||
} | ||
|
||
// 0 topics | ||
impl Topics for () {} | ||
// 1-13 topics | ||
impl_topics_for_tuple! { T0 0 } | ||
impl_topics_for_tuple! { T0 0 T1 1 } | ||
impl_topics_for_tuple! { T0 0 T1 1 T2 2 } | ||
impl_topics_for_tuple! { T0 0 T1 1 T2 2 T3 3 } | ||
impl_topics_for_tuple! { T0 0 T1 1 T2 2 T3 3 T4 4 } | ||
impl_topics_for_tuple! { T0 0 T1 1 T2 2 T3 3 T4 4 T5 5 } | ||
impl_topics_for_tuple! { T0 0 T1 1 T2 2 T3 3 T4 4 T5 5 T6 6 } | ||
impl_topics_for_tuple! { T0 0 T1 1 T2 2 T3 3 T4 4 T5 5 T6 6 T7 7 } | ||
impl_topics_for_tuple! { T0 0 T1 1 T2 2 T3 3 T4 4 T5 5 T6 6 T7 7 T8 8 } | ||
impl_topics_for_tuple! { T0 0 T1 1 T2 2 T3 3 T4 4 T5 5 T6 6 T7 7 T8 8 T9 9 } | ||
impl_topics_for_tuple! { T0 0 T1 1 T2 2 T3 3 T4 4 T5 5 T6 6 T7 7 T8 8 T9 9 T10 10 } | ||
impl_topics_for_tuple! { T0 0 T1 1 T2 2 T3 3 T4 4 T5 5 T6 6 T7 7 T8 8 T9 9 T10 10 T11 11 } | ||
impl_topics_for_tuple! { T0 0 T1 1 T2 2 T3 3 T4 4 T5 5 T6 6 T7 7 T8 8 T9 9 T10 10 T11 11 T12 12 } |
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