Skip to content

Commit

Permalink
fix: encode address on brownie<1.20
Browse files Browse the repository at this point in the history
  • Loading branch information
BobTheBuidler committed Apr 17, 2024
1 parent 8a20c33 commit c55d8b3
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions eth_portfolio/_ydb/token_transfers.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@

import a_sync
from brownie import chain
try:
# this is only available in 4.0.0+
from eth_abi import encode
except ImportError:
from eth_abi import encode_single as encode
from eth_utils import encode_hex
from web3.types import LogReceipt
from y.datatypes import Address
Expand All @@ -20,6 +15,14 @@
from eth_portfolio.constants import TRANSFER_SIGS
from eth_portfolio.structs import TokenTransfer

try:
# this is only available in 4.0.0+
from eth_abi import encode
encode_address = lambda address: encode_hex(encode(["address"], str(address)))
except ImportError:
from eth_abi import encode_single
encode_address = lambda address: encode_hex(encode_single("address", str(address)))

logger = logging.getLogger(__name__)

class _TokenTransfers(ProcessedEvents["asyncio.Task[TokenTransfer]"]):
Expand Down Expand Up @@ -63,13 +66,13 @@ class InboundTokenTransfers(_TokenTransfers):
"""A container that fetches and iterates over all inbound token transfers for a particular wallet address"""
@property
def _topics(self) -> List:
return [TRANSFER_SIGS, None, [encode_hex(encode(['address'], str(self.address)))]]
return [TRANSFER_SIGS, None, [encode_address(self.address)]]

class OutboundTokenTransfers(_TokenTransfers):
"""A container that fetches and iterates over all outbound token transfers for a particular wallet address"""
@property
def _topics(self) -> List:
return [TRANSFER_SIGS, [encode_hex(encode(['address'], str(self.address)))]]
return [TRANSFER_SIGS, [encode_address(self.address)]]

class TokenTransfers(a_sync.ASyncIterable[TokenTransfer]):
"""
Expand Down

0 comments on commit c55d8b3

Please sign in to comment.