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.
- {strideutils-0.3.6 → strideutils-0.3.7}/PKG-INFO +1 -1
- {strideutils-0.3.6 → strideutils-0.3.7}/pyproject.toml +1 -1
- {strideutils-0.3.6 → strideutils-0.3.7}/strideutils/stride_requests.py +43 -40
- {strideutils-0.3.6 → strideutils-0.3.7}/README.md +0 -0
- {strideutils-0.3.6 → strideutils-0.3.7}/strideutils/Makefile +0 -0
- {strideutils-0.3.6 → strideutils-0.3.7}/strideutils/__init__.py +0 -0
- {strideutils-0.3.6 → strideutils-0.3.7}/strideutils/coingecko.py +0 -0
- {strideutils-0.3.6 → strideutils-0.3.7}/strideutils/config_examples/strideutils_config.yaml.example +0 -0
- {strideutils-0.3.6 → strideutils-0.3.7}/strideutils/config_examples/strideutils_secrets.yaml.example +0 -0
- {strideutils-0.3.6 → strideutils-0.3.7}/strideutils/cryptography.py +0 -0
- {strideutils-0.3.6 → strideutils-0.3.7}/strideutils/exec_tx.py +0 -0
- {strideutils-0.3.6 → strideutils-0.3.7}/strideutils/invariant_helpers.py +0 -0
- {strideutils-0.3.6 → strideutils-0.3.7}/strideutils/run_safely.py +0 -0
- {strideutils-0.3.6 → strideutils-0.3.7}/strideutils/sheets_connector.py +0 -0
- {strideutils-0.3.6 → strideutils-0.3.7}/strideutils/slack_connector.py +0 -0
- {strideutils-0.3.6 → strideutils-0.3.7}/strideutils/stride_alerts.py +0 -0
- {strideutils-0.3.6 → strideutils-0.3.7}/strideutils/stride_config.py +0 -0
- {strideutils-0.3.6 → strideutils-0.3.7}/strideutils/stride_upstash.py +0 -0
- {strideutils-0.3.6 → strideutils-0.3.7}/strideutils/twilio_connector.py +0 -0
- {strideutils-0.3.6 → strideutils-0.3.7}/strideutils/types.py +0 -0
- {strideutils-0.3.6 → strideutils-0.3.7}/strideutils-stubs/__init__.pyi +0 -0
- {strideutils-0.3.6 → strideutils-0.3.7}/strideutils-stubs/coingecko.pyi +0 -0
- {strideutils-0.3.6 → strideutils-0.3.7}/strideutils-stubs/cryptography.pyi +0 -0
- {strideutils-0.3.6 → strideutils-0.3.7}/strideutils-stubs/exec_tx.pyi +0 -0
- {strideutils-0.3.6 → strideutils-0.3.7}/strideutils-stubs/invariant_helpers.pyi +0 -0
- {strideutils-0.3.6 → strideutils-0.3.7}/strideutils-stubs/run_safely.pyi +0 -0
- {strideutils-0.3.6 → strideutils-0.3.7}/strideutils-stubs/sheets_connector.pyi +0 -0
- {strideutils-0.3.6 → strideutils-0.3.7}/strideutils-stubs/slack_connector.pyi +0 -0
- {strideutils-0.3.6 → strideutils-0.3.7}/strideutils-stubs/stride_alerts.pyi +0 -0
- {strideutils-0.3.6 → strideutils-0.3.7}/strideutils-stubs/stride_config.pyi +0 -0
- {strideutils-0.3.6 → strideutils-0.3.7}/strideutils-stubs/stride_requests.pyi +0 -0
- {strideutils-0.3.6 → strideutils-0.3.7}/strideutils-stubs/stride_upstash.pyi +0 -0
- {strideutils-0.3.6 → strideutils-0.3.7}/strideutils-stubs/twilio_connector.pyi +0 -0
|
@@ -811,64 +811,67 @@ def generate_vesting_account(
|
|
|
811
811
|
|
|
812
812
|
|
|
813
813
|
def get_block_height_in_past(
|
|
814
|
-
|
|
815
|
-
|
|
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
|
-
|
|
826
|
-
|
|
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
|
-
#
|
|
836
|
-
|
|
837
|
-
if
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
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
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
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)
|
|
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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{strideutils-0.3.6 → strideutils-0.3.7}/strideutils/config_examples/strideutils_config.yaml.example
RENAMED
|
File without changes
|
{strideutils-0.3.6 → strideutils-0.3.7}/strideutils/config_examples/strideutils_secrets.yaml.example
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|