|
| 1 | +"""Address-related API models.""" |
| 2 | + |
| 3 | +from typing import Any, Optional |
| 4 | + |
| 5 | +from pydantic import ConfigDict |
| 6 | + |
| 7 | +from gsrest.models.base import APIModel |
| 8 | +from gsrest.models.common import LabeledItemRef |
| 9 | +from gsrest.models.transactions import TxSummary |
| 10 | +from gsrest.models.values import Values |
| 11 | + |
| 12 | + |
| 13 | +class Address(APIModel): |
| 14 | + """Address model.""" |
| 15 | + |
| 16 | + # Allow extra fields for test fixtures that set .tags |
| 17 | + model_config = ConfigDict( |
| 18 | + populate_by_name=True, |
| 19 | + from_attributes=True, |
| 20 | + extra="allow", |
| 21 | + ) |
| 22 | + |
| 23 | + currency: str |
| 24 | + address: str |
| 25 | + entity: int |
| 26 | + balance: Values |
| 27 | + total_received: Values |
| 28 | + total_spent: Values |
| 29 | + first_tx: TxSummary |
| 30 | + last_tx: TxSummary |
| 31 | + in_degree: int |
| 32 | + out_degree: int |
| 33 | + no_incoming_txs: int |
| 34 | + no_outgoing_txs: int |
| 35 | + token_balances: Optional[dict[str, Values]] = None |
| 36 | + total_tokens_received: Optional[dict[str, Values]] = None |
| 37 | + total_tokens_spent: Optional[dict[str, Values]] = None |
| 38 | + actors: Optional[list[LabeledItemRef]] = None |
| 39 | + is_contract: Optional[bool] = None |
| 40 | + status: Optional[str] = None |
| 41 | + |
| 42 | + def to_dict(self, shallow: bool = False) -> dict[str, Any]: |
| 43 | + """Override to exclude extra fields (like 'tags') from serialization.""" |
| 44 | + result = super().to_dict(shallow=shallow) |
| 45 | + # Remove any extra fields that aren't part of the API response |
| 46 | + result.pop("tags", None) |
| 47 | + return result |
| 48 | + |
| 49 | + |
| 50 | +class NeighborAddress(APIModel): |
| 51 | + """Neighbor address model.""" |
| 52 | + |
| 53 | + value: Values |
| 54 | + no_txs: int |
| 55 | + address: Address |
| 56 | + labels: Optional[list[str]] = None |
| 57 | + token_values: Optional[dict[str, Values]] = None |
| 58 | + |
| 59 | + |
| 60 | +class NeighborAddresses(APIModel): |
| 61 | + """Paginated list of neighbor addresses.""" |
| 62 | + |
| 63 | + neighbors: list[NeighborAddress] |
| 64 | + next_page: Optional[str] = None |
0 commit comments