Example #1
0
class TransactionScheduler:
    def __init__(self):
        self.current_events_chain = CurrentEventsChain()
        self.future_events_chain = FutureEventsChain()
        self.clock = 0

    def moveNextTransaction(self):
        # Removes the Active Transaction from the CEC,
        active_transaction = self.current_events_chain.removeActiveTransaction()

        if active_transaction:
            # Calls the routine for the next sequential Block (NSB)
            if active_transaction.getNextSequentialBlock():
                # Unless something extraordinary occurs, replaces the Transaction
                # in front of its peers (i.e. same priority) on the CEC.
                self.current_events_chain.replaceActiveTransaction(active_transaction)
            return True
        else:
            return False

    def replenishCecWithFecTransactions(self):
        # Removes transactions from the fec for that scheduled time
        for transaction in self.future_events_chain.removeNextTransactions(self.clock):
            self.current_events_chain.append(transaction)

    def addNewTransactions(self, transactions):
        for transaction in transactions:
            if transaction.isDelayed():
                self.future_events_chain.addTransaction(transaction)
            else:
                self.current_events_chain.addTransaction(transaction)

    def advanceClock(self):
        self.clock += 1
        return self.clock
Example #2
0
 def __init__(self):
     self.current_events_chain = CurrentEventsChain()
     self.future_events_chain = FutureEventsChain()
     self.clock = 0