-
Notifications
You must be signed in to change notification settings - Fork 795
feat(abigen): extend ethevent trait methods and decoding #239
feat(abigen): extend ethevent trait methods and decoding #239
Conversation
This reverts commit 03eabc3.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1 comment as discussed on the fully qualified syntax, otherwise looks great to me!
#struct_decl | ||
|
||
impl<'a, M: Middleware> #name<M> { | ||
impl<'a, M: ethers_providers::Middleware> #name<M> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having fully qualified syntax here requires that we have to declare ethers_providers/core/contract in the consuming crate's cargo toml. It'd be ideal if we avoided that. Could you please revert this change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of removing the fully qualified syntax, I simply renamed the top level imports to their crate name in e018a70, which achieves the same effect, plus has the benefit, that the EthEvent
trait, which resides in ethers_contract
is usable with ethers_contract
as crate dependency.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome, thank you, merged.
* add expectRevert * fmt * clippy * update readme * typos * feat: bump ethers for new ethabi types (gakonst#238) ref: gakonst#700 * custom revert test * use ethabi to decode * PR recs * fmt Co-authored-by: Georgios Konstantopoulos <[email protected]>
Motivation
This follows up on #234 and also provides a solution for #98
Solution
The
EthEvent
trait is extended with a method to create anEvent
builder directly (closes #234).The
EthEvent
proc macro now derives adecode_log(log: &RawLog)
that parses the log message into an instance of the type it's derived on.This introduces another trait
EthLogDecode
which only purpose is to create a commonRawLog -> Self
interface for all the generatedEthEvent
s of a contract and the generated enum wrapper that is generated for events that have more than 1 event in their abi (closes #98)Example
if a contract is created as follows
an enum
is created.
In addition, if the abi has at least one event the generated contract gets a new method
events(&self) -> Event<M, Events>
, whereEvents
is either the sole event for contracts with only a single event or the generated enum for contracts with more than one event.In the latter case, the protocol decoding works in such a way that all variants are tried to be decoded one after the other and the first successful attempt is returned
Breaking changes
Contract::event(&self, &str) -> Result<Event<_>,Error>
toevent_for_name
and introducedContract::event<T:EthEvent>(&self) -> Event<_>
+ another convenience function