strideutils 0.3.6__tar.gz → 0.3.7__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. {strideutils-0.3.6 → strideutils-0.3.7}/PKG-INFO +1 -1
  2. {strideutils-0.3.6 → strideutils-0.3.7}/pyproject.toml +1 -1
  3. {strideutils-0.3.6 → strideutils-0.3.7}/strideutils/stride_requests.py +43 -40
  4. {strideutils-0.3.6 → strideutils-0.3.7}/README.md +0 -0
  5. {strideutils-0.3.6 → strideutils-0.3.7}/strideutils/Makefile +0 -0
  6. {strideutils-0.3.6 → strideutils-0.3.7}/strideutils/__init__.py +0 -0
  7. {strideutils-0.3.6 → strideutils-0.3.7}/strideutils/coingecko.py +0 -0
  8. {strideutils-0.3.6 → strideutils-0.3.7}/strideutils/config_examples/strideutils_config.yaml.example +0 -0
  9. {strideutils-0.3.6 → strideutils-0.3.7}/strideutils/config_examples/strideutils_secrets.yaml.example +0 -0
  10. {strideutils-0.3.6 → strideutils-0.3.7}/strideutils/cryptography.py +0 -0
  11. {strideutils-0.3.6 → strideutils-0.3.7}/strideutils/exec_tx.py +0 -0
  12. {strideutils-0.3.6 → strideutils-0.3.7}/strideutils/invariant_helpers.py +0 -0
  13. {strideutils-0.3.6 → strideutils-0.3.7}/strideutils/run_safely.py +0 -0
  14. {strideutils-0.3.6 → strideutils-0.3.7}/strideutils/sheets_connector.py +0 -0
  15. {strideutils-0.3.6 → strideutils-0.3.7}/strideutils/slack_connector.py +0 -0
  16. {strideutils-0.3.6 → strideutils-0.3.7}/strideutils/stride_alerts.py +0 -0
  17. {strideutils-0.3.6 → strideutils-0.3.7}/strideutils/stride_config.py +0 -0
  18. {strideutils-0.3.6 → strideutils-0.3.7}/strideutils/stride_upstash.py +0 -0
  19. {strideutils-0.3.6 → strideutils-0.3.7}/strideutils/twilio_connector.py +0 -0
  20. {strideutils-0.3.6 → strideutils-0.3.7}/strideutils/types.py +0 -0
  21. {strideutils-0.3.6 → strideutils-0.3.7}/strideutils-stubs/__init__.pyi +0 -0
  22. {strideutils-0.3.6 → strideutils-0.3.7}/strideutils-stubs/coingecko.pyi +0 -0
  23. {strideutils-0.3.6 → strideutils-0.3.7}/strideutils-stubs/cryptography.pyi +0 -0
  24. {strideutils-0.3.6 → strideutils-0.3.7}/strideutils-stubs/exec_tx.pyi +0 -0
  25. {strideutils-0.3.6 → strideutils-0.3.7}/strideutils-stubs/invariant_helpers.pyi +0 -0
  26. {strideutils-0.3.6 → strideutils-0.3.7}/strideutils-stubs/run_safely.pyi +0 -0
  27. {strideutils-0.3.6 → strideutils-0.3.7}/strideutils-stubs/sheets_connector.pyi +0 -0
  28. {strideutils-0.3.6 → strideutils-0.3.7}/strideutils-stubs/slack_connector.pyi +0 -0
  29. {strideutils-0.3.6 → strideutils-0.3.7}/strideutils-stubs/stride_alerts.pyi +0 -0
  30. {strideutils-0.3.6 → strideutils-0.3.7}/strideutils-stubs/stride_config.pyi +0 -0
  31. {strideutils-0.3.6 → strideutils-0.3.7}/strideutils-stubs/stride_requests.pyi +0 -0
  32. {strideutils-0.3.6 → strideutils-0.3.7}/strideutils-stubs/stride_upstash.pyi +0 -0
  33. {strideutils-0.3.6 → strideutils-0.3.7}/strideutils-stubs/twilio_connector.pyi +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: strideutils
3
- Version: 0.3.6
3
+ Version: 0.3.7
4
4
  Summary:
5
5
  Author: Your Name
6
6
  Author-email: you@example.com
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "strideutils"
3
- version = "0.3.6"
3
+ version = "0.3.7"
4
4
  description = ""
5
5
  authors = ["Your Name <you@example.com>"]
6
6
  readme = "README.md"
@@ -811,64 +811,67 @@ def generate_vesting_account(
811
811
 
812
812
 
813
813
  def get_block_height_in_past(
814
- time_in_past: datetime.timedelta = datetime.timedelta(hours=24),
815
- max_acceptable_error_seconds: int = 60 * 5,
814
+ target_time: Optional[datetime.datetime] = None,
815
+ target_time_offset: Optional[datetime.timedelta] = None,
816
+ error_tolerance: datetime.timedelta = datetime.timedelta(minutes=5),
816
817
  seconds_per_block: int = 6,
817
- prev_time: Optional[str] = None,
818
- verbose: bool = False,
819
818
  rpc_endpoint: str = config.stride.rpc_endpoint,
820
819
  ) -> int:
821
820
  """
822
821
  Gets the block height at a specified time by binary searching at different heights
823
822
 
824
823
  Args:
825
- time_in_past: target time to search for
826
- max_acceptable_error_seconds: max time delta before the height is considered find
824
+ target_time (datetime): the target time to search for
825
+ (e.g. search for the block at time 2024-01-01 01:00:00 UTC)
826
+ target_time_offset (timedelta): the target time to search for,
827
+ defined as an offset from the current time
828
+ (e.g. search for the block 24 hours ago)
829
+ error_tolerance (timedelta): max time delta before the height is considered found
827
830
  seconds_per_block: block time to use for the estimation start
828
- prev_time: Optional time to start the search at (instead of using time_in_past)
829
831
 
830
832
  Returns:
831
833
  The block height at the specified time
832
834
  """
835
+ # Get the current time and latest block height
836
+ current_time = datetime.datetime.now(tz=datetime.timezone.utc)
833
837
  latest_block = get_latest_block(rpc_endpoint=rpc_endpoint)
834
838
 
835
- # set parameters so we can search for the block height
836
- blocks_per_day = (24 * 60 * 60) // seconds_per_block
837
- if prev_time is not None:
838
- if type(prev_time) is str:
839
- prev_time: datetime.datetime = pd.to_datetime(prev_time) # type: ignore
840
- ts = (datetime.datetime.utcnow() - cast(datetime.datetime, prev_time)).total_seconds()
841
- num_days_back = ts / (60 * 60 * 24)
842
- time_in_past = datetime.timedelta(seconds=ts)
839
+ # Depending on whether the target time or target_time_offset was used,
840
+ # calculate the parameter that was not provided
841
+ if target_time and not target_time_offset:
842
+ target_time_offset = current_time - target_time
843
+ elif target_time_offset and not target_time:
844
+ target_time = current_time - target_time_offset
843
845
  else:
844
- num_days_back = time_in_past.total_seconds() / (60 * 60 * 24)
845
- blocks_in_past = int(num_days_back * blocks_per_day)
846
- time_estimate_error = float(100000)
847
-
848
- current_time = datetime.datetime.utcnow()
849
-
850
- # do an iterative search to find the block
851
- while abs(time_estimate_error) > max_acceptable_error_seconds:
852
- backwards_looking_height = latest_block - blocks_in_past
853
- backwards_looking_time = get_block_time(backwards_looking_height, rpc_endpoint=rpc_endpoint)
854
- time_estimate_error = (current_time - backwards_looking_time - time_in_past).total_seconds()
855
- error_in_blocks = time_estimate_error / seconds_per_block
856
- blocks_in_past -= int(error_in_blocks)
857
- if verbose:
858
- print("\tEstimated block: {}".format(backwards_looking_height))
859
- print("\tEstimated time: {}".format(backwards_looking_time))
860
- print("\tError in blocks: {}".format(error_in_blocks))
861
- print("\tTotal Seconds: {}".format(time_estimate_error))
862
- print("\t-------------------------")
863
- block_last_day = latest_block - blocks_in_past
864
- return block_last_day
865
-
866
-
867
- def get_block_height_one_day_ago(verbose: bool = False) -> int:
846
+ raise ValueError("Either target time or target time offset must be specified (but not both)")
847
+
848
+ # Using the target offset, determine the block delta to start our search, based
849
+ # on the estimated block time
850
+ blocks_in_past = int(target_time_offset.total_seconds() / seconds_per_block)
851
+ estimated_height = latest_block - blocks_in_past
852
+
853
+ # Continually loop over the following until we find a block that lines up with
854
+ # our target time (within our margin of error)
855
+ # - Guess a height
856
+ # - Find the time at that height
857
+ # - Check if the time is close enough to our target
858
+ # - Refine our block height guess and repeat
859
+ while True:
860
+ estimated_time = get_block_time(estimated_height, rpc_endpoint=rpc_endpoint)
861
+
862
+ time_error = target_time.timestamp() - estimated_time.timestamp()
863
+ if abs(time_error) < error_tolerance.total_seconds():
864
+ return estimated_height
865
+
866
+ blocks_correction = int(time_error / seconds_per_block)
867
+ estimated_height += blocks_correction
868
+
869
+
870
+ def get_block_height_one_day_ago() -> int:
868
871
  """
869
872
  Get the block height from 1 day ago
870
873
  """
871
- return get_block_height_in_past(datetime.timedelta(hours=24), verbose=verbose)
874
+ return get_block_height_in_past(target_time_offset=datetime.timedelta(hours=24))
872
875
 
873
876
 
874
877
  def get_sttoken_apr(token: str) -> Optional[float]:
File without changes