Skip to content

Commit 4c83213

Browse files
committed
Convert one last encode_single
1 parent a25164f commit 4c83213

File tree

3 files changed

+16
-11
lines changed

3 files changed

+16
-11
lines changed

tests/core/utilities/test_event_filter_builder.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,13 @@ def test_match_single_string_type_properties_data_arg(value):
4040

4141

4242
@given(st.text())
43-
def test_match_single_string_type_properties_topic_arg(value):
44-
topic_filter = TopicArgumentFilter(arg_type="string")
43+
def test_match_single_string_type_properties_topic_arg(web3, value):
44+
topic_filter = TopicArgumentFilter(arg_type="string", abi_codec=web3.codec)
4545
topic_filter.match_single(value)
4646

4747

4848
@given(st.lists(elements=st.text(), max_size=10, min_size=0))
49-
def test_match_any_string_type_properties(values):
50-
topic_filter = TopicArgumentFilter(arg_type="string")
49+
def test_match_any_string_type_properties(web3, values):
50+
topic_filter = TopicArgumentFilter(arg_type="string", abi_codec=web3.codec)
5151
topic_filter.match_any(*values)
5252
assert len(topic_filter.match_values) == len(values)

web3/_utils/events.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import itertools
77

88
from eth_abi import (
9-
encode_single,
109
grammar,
1110
)
1211
from eth_typing import (
@@ -268,12 +267,13 @@ class EventFilterBuilder:
268267
_address = None
269268
_immutable = False
270269

271-
def __init__(self, event_abi, formatter=None):
270+
def __init__(self, event_abi, abi_codec, formatter=None):
272271
self.event_abi = event_abi
272+
self.abi_codec = abi_codec
273273
self.formatter = formatter
274274
self.event_topic = initialize_event_topics(self.event_abi)
275275
self.args = AttributeDict(
276-
_build_argument_filters_from_event_abi(event_abi))
276+
_build_argument_filters_from_event_abi(event_abi, abi_codec))
277277
self._ordered_arg_names = tuple(arg['name'] for arg in event_abi['inputs'])
278278

279279
@property
@@ -376,11 +376,11 @@ def initialize_event_topics(event_abi):
376376

377377

378378
@to_dict
379-
def _build_argument_filters_from_event_abi(event_abi):
379+
def _build_argument_filters_from_event_abi(event_abi, abi_codec):
380380
for item in event_abi['inputs']:
381381
key = item['name']
382382
if item['indexed'] is True:
383-
value = TopicArgumentFilter(arg_type=item['type'])
383+
value = TopicArgumentFilter(abi_codec, arg_type=item['type'])
384384
else:
385385
value = DataArgumentFilter(arg_type=item['type'])
386386
yield key, value
@@ -431,6 +431,10 @@ def match_values(self):
431431

432432

433433
class TopicArgumentFilter(BaseArgumentFilter):
434+
def __init__(self, arg_type, abi_codec):
435+
self.abi_codec = abi_codec
436+
self.arg_type = arg_type
437+
434438
@to_tuple
435439
def _get_match_values(self):
436440
yield from (self._encode(value) for value in self._match_values)
@@ -446,7 +450,7 @@ def _encode(self, value):
446450
if is_dynamic_sized_type(self.arg_type):
447451
return to_hex(keccak(encode_single_packed(self.arg_type, value)))
448452
else:
449-
return to_hex(encode_single(self.arg_type, value))
453+
return to_hex(self.abi_codec.encode_single(self.arg_type, value))
450454

451455

452456
class EventLogErrorFlags(Enum):

web3/contract.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1072,7 +1072,7 @@ def createFilter(
10721072
topics=topics,
10731073
)
10741074

1075-
filter_builder = EventFilterBuilder(event_abi)
1075+
filter_builder = EventFilterBuilder(event_abi, self.web3.codec)
10761076
filter_builder.address = event_filter_params.get('address')
10771077
filter_builder.fromBlock = event_filter_params.get('fromBlock')
10781078
filter_builder.toBlock = event_filter_params.get('toBlock')
@@ -1100,6 +1100,7 @@ def createFilter(
11001100
def build_filter(self):
11011101
builder = EventFilterBuilder(
11021102
self._get_event_abi(),
1103+
self.web3.codec,
11031104
formatter=get_event_data(self.web3.codec, self._get_event_abi()))
11041105
builder.address = self.address
11051106
return builder

0 commit comments

Comments
 (0)