Skip to content
Snippets Groups Projects
Messages.py 1.08 KiB
Newer Older
  • Learn to ignore specific revisions
  • Abe Zukor's avatar
    Abe Zukor committed
    
    
    azukor2's avatar
    azukor2 committed
    from __future__ import annotations
    
    Abe Zukor's avatar
    Abe Zukor committed
    from dataclasses import dataclass
    from Transaction import Transaction
    
    azukor2's avatar
    azukor2 committed
    from typing import TYPE_CHECKING
    from uuid import uuid4
    
    if TYPE_CHECKING:
        from TransactionDeliverer import TransactionDeliverer
    
    Abe Zukor's avatar
    Abe Zukor committed
    
    @dataclass
    class Message:
    
    azukor2's avatar
    azukor2 committed
        message_id: str
    
    Abe Zukor's avatar
    Abe Zukor committed
        sender: str
        receiver: str
    
    
    azukor2's avatar
    azukor2 committed
        def receive_action(self):
            raise NotImplementedError("This is an abstract method that should never be called")
    
    
    Abe Zukor's avatar
    Abe Zukor committed
    @dataclass
    class TransactionMessage(Message):
        transaction: Transaction
    
    azukor2's avatar
    azukor2 committed
        transaction_ID: str
    
    Abe Zukor's avatar
    Abe Zukor committed
        deliverable: bool = False
    
    azukor2's avatar
    azukor2 committed
        
        def receive_action(self, td: TransactionDeliverer):
            td.process_transaction_message(self)
    
    
    Abe Zukor's avatar
    Abe Zukor committed
    @dataclass
    class ProposedPriorityMessage(Message):
        transaction_ID: str
        proposed_priority: int
    
    azukor2's avatar
    azukor2 committed
    
        def receive_action(self, td: TransactionDeliverer):
            td.process_proposed_priority_message(self)
        
    
    Abe Zukor's avatar
    Abe Zukor committed
    
    @dataclass
    class AgreedPriorityMessage(Message):
        transaction_ID: str
    
    azukor2's avatar
    azukor2 committed
        agreed_priority: int
    
        def receive_action(self, td: TransactionDeliverer):
            td.process_agreed_priority_message(self)