Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: refactor #164

Merged
merged 1 commit into from
Dec 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions eth_portfolio/_db/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -454,29 +454,32 @@ def get_token_transfer(transfer: evmspec.Log) -> Optional[TokenTransfer]:
def transactions_known_at_startup(chainid: int, from_address: ChecksumAddress) -> Dict[_TPK, bytes]:
transfers = {}
obj: Tuple[int, ChecksumAddress, int, bytes]
for obj in select(
for nonce, raw in select(
(t.nonce, t.raw)
for t in entities.Transaction # type: ignore [attr-defined]
if t.from_address.chain.id == chainid and t.from_address.address == from_address
):
nonce, raw = obj
transfers[nonce] = raw
return transfers


_TTPK = Tuple[Tuple[int, int], int, int]
_TokenTransferPK = Tuple[Tuple[int, int], int, int]


@lru_cache(maxsize=None)
def token_transfers_known_at_startup() -> Dict[_TTPK, bytes]:
def token_transfers_known_at_startup() -> Dict[_TokenTransferPK, bytes]:
chainid: int
block: int
tx_index: int
log_index: int
raw: bytes

transfers = {}
obj: Tuple[int, int, int, int, bytes]
for obj in select(
for chainid, block, tx_index, log_index, raw in select(
(t.block.chain.id, t.block.number, t.transaction_index, t.log_index, t.raw)
for t in entities.TokenTransfer # type: ignore [attr-defined]
if t.block.chain.id == chain.id
):
chainid, block, tx_index, log_index, raw = obj
pk = ((chainid, block), tx_index, log_index)
transfers[pk] = raw
return transfers
Expand Down
Loading