|
1 | 1 | import asyncio |
2 | 2 | import copy |
| 3 | +from datetime import datetime, timezone |
3 | 4 | import ssl |
4 | 5 | from functools import partial |
5 | 6 | from typing import Optional, Any, Union, Iterable, TYPE_CHECKING |
|
27 | 28 | decode_account_id, |
28 | 29 | DynamicInfo, |
29 | 30 | ) |
| 31 | +from bittensor.core.chain_data.delegate_info import DelegatedInfo |
30 | 32 | from bittensor.core.chain_data.utils import decode_metadata |
31 | 33 | from bittensor.core.config import Config |
32 | 34 | from bittensor.core.errors import SubstrateRequestException |
@@ -999,7 +1001,7 @@ async def get_all_commitments( |
999 | 1001 | ) |
1000 | 1002 | result = {} |
1001 | 1003 | async for id_, value in query: |
1002 | | - result[decode_account_id(id_[0])] = decode_account_id(value) |
| 1004 | + result[decode_account_id(id_[0])] = decode_metadata(value) |
1003 | 1005 | return result |
1004 | 1006 |
|
1005 | 1007 | async def get_current_weight_commit_info( |
@@ -1219,7 +1221,7 @@ async def get_delegated( |
1219 | 1221 | if not result: |
1220 | 1222 | return [] |
1221 | 1223 |
|
1222 | | - return DelegateInfo.delegated_list_from_dicts(result) |
| 1224 | + return DelegatedInfo.list_from_dicts(result) |
1223 | 1225 |
|
1224 | 1226 | async def get_delegates( |
1225 | 1227 | self, |
@@ -2744,6 +2746,36 @@ async def weights_rate_limit( |
2744 | 2746 | ) |
2745 | 2747 | return None if call is None else int(call) |
2746 | 2748 |
|
| 2749 | + async def get_timestamp( |
| 2750 | + self, |
| 2751 | + block: Optional[int] = None, |
| 2752 | + block_hash: Optional[str] = None, |
| 2753 | + reuse_block: bool = False, |
| 2754 | + ) -> datetime: |
| 2755 | + """ |
| 2756 | + Retrieves the datetime timestamp for a given block |
| 2757 | +
|
| 2758 | + Arguments: |
| 2759 | + block: The blockchain block number for the query. Do not specify if specifying block_hash or reuse_block. |
| 2760 | + block_hash: The blockchain block_hash representation of the block id. Do not specify if specifying block |
| 2761 | + or reuse_block. |
| 2762 | + reuse_block: Whether to reuse the last-used blockchain block hash. Do not specify if specifying block or |
| 2763 | + block_hash. |
| 2764 | +
|
| 2765 | + Returns: |
| 2766 | + datetime object for the timestamp of the block |
| 2767 | + """ |
| 2768 | + unix = ( |
| 2769 | + await self.query_module( |
| 2770 | + "Timestamp", |
| 2771 | + "Now", |
| 2772 | + block=block, |
| 2773 | + block_hash=block_hash, |
| 2774 | + reuse_block=reuse_block, |
| 2775 | + ) |
| 2776 | + ).value |
| 2777 | + return datetime.fromtimestamp(unix / 1000, tz=timezone.utc) |
| 2778 | + |
2747 | 2779 | # Extrinsics helper ================================================================================================ |
2748 | 2780 |
|
2749 | 2781 | async def sign_and_send_extrinsic( |
|
0 commit comments