Skip to content

Commit d7bc745

Browse files
committed
Ruff
1 parent 3eaae9f commit d7bc745

File tree

3 files changed

+46
-26
lines changed

3 files changed

+46
-26
lines changed

bittensor/core/async_subtensor.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
from bittensor.utils.btlogging import logging
6161
from bittensor.utils.delegates_details import DelegatesDetails
6262
from bittensor.utils.weight_utils import generate_weight_hash
63-
from bittensor.core.metagraph import AsyncMetagraph
63+
from bittensor.core.metagraph import Metagraph
6464

6565
if TYPE_CHECKING:
6666
from scalecodec import ScaleType
@@ -133,7 +133,7 @@ def __init__(self, network: str = DEFAULT_NETWORK) -> None:
133133
self.network = DEFAULTS.subtensor.network
134134

135135
self.substrate = AsyncSubstrateInterface(
136-
chain_endpoint=self.chain_endpoint,
136+
url=self.chain_endpoint,
137137
ss58_format=SS58_FORMAT,
138138
type_registry=TYPE_REGISTRY,
139139
use_remote_preset=True,
@@ -2471,7 +2471,7 @@ async def block(self) -> int:
24712471

24722472
async def metagraph(
24732473
self, netuid: int, lite: bool = True, block: Optional[int] = None
2474-
) -> AsyncMetagraph:
2474+
) -> Metagraph:
24752475
"""
24762476
Returns a synced metagraph for a specified subnet within the Bittensor network. The metagraph represents the
24772477
network's structure, including neuron connections and interactions.
@@ -2487,7 +2487,7 @@ async def metagraph(
24872487
The metagraph is an essential tool for understanding the topology and dynamics of the Bittensor network's
24882488
decentralized architecture, particularly in relation to neuron interconnectivity and consensus processes.
24892489
"""
2490-
metagraph = AsyncMetagraph(
2490+
metagraph = Metagraph(
24912491
network=self.chain_endpoint,
24922492
netuid=netuid,
24932493
lite=lite,

bittensor/core/subtensor.py

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,6 @@ def add_args(cls, parser: "argparse.ArgumentParser", prefix: Optional[str] = Non
413413
pass
414414

415415
# Inner private functions
416-
@networking.ensure_connected
417416
def _encode_params(
418417
self,
419418
call_definition: dict[str, list["ParamWithTypes"]],
@@ -458,7 +457,7 @@ def _get_hyperparameter(
458457
return result.value
459458

460459
# Chain calls methods ==============================================================================================
461-
@networking.ensure_connected
460+
462461
def query_subtensor(
463462
self, name: str, block: Optional[int] = None, params: Optional[list] = None
464463
) -> "ScaleType":
@@ -485,7 +484,6 @@ def query_subtensor(
485484
),
486485
)
487486

488-
@networking.ensure_connected
489487
def query_map_subtensor(
490488
self, name: str, block: Optional[int] = None, params: Optional[list] = None
491489
) -> "QueryMapResult":
@@ -561,7 +559,6 @@ def query_runtime_api(
561559

562560
return obj.decode()
563561

564-
@networking.ensure_connected
565562
def state_call(
566563
self, method: str, data: str, block: Optional[int] = None
567564
) -> dict[Any, Any]:
@@ -584,7 +581,6 @@ def state_call(
584581
params=[method, data, block_hash] if block_hash else [method, data],
585582
)
586583

587-
@networking.ensure_connected
588584
def query_map(
589585
self,
590586
module: str,
@@ -615,7 +611,6 @@ def query_map(
615611
),
616612
)
617613

618-
@networking.ensure_connected
619614
def query_constant(
620615
self, module_name: str, constant_name: str, block: Optional[int] = None
621616
) -> Optional["ScaleType"]:
@@ -640,7 +635,6 @@ def query_constant(
640635
),
641636
)
642637

643-
@networking.ensure_connected
644638
def query_module(
645639
self,
646640
module: str,
@@ -671,7 +665,6 @@ def query_module(
671665
),
672666
)
673667

674-
@networking.ensure_connected
675668
def get_account_next_index(self, address: str) -> int:
676669
"""
677670
Returns the next nonce for an account, taking into account the transaction pool.
@@ -767,7 +760,6 @@ def get_netuids_for_hotkey(
767760
else []
768761
)
769762

770-
@networking.ensure_connected
771763
def get_current_block(self) -> int:
772764
"""
773765
Returns the current block number on the Bittensor blockchain. This function provides the latest block number, indicating the most recent state of the blockchain.
@@ -862,7 +854,6 @@ def blocks_since_last_update(self, netuid: int, uid: int) -> Optional[int]:
862854
call = self._get_hyperparameter(param_name="LastUpdate", netuid=netuid)
863855
return None if call is None else self.get_current_block() - int(call[uid])
864856

865-
@networking.ensure_connected
866857
def get_block_hash(self, block_id: int) -> str:
867858
"""
868859
Retrieves the hash of a specific block on the Bittensor blockchain. The block hash is a unique identifier representing the cryptographic hash of the block's content, ensuring its integrity and immutability.
@@ -974,7 +965,6 @@ def get_neuron_certificate(
974965
return None
975966
return None
976967

977-
@networking.ensure_connected
978968
def neuron_for_uid(
979969
self, uid: int, netuid: int, block: Optional[int] = None
980970
) -> "NeuronInfo":
@@ -1216,7 +1206,6 @@ def subnet_exists(self, netuid: int, block: Optional[int] = None) -> bool:
12161206
_result = self.query_subtensor("NetworksAdded", block, [netuid])
12171207
return getattr(_result, "value", False)
12181208

1219-
@networking.ensure_connected
12201209
def get_all_subnets_info(self, block: Optional[int] = None) -> list[SubnetInfo]:
12211210
"""
12221211
Retrieves detailed information about all subnets within the Bittensor network. This function provides comprehensive data on each subnet, including its characteristics and operational parameters.
@@ -1471,7 +1460,6 @@ def weights(
14711460

14721461
return w_map
14731462

1474-
@networking.ensure_connected
14751463
def get_balance(self, address: str, block: Optional[int] = None) -> "Balance":
14761464
"""
14771465
Retrieves the token balance of a specific address within the Bittensor network. This function queries the blockchain to determine the amount of Tao held by a given account.
@@ -1503,7 +1491,6 @@ def get_balance(self, address: str, block: Optional[int] = None) -> "Balance":
15031491

15041492
return Balance(result.value["data"]["free"])
15051493

1506-
@networking.ensure_connected
15071494
def get_transfer_fee(
15081495
self, wallet: "Wallet", dest: str, value: Union["Balance", float, int]
15091496
) -> "Balance":
@@ -1633,7 +1620,6 @@ def get_delegate_take(
16331620
else u16_normalized_float(_result.value)
16341621
)
16351622

1636-
@networking.ensure_connected
16371623
def get_delegate_by_hotkey(
16381624
self, hotkey_ss58: str, block: Optional[int] = None
16391625
) -> Optional[DelegateInfo]:
@@ -1723,7 +1709,6 @@ def get_hotkey_owner(
17231709
else result.value
17241710
)
17251711

1726-
@networking.ensure_connected
17271712
def get_minimum_required_stake(
17281713
self,
17291714
) -> Balance:
@@ -1760,7 +1745,6 @@ def tx_rate_limit(self, block: Optional[int] = None) -> Optional[int]:
17601745
result = self.query_subtensor("TxRateLimit", block)
17611746
return getattr(result, "value", None)
17621747

1763-
@networking.ensure_connected
17641748
def get_delegates(self, block: Optional[int] = None) -> list[DelegateInfo]:
17651749
"""
17661750
Retrieves a list of all delegate neurons within the Bittensor network. This function provides an overview of the neurons that are actively involved in the network's delegation system.

bittensor/utils/substrate_interface.py

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -894,7 +894,7 @@ class AsyncSubstrateInterface:
894894

895895
def __init__(
896896
self,
897-
chain_endpoint: str,
897+
url: str,
898898
use_remote_preset: bool = False,
899899
auto_discover: bool = True,
900900
ss58_format: Optional[int] = None,
@@ -910,7 +910,7 @@ def __init__(
910910
Otherwise, some (most) methods will not work properly, and may raise exceptions.
911911
912912
Args:
913-
chain_endpoint: the URI of the chain to connect to
913+
url: the URI of the chain to connect to
914914
use_remote_preset: whether to pull the preset from GitHub
915915
auto_discover: whether to automatically pull the presets based on the chain name and type registry
916916
ss58_format: the specific SS58 format to use
@@ -923,10 +923,11 @@ def __init__(
923923
"""
924924
self.max_retries = max_retries
925925
self.retry_timeout = retry_timeout
926-
self.chain_endpoint = chain_endpoint
926+
self.chain_endpoint = url
927+
self.url = url
927928
self.__chain = chain_name
928929
self.ws = Websocket(
929-
chain_endpoint,
930+
url,
930931
options={
931932
"max_size": 2**32,
932933
"write_limit": 2**16,
@@ -3865,7 +3866,7 @@ def __init__(
38653866
mock: bool = False,
38663867
):
38673868
self._async_instance = AsyncSubstrateInterface(
3868-
chain_endpoint=chain_endpoint,
3869+
url=chain_endpoint,
38693870
use_remote_preset=use_remote_preset,
38703871
auto_discover=auto_discover,
38713872
ss58_format=ss58_format,
@@ -3896,3 +3897,38 @@ def sync_method(*args, **kwargs):
38963897
return self.event_loop.run_until_complete(attr)
38973898
else:
38983899
return attr
3900+
3901+
def query(
3902+
self,
3903+
module: str,
3904+
storage_function: str,
3905+
params: Optional[list] = None,
3906+
block_hash: Optional[str] = None,
3907+
raw_storage_key: Optional[bytes] = None,
3908+
subscription_handler=None,
3909+
reuse_block_hash: bool = False,
3910+
) -> "ScaleType":
3911+
return self.event_loop.run_until_complete(
3912+
self._async_instance.query(
3913+
module,
3914+
storage_function,
3915+
params,
3916+
block_hash,
3917+
raw_storage_key,
3918+
subscription_handler,
3919+
reuse_block_hash,
3920+
)
3921+
)
3922+
3923+
def get_constant(
3924+
self,
3925+
module_name: str,
3926+
constant_name: str,
3927+
block_hash: Optional[str] = None,
3928+
reuse_block_hash: bool = False,
3929+
) -> Optional["ScaleType"]:
3930+
return self.event_loop.run_until_complete(
3931+
self._async_instance.get_constant(
3932+
module_name, constant_name, block_hash, reuse_block_hash
3933+
)
3934+
)

0 commit comments

Comments
 (0)