Skip to content

Commit 907fe1f

Browse files
committed
Add database model documentation
1 parent c250513 commit 907fe1f

File tree

4 files changed

+52
-1
lines changed

4 files changed

+52
-1
lines changed

safe_transaction_service/account_abstraction/models.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ def to_safe_operation(self) -> SafeOperationClass:
113113

114114

115115
class UserOperationReceipt(models.Model):
116+
"""Stores the on-chain receipt metadata produced when a user operation executes."""
117+
116118
user_operation = models.OneToOneField(
117119
UserOperation, on_delete=models.CASCADE, related_name="receipt"
118120
)
@@ -141,6 +143,8 @@ def without_confirmations(self):
141143

142144

143145
class SafeOperation(TimeStampedModel):
146+
"""Represents a Safe account-abstraction operation built from a user operation."""
147+
144148
objects = SafeOperationQuerySet.as_manager()
145149
hash = Keccak256Field(primary_key=True) # safeOperationHash
146150
user_operation = models.OneToOneField(
@@ -194,6 +198,8 @@ def build_signature(self) -> bytes:
194198

195199

196200
class SafeOperationConfirmation(TimeStampedModel):
201+
"""Signature provided by a Safe owner to authorize a Safe operation."""
202+
197203
safe_operation = models.ForeignKey(
198204
SafeOperation,
199205
on_delete=models.CASCADE,

safe_transaction_service/contracts/models.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,9 @@ def trusted_addresses_for_delegate_call(self):
149149
return self.trusted_for_delegate_call().values_list("address", flat=True)
150150

151151

152-
class Contract(models.Model): # Known contract addresses by the service
152+
class Contract(models.Model):
153+
"""Tracks known contract addresses with optional ABI and branding metadata."""
154+
153155
objects = ContractManager.from_queryset(ContractQuerySet)()
154156
address = EthereumAddressBinaryField(primary_key=True)
155157
name = models.CharField(max_length=200, blank=True, default="")

safe_transaction_service/history/models.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,8 @@ def set_erc20_721_indexing_status(
206206

207207

208208
class IndexingStatus(models.Model):
209+
"""Records the latest processed block for each indexing pipeline."""
210+
209211
objects = IndexingStatusManager()
210212
indexing_type = models.PositiveSmallIntegerField(
211213
primary_key=True,
@@ -318,6 +320,8 @@ def until_block(self, block_number: int):
318320

319321

320322
class EthereumBlock(models.Model):
323+
"""Ethereum block header and metadata used for indexing and reorg handling."""
324+
321325
objects = EthereumBlockManager.from_queryset(EthereumBlockQuerySet)()
322326
number = models.PositiveIntegerField(primary_key=True)
323327
gas_limit = Uint256Field()
@@ -411,6 +415,8 @@ def account_abstraction_txs(self) -> RawQuerySet:
411415

412416

413417
class EthereumTx(TimeStampedModel):
418+
"""Ethereum transaction enriched with receipt data and indexer bookkeeping."""
419+
414420
objects = EthereumTxManager()
415421
block = models.ForeignKey(
416422
EthereumBlock,
@@ -571,6 +577,8 @@ def fast_count(self, address: ChecksumAddress) -> int:
571577

572578

573579
class TokenTransfer(models.Model):
580+
"""Abstract base model normalizing token transfer events across standards."""
581+
574582
objects = TokenTransferManager.from_queryset(TokenTransferQuerySet)()
575583
ethereum_tx = models.ForeignKey(EthereumTx, on_delete=models.CASCADE)
576584
timestamp = models.DateTimeField(db_index=True)
@@ -651,6 +659,8 @@ def token_txs(self):
651659

652660

653661
class ERC20Transfer(TokenTransfer):
662+
"""ERC-20 `Transfer` event captured for a tracked Safe-related transaction."""
663+
654664
objects = TokenTransferManager.from_queryset(ERC20TransferQuerySet)()
655665
value = Uint256Field()
656666

@@ -767,6 +777,8 @@ def token_txs(self):
767777

768778

769779
class ERC721Transfer(TokenTransfer):
780+
"""ERC-721 `Transfer` event including the non-fungible token identifier."""
781+
770782
objects = ERC721TransferManager.from_queryset(ERC721TransferQuerySet)()
771783
token_id = Uint256Field()
772784

@@ -1111,6 +1123,11 @@ def can_be_decoded(self):
11111123

11121124

11131125
class InternalTx(models.Model):
1126+
"""
1127+
Represents an internal call trace produced while executing a Safe-related transaction.
1128+
For L2 networks, as traces are not available, they are "simulated" from events.
1129+
"""
1130+
11141131
objects = InternalTxManager.from_queryset(InternalTxQuerySet)()
11151132
ethereum_tx = models.ForeignKey(
11161133
EthereumTx, on_delete=models.CASCADE, related_name="internal_txs"
@@ -1326,6 +1343,8 @@ def safes_pending_to_be_processed(self) -> QuerySet[ChecksumAddress]:
13261343

13271344

13281345
class InternalTxDecoded(models.Model):
1346+
"""Holds decoded Safe contract call data for an internal transaction."""
1347+
13291348
objects = InternalTxDecodedManager.from_queryset(InternalTxDecodedQuerySet)()
13301349
internal_tx = models.OneToOneField(
13311350
InternalTx,
@@ -1586,6 +1605,8 @@ def queued(self, safe_address: str):
15861605

15871606

15881607
class MultisigTransaction(TimeStampedModel):
1608+
"""Safe multisig transaction with execution status, gas parameters, and signatures."""
1609+
15891610
objects = MultisigTransactionManager.from_queryset(MultisigTransactionQuerySet)()
15901611
safe_tx_hash = Keccak256Field(primary_key=True)
15911612
safe = EthereumAddressBinaryField(db_index=True)
@@ -1707,6 +1728,8 @@ def not_indexed_metadata_contract_addresses(self):
17071728

17081729

17091730
class ModuleTransaction(TimeStampedModel):
1731+
"""Safe module execution derived from an internal transaction trace."""
1732+
17101733
objects = ModuleTransactionManager()
17111734
internal_tx = models.OneToOneField(
17121735
InternalTx, on_delete=models.CASCADE, related_name="module_tx", primary_key=True
@@ -1781,6 +1804,8 @@ def with_transaction(self):
17811804

17821805

17831806
class MultisigConfirmation(TimeStampedModel):
1807+
"""Owner confirmation or signature associated with a multisig transaction."""
1808+
17841809
objects = MultisigConfirmationManager.from_queryset(MultisigConfirmationQuerySet)()
17851810
ethereum_tx = models.ForeignKey(
17861811
EthereumTx,
@@ -1847,6 +1872,8 @@ def to_dict(self) -> dict:
18471872

18481873

18491874
class MonitoredAddress(models.Model):
1875+
"""Abstract base storing indexing progress for addresses we continuously monitor."""
1876+
18501877
address = EthereumAddressBinaryField(primary_key=True)
18511878
initial_block_number = models.IntegerField(
18521879
default=0
@@ -1867,6 +1894,8 @@ def __str__(self):
18671894

18681895

18691896
class ProxyFactory(MonitoredAddress):
1897+
"""Safe Proxy Factory contract whose emitted events are tracked for deployments."""
1898+
18701899
class Meta:
18711900
verbose_name_plural = "Proxy factories"
18721901
ordering = ["tx_block_number"]
@@ -1912,6 +1941,8 @@ def relevant(self):
19121941

19131942

19141943
class SafeMasterCopy(MonitoredAddress):
1944+
"""Indexed Safe master copy contract including version and deployment metadata."""
1945+
19151946
objects = SafeMasterCopyManager.from_queryset(SafeMasterCopyQueryset)()
19161947
version = models.CharField(max_length=20, validators=[validate_version])
19171948
deployer = models.CharField(max_length=50, default="Safe")
@@ -1955,6 +1986,8 @@ def banned(
19551986

19561987

19571988
class SafeContract(models.Model):
1989+
"""Represents a deployed Safe smart contract and its creation transaction."""
1990+
19581991
objects = SafeContractManager.from_queryset(SafeContractQuerySet)()
19591992
created = models.DateTimeField(auto_now_add=True, db_index=True)
19601993
address = EthereumAddressBinaryField(primary_key=True)
@@ -2135,6 +2168,8 @@ def from_erc20_721_event(
21352168

21362169

21372170
class SafeStatusBase(models.Model):
2171+
"""Shared Safe state representation produced after processing an internal transaction."""
2172+
21382173
internal_tx = models.OneToOneField(
21392174
InternalTx,
21402175
on_delete=models.CASCADE,
@@ -2255,6 +2290,8 @@ def addresses_for_owner(self, owner_address: str) -> QuerySet[str]:
22552290

22562291

22572292
class SafeLastStatus(SafeStatusBase):
2293+
"""Latest known Safe state cached for quick access."""
2294+
22582295
objects = SafeLastStatusManager()
22592296

22602297
class Meta:
@@ -2330,6 +2367,8 @@ def last_for_address(self, address: str) -> Optional["SafeStatus"]:
23302367

23312368

23322369
class SafeStatus(SafeStatusBase):
2370+
"""Historical Safe state snapshot for each processed configuration change."""
2371+
23332372
objects = SafeStatusManager.from_queryset(SafeStatusQuerySet)()
23342373
internal_tx = models.OneToOneField(
23352374
InternalTx,

safe_transaction_service/tokens/models.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,8 @@ def without_logo(self):
208208

209209

210210
class Token(models.Model):
211+
"""Stores metadata about ERC-20 and ERC-721 tokens handled by the service."""
212+
211213
objects = TokenManager.from_queryset(TokenQuerySet)()
212214
pool_tokens = PoolTokenManager()
213215
address = EthereumAddressBinaryField(primary_key=True)
@@ -334,6 +336,8 @@ class TokenListToken(TypedDict):
334336

335337

336338
class TokenList(models.Model):
339+
"""References an external token list that should be ingested into the service."""
340+
337341
url = models.URLField(unique=True)
338342
description = models.CharField(max_length=200)
339343

0 commit comments

Comments
 (0)