Skip to content

Commit

Permalink
introduce strategy chains
Browse files Browse the repository at this point in the history
  • Loading branch information
KPrasch committed Feb 7, 2024
1 parent 540f44a commit f8025f8
Show file tree
Hide file tree
Showing 10 changed files with 289 additions and 223 deletions.
1 change: 1 addition & 0 deletions atxm/_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def __init__(self, interval: float = INTERVAL):
self.log = Logger(self.__class__.__name__)
self._task = LoopingCall(self.run)
self._task.clock = self.CLOCK
self._task.interval = self.interval

@property
def running(self) -> bool:
Expand Down
44 changes: 43 additions & 1 deletion atxm/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,31 @@
from enum import Enum

from web3.types import RPCError


class Faults(Enum):
"""
Fault codes for transaction processing.
These are alternate states that a transaction can enter
other than "finalized".
"""

# Strategy has been running for too long
TIMEOUT = "timeout"

# Transaction has been capped and subsequently timed out
PAUSE = "pause"

# Transaction reverted
REVERT = "revert"

# Something went wrong
ERROR = "error"

# ...
INSUFFICIENT_FUNDS = "insufficient_funds"


class TransactionFinalized(Exception):
"""raised when a transaction has been included in a block"""

Expand All @@ -9,12 +34,29 @@ class InsufficientFunds(RPCError):
"""raised when a transaction exceeds the spending cap"""


class Halt(Exception):
class Wait(Exception):
"""
Raised when a strategy exceeds a limitation.
Used to mark a pending transaction as "wait, don't retry".
"""


class Fault(Exception):
"""raised when a transaction has been faulted"""

def __init__(
self,
tx: "AsyncTx",
fault: Faults,
clear: bool,
message: str
):
self.tx = tx
self.fault = fault
self.message = message
self.clear = clear
super().__init__(message)


class TransactionReverted(Exception):
"""raised when a transaction has been reverted"""
Loading

0 comments on commit f8025f8

Please sign in to comment.