mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
Better topic0 (#4950)
Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
This commit is contained in:
@ -393,18 +393,26 @@ impl Filter {
|
||||
#[must_use]
|
||||
pub fn event(self, event_name: &str) -> Self {
|
||||
let hash = keccak256(event_name.as_bytes());
|
||||
self.topic0(hash)
|
||||
self.event_signature(hash)
|
||||
}
|
||||
|
||||
/// Hashes all event signatures and sets them as array to topic0
|
||||
/// Hashes all event signatures and sets them as array to event_signature(topic0)
|
||||
#[must_use]
|
||||
pub fn events(self, events: impl IntoIterator<Item = impl AsRef<[u8]>>) -> Self {
|
||||
let events = events.into_iter().map(|e| keccak256(e.as_ref())).collect::<Vec<_>>();
|
||||
self.topic0(events)
|
||||
self.event_signature(events)
|
||||
}
|
||||
|
||||
/// Sets event_signature(topic0) (the event name for non-anonymous events)
|
||||
#[must_use]
|
||||
pub fn event_signature<T: Into<Topic>>(mut self, topic: T) -> Self {
|
||||
self.topics[0] = topic.into();
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets topic0 (the event name for non-anonymous events)
|
||||
#[must_use]
|
||||
#[deprecated(note = "use `event_signature` instead")]
|
||||
pub fn topic0<T: Into<Topic>>(mut self, topic: T) -> Self {
|
||||
self.topics[0] = topic.into();
|
||||
self
|
||||
|
||||
@ -182,9 +182,9 @@ fn receipts_provider_example<T: ReceiptProvider + TransactionsProvider + HeaderP
|
||||
let addr = Address::random();
|
||||
let topic = B256::random();
|
||||
|
||||
// TODO: Make it clearer how to choose between topic0 (event name) and the other 3 indexed
|
||||
// topics. This API is a bit clunky and not obvious to use at the moemnt.
|
||||
let filter = Filter::new().address(addr).topic0(topic);
|
||||
// TODO: Make it clearer how to choose between event_signature(topic0) (event name) and the
|
||||
// other 3 indexed topics. This API is a bit clunky and not obvious to use at the moemnt.
|
||||
let filter = Filter::new().address(addr).event_signature(topic);
|
||||
let filter_params = FilteredParams::new(Some(filter));
|
||||
let address_filter = FilteredParams::address_filter(&addr.into());
|
||||
let topics_filter = FilteredParams::topics_filter(&[topic.into()]);
|
||||
|
||||
Reference in New Issue
Block a user