|
25 | 25 |
|
26 | 26 |
|
27 | 27 | class PortfolioLedgerBase(a_sync.ASyncGenericBase, _AiterMixin[T], Generic[_LedgerEntryList, T]): |
| 28 | + """ |
| 29 | + The :class:`~eth_portfolio._ledgers.PortfolioLedgerBase` class provides |
| 30 | + an abstract base for fetching and processing ledger entries across multiple Ethereum addresses |
| 31 | + in a portfolio. It defines common methods and properties for portfolio-wide ledger operations. |
| 32 | +
|
| 33 | + This class is a key component in the eth-portfolio ecosystem, serving as: |
| 34 | + - An abstraction layer between address-specific ledgers and portfolio-wide data management. |
| 35 | + - A foundation for standardized data processing across different ledger types. |
| 36 | + - A base for implementing asynchronous operations for efficient data retrieval. |
| 37 | +
|
| 38 | + Attributes: |
| 39 | + property_name: The name of the ledger property (e.g., 'transactions', 'token_transfers', 'internal_transfers'). |
| 40 | + portfolio: The portfolio containing the addresses to be queried. |
| 41 | + object_caches: A dictionary mapping Ethereum addresses to their respective address-specific ledgers. |
| 42 | +
|
| 43 | + Example: |
| 44 | + >>> ledger = PortfolioLedgerBase(portfolio=Portfolio(addresses=["0x1234...", "0xABCD..."])) |
| 45 | + """ |
| 46 | + |
28 | 47 | property_name: str |
29 | 48 | object_caches: Dict[Address, AddressLedgerBase[_LedgerEntryList, T]] |
30 | 49 |
|
31 | 50 | def __init__(self, portfolio: "Portfolio"): # type: ignore |
| 51 | + """ |
| 52 | + Initializes the :class:`~eth_portfolio._ledgers.PortfolioLedgerBase` class. |
| 53 | +
|
| 54 | + This constructor is crucial in the eth-portfolio ecosystem as it: |
| 55 | + - Sets up the foundation for portfolio-wide ledger management. |
| 56 | + - Establishes connections between portfolio addresses and their respective ledgers. |
| 57 | + - Ensures proper initialization for subclasses handling different ledger types. |
| 58 | +
|
| 59 | + Args: |
| 60 | + portfolio: The :class:`~eth_portfolio.portfolio.Portfolio` instance containing the Ethereum addresses to be managed. |
| 61 | +
|
| 62 | + Raises: |
| 63 | + AssertionError: If the subclass does not define a `property_name`, which is essential |
| 64 | + for identifying the specific ledger type (e.g., transactions, token transfers). |
| 65 | +
|
| 66 | + Example: |
| 67 | + >>> from eth_portfolio.portfolio import Portfolio |
| 68 | + >>> from eth_portfolio._ledgers import PortfolioTransactionsLedger |
| 69 | + >>> ledger = PortfolioTransactionsLedger(portfolio=Portfolio(addresses=["0x1234...", "0xABCD..."])) |
| 70 | +
|
| 71 | + Note: |
| 72 | + Subclasses must define a `property_name` attribute to specify the type of ledger |
| 73 | + they manage (e.g., 'transactions', 'token_transfers', 'internal_transfers'). |
| 74 | + """ |
32 | 75 | assert hasattr(self, "property_name"), "Subclasses must define a property_name" |
33 | 76 | self.object_caches = { |
34 | 77 | address.address: getattr(address, self.property_name) for address in portfolio |
|
0 commit comments