Skip to content

Commit 1d17f18

Browse files
committed
feat(docs): document PortfolioLedgerBase
1 parent 49a2f4b commit 1d17f18

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

eth_portfolio/_ledgers/portfolio.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,53 @@
2525

2626

2727
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+
2847
property_name: str
2948
object_caches: Dict[Address, AddressLedgerBase[_LedgerEntryList, T]]
3049

3150
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+
"""
3275
assert hasattr(self, "property_name"), "Subclasses must define a property_name"
3376
self.object_caches = {
3477
address.address: getattr(address, self.property_name) for address in portfolio

0 commit comments

Comments
 (0)