Skip to content

Commit

Permalink
feat(docs): more struct docs (#91)
Browse files Browse the repository at this point in the history
  • Loading branch information
BobTheBuidler authored Aug 27, 2024
1 parent d137bc9 commit 974a68e
Showing 1 changed file with 29 additions and 4 deletions.
33 changes: 29 additions & 4 deletions eth_portfolio/structs.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
"""
Defines the data classes used to represent the various types of value-transfer actions on the blockchain. These include transactions, internal transfers, and token transfers.
The classes are designed to provide a consistent and flexible interface for working with blockchain data. Instance attributes can be fetched with either dot notation or key lookup. Classes are compatible with the standard dictionary interface.
"""

import logging
from decimal import Decimal
from typing import Any, ClassVar, Iterator, Literal, Optional, Tuple, TypeVar, Union
Expand Down Expand Up @@ -40,12 +46,12 @@ def __getitem__(self, item: str) -> Any:
Args:
item: The name of the field to retrieve.
Returns:
The value of the specified field.
Raises:
KeyError: If the provided key is not a member of the struct.
Returns:
The value of the specified field.
"""
try:
return getattr(self, item)
Expand All @@ -71,6 +77,10 @@ class _LedgerEntryBase(_DictStruct, kw_only=True, frozen=True):
hash: str
from_address: Optional[str] = None
value: Decimal
"""
The value/amount of the transferred assets.
"""

to_address: Optional[str] = None
price: Optional[Decimal] = None
"""
Expand Down Expand Up @@ -147,6 +157,10 @@ class Transaction(_LedgerEntryBase, kw_only=True, frozen=True):
"""

entry_type: ClassVar[Literal['transaction']] = 'transaction'
"""
Constant indicating this value transfer is an on-chain transaction entry.
"""

block_hash: str
"""
The hash of the block that includes this transaction.
Expand Down Expand Up @@ -249,6 +263,10 @@ class InternalTransfer(_LedgerEntryBase, kw_only=True, frozen=True):
"""

entry_type: ClassVar[Literal['internal_transfer']] = 'internal_transfer'
"""
Constant indicating this value transfer is an internal transfer or call entry.
"""

block_hash: str
"""
The hash of the block containing the transaction that includes this internal transfer.
Expand Down Expand Up @@ -342,6 +360,10 @@ class TokenTransfer(_LedgerEntryBase, kw_only=True, frozen=True):
"""

entry_type: ClassVar[Literal['token_transfer']] = 'token_transfer'
"""
Constant indicating this value transfer is a token transfer entry.
"""

log_index: int
"""
The index of this transfer event within the transaction logs.
Expand All @@ -359,6 +381,9 @@ class TokenTransfer(_LedgerEntryBase, kw_only=True, frozen=True):
"""

value: Decimal
"""
The amount of tokens transferred, scaled to a human-readable decimal value.
"""


LedgerEntry = Union[Transaction, InternalTransfer, TokenTransfer]
Expand All @@ -369,4 +394,4 @@ class TokenTransfer(_LedgerEntryBase, kw_only=True, frozen=True):
_LE = TypeVar("_LE", Transaction, InternalTransfer, TokenTransfer)
"""
Type variable for generic operations on ledger entries. Can be :class:`~structs.Transaction`, :class:`~structs.InternalTransfer`, or :class:`~structs.TokenTransfer`.
"""
"""

0 comments on commit 974a68e

Please sign in to comment.