@@ -24,9 +24,11 @@ class SubtensorApi:
24
24
Arguments:
25
25
network: The network to connect to. Defaults to `None` -> `finney`.
26
26
config: Bittensor configuration object. Defaults to `None`.
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
27
legacy_methods: If `True`, all methods from the Subtensor class will be added to the root level of this class.
28
+ fallback_chains (list): List of fallback chains to use if no network is specified. Defaults to `None`.
29
+ retry_forever (bool): Whether to retry forever on connection errors. Defaults to `False`.
30
+ log_verbose (bool): Enables or disables verbose logging.
31
+ mock: Whether this is a mock instance. Mainly just for use in testing.
30
32
31
33
Example:
32
34
# sync version
@@ -57,16 +59,21 @@ def __init__(
57
59
self ,
58
60
network : Optional [str ] = None ,
59
61
config : Optional ["Config" ] = None ,
60
- log_verbose : bool = False ,
61
62
async_subtensor : bool = False ,
62
63
legacy_methods : bool = False ,
63
- _mock : bool = False ,
64
+ fallback_chains : Optional [list [str ]] = None ,
65
+ retry_forever : bool = False ,
66
+ log_verbose : bool = False ,
67
+ mock : bool = False ,
64
68
):
65
69
self .network = network
66
- self ._mock = _mock
70
+ self ._fallback_chains = fallback_chains
71
+ self ._retry_forever = retry_forever
72
+ self ._mock = mock
67
73
self .log_verbose = log_verbose
68
74
self .is_async = async_subtensor
69
75
self ._config = config
76
+
70
77
# assigned only for async instance
71
78
self .initialize = None
72
79
self ._subtensor = self ._get_subtensor ()
@@ -99,21 +106,29 @@ def _get_subtensor(self) -> Union["_Subtensor", "_AsyncSubtensor"]:
99
106
_subtensor = _AsyncSubtensor (
100
107
network = self .network ,
101
108
config = self ._config ,
102
- _mock = self ._mock ,
103
109
log_verbose = self .log_verbose ,
110
+ fallback_chains = self ._fallback_chains ,
111
+ retry_forever = self ._retry_forever ,
112
+ _mock = self ._mock ,
104
113
)
105
114
self .initialize = _subtensor .initialize
106
115
return _subtensor
107
116
else :
108
117
return _Subtensor (
109
118
network = self .network ,
110
119
config = self ._config ,
111
- _mock = self ._mock ,
112
120
log_verbose = self .log_verbose ,
121
+ fallback_chains = self ._fallback_chains ,
122
+ retry_forever = self ._retry_forever ,
123
+ _mock = self ._mock ,
113
124
)
114
125
115
126
def __str__ (self ):
116
- return f"<Network: { self .network } , Chain: { self .chain_endpoint } , { 'Async version' if self .is_async else 'Sync version' } >"
127
+ return (
128
+ f"<Network: { self .network } , "
129
+ f"Chain: { self ._determine_chain_endpoint ()} , "
130
+ f"{ 'Async version' if self .is_async else 'Sync version' } >"
131
+ )
117
132
118
133
def __repr__ (self ):
119
134
return self .__str__ ()
@@ -130,50 +145,68 @@ async def __aenter__(self):
130
145
async def __aexit__ (self , exc_type , exc_val , exc_tb ):
131
146
await self .substrate .close ()
132
147
148
+ def _determine_chain_endpoint (self ) -> str :
149
+ """Determines the connection and mock flag."""
150
+ if self ._mock :
151
+ return "Mock"
152
+ return self .substrate .url
153
+
133
154
@property
134
155
def block (self ):
156
+ """Returns current chain block number."""
135
157
return self ._subtensor .block
136
158
137
159
@property
138
160
def chain (self ):
161
+ """Property to access chain methods."""
139
162
return _Chain (self ._subtensor )
140
163
141
164
@property
142
165
def commitments (self ):
166
+ """Property to access commitments methods."""
143
167
return _Commitments (self ._subtensor )
144
168
145
169
@property
146
170
def delegates (self ):
171
+ """Property to access delegates methods."""
147
172
return _Delegates (self ._subtensor )
148
173
149
174
@property
150
175
def extrinsics (self ):
176
+ """Property to access extrinsics methods."""
151
177
return _Extrinsics (self ._subtensor )
152
178
153
179
@property
154
180
def metagraphs (self ):
181
+ """Property to access metagraphs methods."""
155
182
return _Metagraphs (self ._subtensor )
156
183
157
184
@property
158
185
def neurons (self ):
186
+ """Property to access neurons methods."""
159
187
return self ._neurons
160
188
161
189
@neurons .setter
162
190
def neurons (self , value ):
191
+ """Setter for neurons property."""
163
192
self ._neurons = value
164
193
165
194
@property
166
195
def queries (self ):
196
+ """Property to access queries methods."""
167
197
return _Queries (self ._subtensor )
168
198
169
199
@property
170
200
def stakes (self ):
201
+ """Property to access stakes methods."""
171
202
return _Stakes (self ._subtensor )
172
203
173
204
@property
174
205
def subnets (self ):
206
+ """Property to access subnets methods."""
175
207
return _Subnets (self ._subtensor )
176
208
177
209
@property
178
210
def wallets (self ):
211
+ """Property to access wallets methods."""
179
212
return _Wallets (self ._subtensor )
0 commit comments