-
Notifications
You must be signed in to change notification settings - Fork 1
/
bt_decode.pyi
351 lines (323 loc) · 9.6 KB
/
bt_decode.pyi
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
from typing import Any, Dict, List, Optional, Tuple
class AxonInfo:
# Axon serving block.
block: int
# Axon version
version: int
# Axon u128 encoded ip address of type v6 or v4.
ip: int
# Axon u16 encoded port.
port: int
# Axon ip type, 4 for ipv4 and 6 for ipv6.
ip_type: int
# Axon protocol. TCP, UDP, other.
protocol: int
# Axon proto placeholder 1.
placeholder1: int
# Axon proto placeholder 2.
placeholder2: int
@staticmethod
def decode(encoded: bytes) -> "AxonInfo":
pass
@staticmethod
def decode_option(encoded: bytes) -> Optional["AxonInfo"]:
pass
@staticmethod
def decode_vec(encoded: bytes) -> List["AxonInfo"]:
pass
class PrometheusInfo:
block: int
# Prometheus version.
version: int
# Prometheus u128 encoded ip address of type v6 or v4.
ip: int
# Prometheus u16 encoded port.
port: int
# Prometheus ip type, 4 for ipv4 and 6 for ipv6.
ip_type: int
@staticmethod
def decode(encoded: bytes) -> "PrometheusInfo":
pass
@staticmethod
def decode_option(encoded: bytes) -> Optional["PrometheusInfo"]:
pass
@staticmethod
def decode_vec(encoded: bytes) -> List["PrometheusInfo"]:
pass
class NeuronInfo:
hotkey: bytes
coldkey: bytes
uid: int
netuid: int
active: bool
axon_info: AxonInfo
prometheus_info: PrometheusInfo
stake: List[
Tuple[bytes, int]
] # map of coldkey to stake on this neuron/hotkey (includes delegations)
rank: int
emission: int
incentive: int
consensus: int
trust: int
validator_trust: int
dividends: int
last_update: int
validator_permit: bool
weights: List[Tuple[int, int]] # Vec of (uid, weight)
bonds: List[Tuple[int, int]] # Vec of (uid, bond)
pruning_score: int
@staticmethod
def decode(encoded: bytes) -> "NeuronInfo":
pass
@staticmethod
def decode_option(encoded: bytes) -> Optional["NeuronInfo"]:
pass
@staticmethod
def decode_vec(encoded: bytes) -> List["NeuronInfo"]:
pass
class NeuronInfoLite:
hotkey: bytes
coldkey: bytes
uid: int
netuid: int
active: bool
axon_info: AxonInfo
prometheus_info: PrometheusInfo
stake: List[
Tuple[bytes, int]
] # map of coldkey to stake on this neuron/hotkey (includes delegations)
rank: int
emission: int
incentive: int
consensus: int
trust: int
validator_trust: int
dividends: int
last_update: int
validator_permit: bool
# has no weights or bonds
pruning_score: int
@staticmethod
def decode(encoded: bytes) -> "NeuronInfoLite":
pass
@staticmethod
def decode_option(encoded: bytes) -> Optional["NeuronInfoLite"]:
pass
@staticmethod
def decode_vec(encoded: bytes) -> List["NeuronInfoLite"]:
pass
class SubnetIdentity:
subnet_name: bytes # TODO: or List[int] ??
# The github repository associated with the chain identity
github_repo: bytes
# The subnet's contact
subnet_contact: bytes
@staticmethod
def decode(encoded: bytes) -> "SubnetIdentity":
pass
@staticmethod
def decode_option(encoded: bytes) -> Optional["SubnetIdentity"]:
pass
@staticmethod
def decode_vec(encoded: bytes) -> List["SubnetIdentity"]:
pass
class SubnetInfo:
netuid: int
rho: int
kappa: int
difficulty: int
immunity_period: int
max_allowed_validators: int
min_allowed_weights: int
max_weights_limit: int
scaling_law_power: int
subnetwork_n: int
max_allowed_uids: int
blocks_since_last_step: int
tempo: int
network_modality: int
network_connect: List[List[int]] # List[[int, int]]
emission_values: int
burn: int
owner: bytes
@staticmethod
def decode(encoded: bytes) -> "SubnetInfo":
pass
@staticmethod
def decode_option(encoded: bytes) -> Optional["SubnetInfo"]:
pass
@staticmethod
def decode_vec(encoded: bytes) -> List["SubnetInfo"]:
pass
@staticmethod
def decode_vec_option(encoded: bytes) -> List[Optional["SubnetInfo"]]:
pass
class SubnetInfoV2:
netuid: int
rho: int
kappa: int
difficulty: int
immunity_period: int
max_allowed_validators: int
min_allowed_weights: int
max_weights_limit: int
scaling_law_power: int
subnetwork_n: int
max_allowed_uids: int
blocks_since_last_step: int
tempo: int
network_modality: int
network_connect: List[List[int]] # List[[int, int]]
emission_values: int
burn: int
owner: bytes
identity: Optional[SubnetIdentity]
@staticmethod
def decode(encoded: bytes) -> "SubnetInfoV2":
pass
@staticmethod
def decode_option(encoded: bytes) -> Optional["SubnetInfoV2"]:
pass
@staticmethod
def decode_vec(encoded: bytes) -> List["SubnetInfoV2"]:
pass
@staticmethod
def decode_vec_option(encoded: bytes) -> List[Optional["SubnetInfoV2"]]:
pass
class SubnetHyperparameters:
rho: int
kappa: int
immunity_period: int
min_allowed_weights: int
max_weights_limit: int
tempo: int
min_difficulty: int
max_difficulty: int
weights_version: int
weights_rate_limit: int
adjustment_interval: int
activity_cutoff: int
registration_allowed: bool
target_regs_per_interval: int
min_burn: int
max_burn: int
bonds_moving_avg: int
max_regs_per_block: int
serving_rate_limit: int
max_validators: int
adjustment_alpha: int
difficulty: int
commit_reveal_weights_interval: int
commit_reveal_weights_enabled: bool
alpha_high: int
alpha_low: int
liquid_alpha_enabled: bool
@staticmethod
def decode(encoded: bytes) -> "SubnetHyperparameters":
pass
@staticmethod
def decode_option(encoded: bytes) -> Optional["SubnetHyperparameters"]:
pass
@staticmethod
def decode_vec(encoded: bytes) -> List["SubnetHyperparameters"]:
pass
class StakeInfo:
hotkey: bytes
coldkey: bytes
stake: int
@staticmethod
def decode(encoded: bytes) -> "StakeInfo":
pass
@staticmethod
def decode_option(encoded: bytes) -> Optional["StakeInfo"]:
pass
@staticmethod
def decode_vec(encoded: bytes) -> List["StakeInfo"]:
pass
@staticmethod
def decode_vec_tuple_vec(encoded: bytes) -> List[Tuple[bytes, List["StakeInfo"]]]:
pass
class DelegateInfo:
delegate_ss58: bytes
take: int
nominators: List[Tuple[bytes, int]] # map of nominator_ss58 to stake amount
owner_ss58: bytes
registrations: List[int] # Vec of netuid this delegate is registered on
validator_permits: List[int] # Vec of netuid this delegate has validator permit on
return_per_1000: (
int # Delegators current daily return per 1000 TAO staked minus take fee
)
total_daily_return: int
@staticmethod
def decode(encoded: bytes) -> "DelegateInfo":
pass
@staticmethod
def decode_option(encoded: bytes) -> Optional["DelegateInfo"]:
pass
@staticmethod
def decode_vec(encoded: bytes) -> List["DelegateInfo"]:
pass
@staticmethod
def decode_delegated(encoded: bytes) -> List[Tuple["DelegateInfo", int]]:
pass
class MetadataV15:
"""
MetadataV15 is the 15th version-style of metadata for the chain.
It contains information about all the chain types, including the type signatures
of the Runtime API functions.
Example:
>>> import bittensor, bt_decode, scalecodec
>>> sub = bittensor.subtensor()
>>> v15_int = scalecodec.U32()
>>> v15_int.value = 15
>>> metadata_rpc_result = sub.substrate.rpc_request("state_call", [
... "Metadata_metadata_at_version",
... v15_int.encode().to_hex(),
... sub.substrate.get_chain_finalised_head()
])
>>> metadata_option_hex_str = metadata_rpc_result['result']
>>> metadata_option_bytes = bytes.fromhex(metadata_option_hex_str[2:])
>>> metadata_v15 = bt_decode.MetadataV15.decode_from_metadata_option(metadata_option_bytes)
>>> print(metadata_v15.to_json())
"""
@staticmethod
def decode_from_metadata_option(encoded_metadata_v15: bytes) -> "MetadataV15":
pass
def to_json(self) -> str:
"""
Returns a JSON representation of the metadata.
"""
pass
def value(self) -> Dict[str, Any]:
pass
class PortableRegistry:
"""
PortableRegistry is a portable for of the chains registry that
can be used to serialize and deserialize the registry to and from JSON.
Example:
>>> import bittensor, bt_decode, scalecodec
>>> sub = bittensor.subtensor()
>>> v15_int = scalecodec.U32()
>>> v15_int.value = 15
>>> metadata_rpc_result = sub.substrate.rpc_request("state_call", [
... "Metadata_metadata_at_version",
... v15_int.encode().to_hex(),
... sub.substrate.get_chain_finalised_head()
])
>>> metadata_option_hex_str = metadata_rpc_result['result']
>>> metadata_option_bytes = bytes.fromhex(metadata_option_hex_str[2:])
>>> metadata_v15 = bt_decode.MetadataV15.decode_from_metadata_option(metadata_option_bytes)
>>> bt_decode.PortableRegistry.from_metadata_v15( metadata_v15 )
"""
registry: str # JSON encoded PortableRegistry
@staticmethod
def from_json(json_str: str) -> "PortableRegistry":
pass
@staticmethod
def from_metadata_v15(metadata_v15: MetadataV15) -> "PortableRegistry":
pass
def decode(
type_string: str, portable_registry: PortableRegistry, encoded: bytes
) -> Any:
pass