Skip to content

Commit

Permalink
fix: time_left max C int issue [SBK-338] (#67)
Browse files Browse the repository at this point in the history
* fix: time_left max C int issue

* refactor: use constant instead of setting for max duration
  • Loading branch information
mikeshultz authored Oct 27, 2023
1 parent 736f946 commit c750cf4
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions sdk/py/apepay/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
)
from .utils import time_unit_to_timedelta

MAX_DURATION_SECONDS = int(timedelta.max.total_seconds()) - 1


class Validator(BaseInterfaceModel):
contract: ContractInstance
Expand Down Expand Up @@ -427,17 +429,20 @@ def amount_left(self) -> int:

@property
def time_left(self) -> timedelta:
return timedelta(seconds=self.contract.time_left(self.creator, self.stream_id))
seconds = self.contract.time_left(self.creator, self.stream_id)
return timedelta(seconds=min(MAX_DURATION_SECONDS, seconds))

@property
def total_time(self) -> timedelta:
info = self.info # NOTE: Avoid calling contract twice
# NOTE: Measure time-duration of unclaimed amount remaining (locked and unlocked)
max_life = int(info.funded_amount / info.amount_per_second)

return (
# NOTE: `last_pull == start_time` if never pulled
datetime.fromtimestamp(info.last_pull)
- datetime.fromtimestamp(info.start_time)
# NOTE: Measure time-duration of unclaimed amount remaining (locked and unlocked)
+ timedelta(seconds=int(info.funded_amount / info.amount_per_second))
+ timedelta(seconds=min(MAX_DURATION_SECONDS, max_life))
)

@property
Expand Down

0 comments on commit c750cf4

Please sign in to comment.