Skip to content

Commit

Permalink
refactor for less code change
Browse files Browse the repository at this point in the history
  • Loading branch information
kibagateaux committed Jan 24, 2023
1 parent ecbb5be commit 481b7f5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 22 deletions.
19 changes: 2 additions & 17 deletions boa/vyper/contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -609,25 +609,10 @@ def decode_log(self, e):
)

tuple_typ = TupleType(arg_typs)
args = abi_decode(tuple_typ.abi_type.selector_name(), data)

# align the evm topic + args lists with the way they appear in the source
# ex. Transfer(indexed address, address, indexed address)
t_i = 0
a_i = 0
decoded_values = []
for is_topic, k in zip(
event_t.indexed, event_t.arguments.keys()
):
if is_topic:
decoded_values.append((k, decoded_topics[t_i]))
t_i += 1
else:
decoded_values.append((k, args[a_i]))
a_i += 1
args = abi_decode(tuple_typ.abi_type.selector_name(), data)

event_name = ", ".join(f"{k}={v}" for k, v in decoded_values)
return Event(log_id, self.address, event_t, event_name, decoded_topics, args)
return Event(log_id, self.address, event_t, decoded_topics, args)

def marshal_to_python(self, computation, vyper_typ):
self._computation = computation # for further inspection
Expand Down
27 changes: 22 additions & 5 deletions boa/vyper/event.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import functools
import re
from dataclasses import dataclass
from typing import Any, List, Dict

Expand All @@ -9,17 +10,33 @@ class Event:
log_id: int # internal py-evm log id, for ordering purposes
address: str # checksum address
event_type: Any # vyper.semantics.types.user.Event
event_name: str # human readable output
topics: List[Any] # list of decoded topics
args: List[Any] # list of decoded args

def __repr__(self):
return self.event_name
t_i = 0
a_i = 0
b = []
# align the evm topic + args lists with the way they appear in the source
# ex. Transfer(indexed address, address, indexed address)
for is_topic, k in zip(
self.event_type.indexed, self.event_type.arguments.keys()
):
if is_topic:
b.append((k, self.topics[t_i]))
t_i += 1
else:
b.append((k, self.args[a_i]))
a_i += 1

args = ", ".join(f"{k}={v}" for k, v in b)
return f"{self.event_type.name}({args})"

@functools.cached_property
def args_map(self):
event_values = self.event_name.split(', ')
return dict([(topic.split('=')) for topic in event_values])
def args_map(self) -> Dict[str, Any]:
# get values from inside event pareentheses
event_values = dict(re.findall(r"(\w+)=([\w\d]+)", self.__repr__()))
return event_values

class RawEvent:
event_data: Any

0 comments on commit 481b7f5

Please sign in to comment.