Skip to content

Commit

Permalink
Update: send tx as params of success handler
Browse files Browse the repository at this point in the history
  • Loading branch information
grace0950 committed Mar 2, 2024
1 parent 2dcf55c commit 8fead85
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "ticton"
version = "0.1.24"
version = "0.1.25"
description = ""
authors = ["alan890104 <[email protected]>"]
readme = "README.md"
Expand Down
2 changes: 1 addition & 1 deletion ticton/__init__.py
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
15 changes: 15 additions & 0 deletions ticton/callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,40 @@


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
remain_scale: int
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): ...

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 8fead85

Please sign in to comment.