-
Notifications
You must be signed in to change notification settings - Fork 791
Conversation
will address these comments tomorrow. ledger issue has worn my brain out |
0fc3a69
to
41b3d10
Compare
if let Ok(decoded) = <::std::string::String as #ethers_core::abi::AbiDecode>::decode(data) { | ||
return Ok(Self::RevertString(decoded)) | ||
} |
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.
Shouldn't this be below the if let Ok
in the macro below? So that we only decode as string as a fallback vs prioritizing it?
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.
This implementation has never been safe for users to access directly, as it does not include selector information, and ABI encoded types are incredibly ambiguous. It has always thrown bad false positives.
My belief is that strings will be more common than other error types, even for contracts that do not revert, so putting a string in the first attempt results in the fewest decode attempts
pub trait ContractRevert: AbiDecode + AbiEncode + Send + Sync { | ||
/// Decode the error from EVM revert data including an Error selector |
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.
is this only derived for enums?
because this clashes with EthError
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.
yes, this trait is only for unifying multiple potential ethereum errors into 1 type. Basically this should be thought of as "the errors associated with a specific contract's ABI".
I thought about breaking out a super-trait that had the shared methods on it, and decided that it was too complex for users
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.
i also thought about modifying AbiDecode to include decode_with_selector(selector: Selector, bytes: &[u8])
but didn't want to get into lower level changes
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.
you can also consult the docstring, btw
/// A trait for enums unifying [`EthError`] types.
///
/// We do not recommend manual implementations of this trait. Instead, use the
/// automatically generated implementation in the [`crate::abigen`] macro```
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.
good w/ me pending any more matt feedback
d7d3bb0
to
03e8f1f
Compare
this is now based on latest master 👍 |
@prestwich seems to have broken in the Seaport codegen
|
@gakonst seaport is fixed now 👍 |
4c648b5
to
1fc4cd9
Compare
Motivation
Followup work to #2172. Allows easier decoding of error types for generated contracts
Solution
ContractRevert
traitContractRevert
on the error enum inabigen!
contract modulesRevertString(String)
to contract error enum inabigen!
contract modulesContractError::decode_contract_revert<Err: ContractRevert(&self) -> Option<Err>
FromIterator
impls toethers::core::types::Bytes
This is a breaing change to
abigen!
generated bindings (again) but i promise this one is also really good :)PR Checklist