From d383fcffed5b9cabfdef6418094545c8e82b98df Mon Sep 17 00:00:00 2001 From: derekpierre Date: Thu, 4 Apr 2024 14:04:16 -0400 Subject: [PATCH] Add an API with the ability to remove a tx from anywhere in the queue; this is handy when the user is notified about a failed tx and doesn't want to stall other txs from executing. Only the user has the context to make that decision, not ATxM. --- atxm/machine.py | 9 +++++++++ atxm/tracker.py | 7 +++++++ 2 files changed, 16 insertions(+) diff --git a/atxm/machine.py b/atxm/machine.py index 42bc85d..83e06d2 100644 --- a/atxm/machine.py +++ b/atxm/machine.py @@ -521,3 +521,12 @@ def queue_transaction( self._wake() return tx + + def remove_queued_transaction(self, tx: FutureTx): + """ + Removes a queued transaction; useful when an exisitng queued transaction has broadcast + failures, or a queued transaction is no longer necessary. + + Returns true if transaction was present and removed, false otherwise. + """ + return self._tx_tracker.remove_queued_tx(tx) diff --git a/atxm/tracker.py b/atxm/tracker.py index a146cd7..4a74751 100644 --- a/atxm/tracker.py +++ b/atxm/tracker.py @@ -257,3 +257,10 @@ def queue_tx( f"[tracker] queued transaction #atx-{tx.id} priority {len(self.__queue)}" ) return tx + + def remove_queued_tx(self, tx: FutureTx) -> bool: + try: + self.__queue.remove(tx) + return True + except ValueError: + return False