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

Abi-generate specific event filters based on its topics #83

Open
ArtificialPB opened this issue Feb 23, 2024 · 0 comments
Open

Abi-generate specific event filters based on its topics #83

ArtificialPB opened this issue Feb 23, 2024 · 0 comments
Labels
difficulty: medium Medium issues requiring additional skills. type: feature Feature requests.

Comments

@ArtificialPB
Copy link
Member

Module

ABI

📝 Description

Currently, each abi-generated event class has an EventFactory, which provides a filter function that returns a subclass of EventFilterBase. For each Event we know which fields are indexed and what type they are.

We should generate a specific subclass of EventFilterBase for each event, where each subclass contains its topics' type-specific filter methods that encode the specific type (e.g. BigInteger for uint256) into Hash and sets it on the internal LogFilter.

For example, we have the following event:

event Transfer(address indexed from, address indexed to, uint256 value)

Abigen would generate something like this:

class TransferEventFilter(
    provider: Middleware,
    factory: EventFactory<Transfer>,
) : EventFilterBase<Transfer, TransferEventFilter>(provider, factory) {
    override val self: TransferEventFilter
        get() = this

    init {
        filter.topic0(factory.abi.topicId)
    }
    
    fun from(address: Address): TransferEventFilter {
        filter.topic1(address)
        return this
    }

    fun from(vararg addresses: Address): TransferEventFilter {
        filter.topic1(addresses)
        return this
    }

    fun to(address: Address): TransferEventFilter {
        filter.topic2(address)
        return this
    }

    fun to(vararg addresses: Address): TransferEventFilter {
        filter.topic2(addresses)
        return this
    }
}
@ArtificialPB ArtificialPB added type: feature Feature requests. difficulty: medium Medium issues requiring additional skills. labels Feb 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
difficulty: medium Medium issues requiring additional skills. type: feature Feature requests.
Projects
None yet
Development

No branches or pull requests

1 participant