Skip to content

Commit

Permalink
move all Event type instantiation to decode_logs
Browse files Browse the repository at this point in the history
  • Loading branch information
kibagateaux committed Jan 23, 2023
1 parent 48641f5 commit 9c1f958
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
20 changes: 18 additions & 2 deletions boa/vyper/contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -609,10 +609,26 @@ def decode_log(self, e):
)

tuple_typ = TupleType(arg_typs)

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

return Event(log_id, self.address, event_t, decoded_topics, args, {})
# 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

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

def marshal_to_python(self, computation, vyper_typ):
self._computation = computation # for further inspection
Expand Down
20 changes: 2 additions & 18 deletions boa/vyper/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,13 @@ 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
args_map: Dict[str, Any] # Mapping of decoded args

def __repr__(self):
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)
self.args_map = dict([(k,v) for k, v in b])
return f"{self.event_type.name}({args})"
return self.event_name


class RawEvent:
Expand Down

0 comments on commit 9c1f958

Please sign in to comment.