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

feat: Solidity events support #83

Merged
merged 23 commits into from
Jun 12, 2023
Merged

feat: Solidity events support #83

merged 23 commits into from
Jun 12, 2023

Conversation

DaniPopes
Copy link
Member

Closes #38

DaniPopes and others added 5 commits June 9, 2023 23:09
* fix: event trait fixes

* fix: re-exporting event

* refactor: event trait take 2

* refactor: improve topic detokenization

* refactor: change events to account for indexed structs not in body

* fix: move test to bottom of event
/// For more details, see the [Solidity reference][ref].
///
/// [ref]: https://docs.soliditylang.org/en/latest/abi-spec.html#encoding-of-indexed-event-parameters
pub trait EventTopic: SolType {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will this need to be generated in sol! for all structs?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be done with a blanket impl:

impl<T: SolStruct> EventTopic for T
where
    T::Tuple: EventTopic,
{
    fn topic_preimage_length(rust: &T) -> usize {
        let tuple = rust.to_rust();
        T::Tuple::topic_preimage_length(&tuple)
    }
}

But we're cloning the data to get the inner tuple, so this is not ideal

Copy link
Member

@prestwich prestwich Jun 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But we're cloning the data to get the inner tuple, so this is not ideal

I'm gonna think about this a bit more. what do you think of this:

trait SolType {

    type BorrowAbstraction: From<Self::RustType>;

    fn encode<T: Into<Self::BorrowAbstraction>>(t: T)

}

pub enum TupleBorrowAbstraction<T, U> {
    Owned((T,U)),
    Borrowed(&(T, U)),
    MembersBorrowed((&T, &U))
}

// From impls here

crates/sol-types/src/types/event/topic.rs Outdated Show resolved Hide resolved
crates/sol-types/src/types/event/topic.rs Outdated Show resolved Hide resolved
@DaniPopes DaniPopes merged commit 747533d into main Jun 12, 2023
@DaniPopes DaniPopes deleted the dani/events branch June 12, 2023 22:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for events
2 participants