Skip to content

Commit

Permalink
Feat (ZkSync-lite): Notify decoding progress
Browse files Browse the repository at this point in the history
Signed-off-by: OjusWiZard <ojuswimail@gmail.com>
  • Loading branch information
OjusWiZard committed May 20, 2024
1 parent eaf6193 commit 1542ff2
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
5 changes: 4 additions & 1 deletion rotkehlchen/api/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2913,7 +2913,10 @@ def decode_pending_evmlike_transactions(
"""
decoded_num = 0
# For now it's only zksync lite
decoded_num = self.rotkehlchen.chains_aggregator.zksync_lite.decode_undecoded_transactions(force_redecode=ignore_cache) # noqa: E501
decoded_num = self.rotkehlchen.chains_aggregator.zksync_lite.decode_undecoded_transactions(
force_redecode=ignore_cache,
send_ws_notifications=True,
)
return {
'result': {'decoded_tx_number': decoded_num},
'message': '',
Expand Down
1 change: 1 addition & 0 deletions rotkehlchen/api/websockets/typedefs.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class WSMessageType(Enum):
DATABASE_UPLOAD_RESULT = auto()
ACCOUNTING_RULE_CONFLICT = auto()
EVM_UNDECODED_TRANSACTIONS = auto()
EVMLIKE_UNDECODED_TRANSACTIONS = auto()
CALENDAR_REMINDER = auto()

def __str__(self) -> str:
Expand Down
30 changes: 28 additions & 2 deletions rotkehlchen/chain/zksync_lite/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from pysqlcipher3.dbapi2 import IntegrityError

from rotkehlchen.accounting.structures.balance import Balance
from rotkehlchen.api.websockets.typedefs import WSMessageType
from rotkehlchen.assets.asset import Asset, CryptoAsset
from rotkehlchen.assets.utils import TokenEncounterInfo, get_or_create_evm_token
from rotkehlchen.chain.ethereum.utils import asset_normalized_value
Expand Down Expand Up @@ -61,6 +62,7 @@ def __init__(
database: 'DBHandler',
) -> None:
self.database = database
self.msg_aggregator = database.msg_aggregator
self.session = requests.session()
set_user_agent(self.session)
self.id_to_token: dict[int, CryptoAsset] = {}
Expand Down Expand Up @@ -838,7 +840,11 @@ def decode_transaction(
(1, transaction.tx_hash),
)

def decode_undecoded_transactions(self, force_redecode: bool) -> int:
def decode_undecoded_transactions(
self,
force_redecode: bool,
send_ws_notifications: bool = False,
) -> int:
"""Decodes undecoded zksync lite transactions. If force redecode is True
then all transactions are redecoded.
Returns the number of decoded transactions (not events in transactions)
Expand All @@ -851,7 +857,7 @@ def decode_undecoded_transactions(self, force_redecode: bool) -> int:
with self.database.conn.read_ctx() as cursor:
tracked_addresses = self.database.get_blockchain_accounts(cursor).zksync_lite

for transaction in transactions:
for tx_index, transaction in enumerate(transactions):
with self.database.user_write() as write_cursor: # delete old tx events
write_cursor.execute(
'DELETE FROM history_events WHERE event_identifier=?',
Expand All @@ -860,4 +866,24 @@ def decode_undecoded_transactions(self, force_redecode: bool) -> int:

self.decode_transaction(transaction, tracked_addresses)

if send_ws_notifications and tx_index % 10 == 0:
self.msg_aggregator.add_message(
message_type=WSMessageType.EVMLIKE_UNDECODED_TRANSACTIONS,
data={
'evm_chain': self.ethereum_inquirer.chain_name,
'total': len(transactions),
'processed': tx_index,
},
)

if send_ws_notifications:
self.msg_aggregator.add_message(
message_type=WSMessageType.EVMLIKE_UNDECODED_TRANSACTIONS,
data={
'evm_chain': self.ethereum_inquirer.chain_name,
'total': len(transactions),
'processed': len(transactions),
},
)

return len(transactions)

0 comments on commit 1542ff2

Please sign in to comment.