Skip to content

Export some kind of general Contract struct #513

@bh2smith

Description

@bh2smith

Not exactly sure how to describe this, but I suppose it would be analogous to the Contract object what we know and love from ethers which can be instantiated as an interface from an ABI or as an instance when also provided with an address and web3Provider.

This would allow us to make generalizations for arbitrary contracts some common functionalities.

One particular place where this could come in handy is when implementing an Event Listener in place of the generic EventRetrieving

pub struct EventHandler<C: EventRetrieving, S: EventStoring<C::Event>> {
    contract: C,
    store: S,
    last_handled_block: Option<u64>,
}

Where

pub trait EventRetrieving {
    type Event: ParseLog;
    fn get_events(&self) -> AllEventsBuilder<DynTransport, Self::Event>;
    fn web3(&self) -> Web3<DynTransport>;
}

At the moment we need to implement EventRetrieving in a very boiler plate kind of way for each contract we want to listen to.

impl EventRetrieving for GPv2SettlementContract {
    type Event = ContractEvent;
    fn get_events(&self) -> AllEventsBuilder<DynTransport, Self::Event> {
        self.0.all_events()
    }

    fn web3(&self) -> Web3<DynTransport> {
        self.0.raw_instance().web3()
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions