Skip to content

Commit 7c1aa79

Browse files
authored
Pre-release of 0.2.0 (#3)
* update build CI * [feat] Add metadata v15 class (#1) * add metadata v15 class and example in docstring * fix docstring * serde full * add portable registry * add registry from metadata directly * add clone * add clone to metadata * Feat/decode by type string (#2) * add decoding well-known types (i.e. in the type registry) * not well-known types work for arr, tup?, vec * add compact; fix primitive load * bump edition * add scale info type string format * add tests * fix primitives (char not in registry) * check length first * handle variants better * handle options * bump version * fix options * fix tests * fix option parsing to return None or val * add more tests * use prerelease
1 parent 1d09e0b commit 7c1aa79

File tree

9 files changed

+24410
-21
lines changed

9 files changed

+24410
-21
lines changed

.github/workflows/CI.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,14 @@
33
#
44
# maturin generate-ci github
55
#
6-
name: CI
6+
name: Build wheels
77

88
on:
99
push:
1010
branches:
1111
- main
1212
tags:
1313
- '*'
14-
pull_request:
1514
workflow_dispatch:
1615

1716
permissions:

Cargo.lock

Lines changed: 113 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "bt_decode"
33
version = "0.0.1"
4-
edition = "2018"
4+
edition = "2021"
55

66
[lib]
77
name = "bt_decode"
@@ -20,10 +20,13 @@ features = ["extension-module"]
2020
path = "libs/custom-derive"
2121

2222
[dependencies]
23-
frame-metadata = { version = "16.0.0", features = [ "current", "decode" ], default-features = false }
23+
frame-metadata = { version = "16.0.0", features = [ "current", "decode", "serde_full" ], default-features = false }
2424
scale-decode = { version = "0.13.0", default-features = false }
2525

2626
codec = { package = "parity-scale-codec", version = "3.2.2", default-features = false, features = [
2727
"derive",
2828
] }
29-
scale-info = { version = "2.11.2", default-features = false }
29+
scale-info = { version = "2.11.2", features = [ "serde" ], default-features = false }
30+
serde_json = { version = "1.0.127", features = [ "alloc" ], default-features = false }
31+
scale-bits = { version = "0.4.0", default-features = false }
32+
scale-value = { version = "0.16.2", default-features = false }

bt_decode.pyi

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import List, Optional, Tuple
1+
from typing import Any, List, Optional, Tuple
22

33
class AxonInfo:
44
# Axon serving block.
@@ -218,3 +218,69 @@ class DelegateInfo:
218218
@staticmethod
219219
def decode_delegated(encoded: bytes) -> List[Tuple["DelegateInfo", int]]:
220220
pass
221+
222+
class MetadataV15:
223+
"""
224+
MetadataV15 is the 15th version-style of metadata for the chain.
225+
It contains information about all the chain types, including the type signatures
226+
of the Runtime API functions.
227+
228+
Example:
229+
>>> import bittensor, bt_decode, scalecodec
230+
>>> sub = bittensor.subtensor()
231+
>>> v15_int = scalecodec.U32()
232+
>>> v15_int.value = 15
233+
>>> metadata_rpc_result = sub.substrate.rpc_request("state_call", [
234+
... "Metadata_metadata_at_version",
235+
... v15_int.encode().to_hex(),
236+
... sub.substrate.get_chain_finalised_head()
237+
])
238+
>>> metadata_option_hex_str = metadata_rpc_result['result']
239+
>>> metadata_option_bytes = bytes.fromhex(metadata_option_hex_str[2:])
240+
>>> metadata_v15 = bt_decode.MetadataV15.decode_from_metadata_option(metadata_option_bytes)
241+
>>> print(metadata_v15.to_json())
242+
"""
243+
244+
@staticmethod
245+
def decode_from_metadata_option(encoded_metadata_v15: bytes) -> "MetadataV15":
246+
pass
247+
def to_json(self) -> str:
248+
"""
249+
Returns a JSON representation of the metadata.
250+
"""
251+
pass
252+
253+
class PortableRegistry:
254+
"""
255+
PortableRegistry is a portable for of the chains registry that
256+
can be used to serialize and deserialize the registry to and from JSON.
257+
258+
Example:
259+
>>> import bittensor, bt_decode, scalecodec
260+
>>> sub = bittensor.subtensor()
261+
>>> v15_int = scalecodec.U32()
262+
>>> v15_int.value = 15
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+
>>> metadata_option_hex_str = metadata_rpc_result['result']
269+
>>> metadata_option_bytes = bytes.fromhex(metadata_option_hex_str[2:])
270+
>>> metadata_v15 = bt_decode.MetadataV15.decode_from_metadata_option(metadata_option_bytes)
271+
>>> bt_decode.PortableRegistry.from_metadata_v15( metadata_v15 )
272+
"""
273+
274+
registry: str # JSON encoded PortableRegistry
275+
276+
@staticmethod
277+
def from_json(json_str: str) -> "PortableRegistry":
278+
pass
279+
@staticmethod
280+
def from_metadata_v15(metadata_v15: MetadataV15) -> "PortableRegistry":
281+
pass
282+
283+
def decode(
284+
type_string: str, portable_registry: PortableRegistry, encoded: bytes
285+
) -> Any:
286+
pass

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "bt-decode"
3-
version = "0.0.1a"
3+
version = "0.2.0a"
44
description = "A wrapper around the scale-codec crate for fast scale-decoding of Bittensor data structures."
55
readme = "README.md"
66
license = {file = "LICENSE"}

0 commit comments

Comments
 (0)