From 8fead85a5f394bd056e22293ea6df3237fbe6db3 Mon Sep 17 00:00:00 2001 From: grace0950 Date: Sat, 2 Mar 2024 17:58:13 +0800 Subject: [PATCH] Update: send tx as params of success handler --- pyproject.toml | 2 +- ticton/__init__.py | 2 +- ticton/callbacks.py | 15 +++++++++++++++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 735c3cb..68e6088 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "ticton" -version = "0.1.24" +version = "0.1.25" description = "" authors = ["alan890104 "] readme = "README.md" diff --git a/ticton/__init__.py b/ticton/__init__.py index 8842029..302f34e 100644 --- a/ticton/__init__.py +++ b/ticton/__init__.py @@ -1,7 +1,7 @@ from .arithmetic import FixedFloat, to_token, token_to_float from .client import DryRunResult, TicTonAsyncClient -__version__ = "0.1.24" +__version__ = "0.1.25" __all__ = [ "FixedFloat", diff --git a/ticton/callbacks.py b/ticton/callbacks.py index 4f05595..7449535 100644 --- a/ticton/callbacks.py +++ b/ticton/callbacks.py @@ -12,13 +12,18 @@ class OnTickSuccessParams(BaseModel): + tx: Transaction watchmaker: AddressLike base_asset_price: float new_alarm_id: int created_at: int + def __str__(self): + return f"Tick success: new_alarm_id={self.new_alarm_id}, watchmaker={self.watchmaker}, base_asset_price={self.base_asset_price}, created_at={self.created_at}" + class OnWindSuccessParams(BaseModel): + tx: Transaction timekeeper: AddressLike alarm_id: int new_base_asset_price: float @@ -26,14 +31,21 @@ class OnWindSuccessParams(BaseModel): new_alarm_id: int created_at: int + def __str__(self): + return f"Wind success: new_alarm_id={self.new_alarm_id}, alarm_id={self.alarm_id}, timekeeper={self.timekeeper}, new_base_asset_price={self.new_base_asset_price}, remain_scale={self.remain_scale}, created_at={self.created_at}" + class OnRingSuccessParams(BaseModel): + tx: Transaction alarm_id: int = Field(..., description="alarm index") created_at: int = Field(..., description="created at") origin: Optional[AddressLike] = Field(None, description="origin address, maybe empty if no reward") receiver: Optional[AddressLike] = Field(None, description="receiver address, maybe empty if no reward") reward: float = Field(0.0, description="reward amount") + def __str__(self): + return f"Ring success: alarm_id={self.alarm_id}, origin={self.origin}, receiver={self.receiver}, reward={self.reward}, created_at={self.created_at}" + async def handle_noop(*args, **kwargs): ... @@ -87,6 +99,7 @@ async def _handle_tick( base_asset_price = float(FixedFloat(tick_msg.base_asset_price, skip_scale=True).to_float()) * 1e3 await on_tick_success( OnTickSuccessParams( + tx=tx, watchmaker=tock_msg.watchmaker, # type: ignore base_asset_price=base_asset_price, new_alarm_id=tock_msg.alarm_index, @@ -128,6 +141,7 @@ async def handle_chime( await on_wind_success( OnWindSuccessParams( + tx=tx, timekeeper=tock_msg.watchmaker, # type: ignore alarm_id=wind_msg.alarm_index, new_base_asset_price=float(FixedFloat(wind_msg.new_base_asset_price, skip_scale=True).to_float()) * 1e3, @@ -169,6 +183,7 @@ async def handle_chronoshift( await on_ring_success( OnRingSuccessParams( + tx=tx, alarm_id=chronoshift_msg.alarm_index, created_at=chronoshift_msg.created_at, origin=origin, # type: ignore