From ecbb5be925227a23773de868bfe7fe1d5c689beb Mon Sep 17 00:00:00 2001 From: kibagateaux Date: Mon, 23 Jan 2023 15:51:35 -0500 Subject: [PATCH] generate Event.args_map on request and cache instead of instaniating object --- boa/vyper/contract.py | 3 +-- boa/vyper/event.py | 10 +++++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/boa/vyper/contract.py b/boa/vyper/contract.py index b0a65687..728c23ee 100644 --- a/boa/vyper/contract.py +++ b/boa/vyper/contract.py @@ -627,8 +627,7 @@ def decode_log(self, e): 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) + return Event(log_id, self.address, event_t, event_name, decoded_topics, args) def marshal_to_python(self, computation, vyper_typ): self._computation = computation # for further inspection diff --git a/boa/vyper/event.py b/boa/vyper/event.py index a6c0a4c9..6bde5328 100644 --- a/boa/vyper/event.py +++ b/boa/vyper/event.py @@ -1,3 +1,4 @@ +import functools from dataclasses import dataclass from typing import Any, List, Dict @@ -11,11 +12,14 @@ class 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): return self.event_name - + + @functools.cached_property + def args_map(self): + event_values = self.event_name.split(', ') + return dict([(topic.split('=')) for topic in event_values]) class RawEvent: - event_data: Any + event_data: Any \ No newline at end of file