@@ -90,7 +90,7 @@ neurons: List[NeuronInfo] = NeuronInfo.decode_vec(
90
90
```
91
91
92
92
### NeuronInfoLite
93
- #### get_neuron
93
+ #### get_neuron_lite
94
94
``` python
95
95
import bittensor
96
96
from bt_decode import NeuronInfoLite
@@ -247,3 +247,44 @@ subnet_hyper_params: Optional[SubnetHyperparameters] = SubnetHyperparameters.dec
247
247
hex_bytes_result
248
248
))
249
249
```
250
+
251
+ ### decode by type string
252
+ * Note: This feature is unstable, but working for multiple types.*
253
+
254
+ You may also decode using a type-string formed from existing types by passing the metadata as pulled from a node (or formed manually).
255
+ ``` python
256
+ import bittensor, bt_decode, scalecodec
257
+ # Get subtensor connection
258
+ sub = bittensor.subtensor()
259
+ # Create a param for the RPC call, using v15 metadata
260
+ v15_int = scalecodec.U32()
261
+ v15_int.value = 15
262
+ # Make the RPC call to grab the metadata
263
+ metadata_rpc_result = sub.substrate.rpc_request(" state_call" , [
264
+ " Metadata_metadata_at_version" ,
265
+ v15_int.encode().to_hex(),
266
+ sub.substrate.get_chain_finalised_head()
267
+ ])
268
+ # Decode the metadata into a PortableRegistry type
269
+ metadata_option_hex_str = metadata_rpc_result[' result' ]
270
+ metadata_option_bytes = bytes .fromhex(metadata_option_hex_str[2 :])
271
+ metadata_v15 = bt_decode.MetadataV15.decode_from_metadata_option(metadata_option_bytes)
272
+ registry = bt_decode.PortableRegistry.from_metadata_v15( metadata_v15 )
273
+
274
+ # Decode by type-string
275
+ NETUID = 1
276
+ # # Grab result from RuntimeAPI
277
+ hex_bytes_result = sub.query_runtime_api(
278
+ runtime_api = " NeuronInfoRuntimeApi" ,
279
+ method = " get_neurons_lite" ,
280
+ params = [NETUID ]
281
+ )
282
+ # # Decode scale-encoded NeuronInfoLite by type-string
283
+ neurons_lite: List[NeuronInfoLite] = bt_decode.decode(
284
+ " Vec<NeuronInfoLite>" , # type-string
285
+ registry, # registry as above
286
+ bytes .fromhex(
287
+ hex_bytes_result # bytes to decode
288
+ )
289
+ )
290
+ ```
0 commit comments