Source code for cadrumo.application.operations.persistence.financial_operand_custody
"""Durable custody-checkpoint persistence contract for financial operands.The repository stores the checkpoints defined by the operand custody contractand nothing else. Its guarantee is narrow and load-bearing: an advance isaccepted only when it follows the predecessor the caller actually observed, sotwo supervisor paths racing to settle one wait cannot both win.That compare-and-swap is what makes release exactly-once at the durable layerrather than only in memory. The in-process transition table refuses an illegalmove; this refuses a legal move applied twice.See Also: :class:`~cadrumo.application.operations.financial_operand_custody.OperationFinancialOperandCustodyCheckpoint` The non-sensitive record this contract persists and replays."""from__future__importannotationsfromtypingimportTYPE_CHECKING,Protocol,runtime_checkablefrom....core.errors.hierarchyimportCadrumoErrorifTYPE_CHECKING:from..financial_operand_custodyimportOperationFinancialOperandCustodyCheckpoint
[docs]classOperationFinancialOperandCustodyConflictError(CadrumoError):"""Raised when a custody advance loses its compare-and-swap."""
[docs]@runtime_checkableclassOperationFinancialOperandCustodyRepository(Protocol):"""Persist and replay one operand wait's custody positions."""
[docs]asyncdefread(self,interaction_id:str)->OperationFinancialOperandCustodyCheckpoint|None:"""Return the latest checkpoint for one wait, or ``None`` if never opened."""...
[docs]asyncdefopen(self,checkpoint:OperationFinancialOperandCustodyCheckpoint)->None:"""Record the opening checkpoint, refusing a wait that already exists."""...
[docs]asyncdefadvance(self,predecessor:OperationFinancialOperandCustodyCheckpoint,successor:OperationFinancialOperandCustodyCheckpoint,)->None:"""Replace ``predecessor`` with ``successor`` only if it is still current. Raises: OperationFinancialOperandCustodyConflictError: The stored checkpoint is no longer ``predecessor``, so another path already settled or advanced this wait. """...
[docs]asyncdefunsettled(self)->tuple[OperationFinancialOperandCustodyCheckpoint,...]:"""Return every wait left in a non-terminal state, for restart reconciliation."""...