6
6
from .commitments import Commitments as _Commitments
7
7
from .delegates import Delegates as _Delegates
8
8
from .extrinsics import Extrinsics as _Extrinsics
9
- from .metagraph import Metagraphs as _Metagraphs
9
+ from .metagraphs import Metagraphs as _Metagraphs
10
10
from .neurons import Neurons as _Neurons
11
11
from .queries import Queries as _Queries
12
12
from .stakes import Stakes as _Stakes
13
- from .subnet import Subnet as _Subnet
14
- from .wallet import Wallet as _Wallet
13
+ from .subnets import Subnets as _Subnets
14
+ from .utils import add_classic_fields as _add_classic_fields
15
+ from .wallets import Wallets as _Wallets
15
16
16
17
if TYPE_CHECKING :
17
18
from bittensor .core .config import Config
@@ -23,8 +24,9 @@ class SubtensorApi:
23
24
Arguments:
24
25
network: The network to connect to. Defaults to `None` -> `finney`.
25
26
config: Bittensor configuration object. Defaults to `None`.
26
- log_verbose: If true, sets the subtensor to log verbosely. Defaults to `False`.
27
- async_subtensor: If true, uses the async subtensor to create the connection. Defaults to `False`.
27
+ log_verbose: If `True`, sets the subtensor to log verbosely. Defaults to `False`.
28
+ async_subtensor: If `True`, uses the async subtensor to create the connection. Defaults to `False`.
29
+ subtensor_fields: If `True`, all methods from the Subtensor class will be added to the root level of this class.
28
30
29
31
Example:
30
32
# sync version
@@ -43,6 +45,12 @@ class SubtensorApi:
43
45
print(await subtensor.block)
44
46
print(await subtensor.delegates.get_delegate_identities())
45
47
print(await subtensor.chain.tx_rate_limit())
48
+
49
+ # using `subtensor_fields`
50
+ import bittensor as bt
51
+
52
+ subtensor = bt.SubtensorApi(subtensor_fields=True)
53
+ print(subtensor.bonds(0))
46
54
"""
47
55
48
56
def __init__ (
@@ -51,6 +59,7 @@ def __init__(
51
59
config : Optional ["Config" ] = None ,
52
60
log_verbose : bool = False ,
53
61
async_subtensor : bool = False ,
62
+ subtensor_fields : bool = False ,
54
63
_mock : bool = False ,
55
64
):
56
65
self .network = network
@@ -60,6 +69,9 @@ def __init__(
60
69
self ._config = config
61
70
self ._subtensor = self ._get_subtensor ()
62
71
72
+ # fix naming collision
73
+ self ._neurons = _Neurons (self ._subtensor )
74
+
63
75
# define empty fields
64
76
self .substrate = self ._subtensor .substrate
65
77
self .add_args = self ._subtensor .add_args
@@ -74,6 +86,8 @@ def __init__(
74
86
self .sign_and_send_extrinsic = self ._subtensor .sign_and_send_extrinsic
75
87
self .start_call = self ._subtensor .start_call
76
88
self .wait_for_block = self ._subtensor .wait_for_block
89
+ if subtensor_fields :
90
+ _add_classic_fields (self )
77
91
78
92
def _get_subtensor (self ) -> Union ["_Subtensor" , "_AsyncSubtensor" ]:
79
93
"""Returns the subtensor instance based on the provided config and subtensor type flag."""
@@ -136,7 +150,11 @@ def metagraphs(self):
136
150
137
151
@property
138
152
def neurons (self ):
139
- return _Neurons (self ._subtensor )
153
+ return self ._neurons
154
+
155
+ @neurons .setter
156
+ def neurons (self , value ):
157
+ self ._neurons = value
140
158
141
159
@property
142
160
def queries (self ):
@@ -147,9 +165,9 @@ def stakes(self):
147
165
return _Stakes (self ._subtensor )
148
166
149
167
@property
150
- def subnet (self ):
151
- return _Subnet (self ._subtensor )
168
+ def subnets (self ):
169
+ return _Subnets (self ._subtensor )
152
170
153
171
@property
154
- def wallet (self ):
155
- return _Wallet (self ._subtensor )
172
+ def wallets (self ):
173
+ return _Wallets (self ._subtensor )
0 commit comments