Substrate currently has a powerful metadata system that provides a lot of information about modules in a runtime. However it does not includes all the necessary information for the SDK to correctly interact with the runtime. Those information currently needs to be distributed off-chain and out-out-sync information will cause hard to diagnostic bugs and potentially cause security issues. It also increase maintenance burden as any change of the types that exposed in metadata will become backward incompatible change and requires SDK and all the dApps to be upgraded.
Ink! is currently able to generate ABI file which includes metadata out the contract and contains a limited set of the type information. However currently adding new types are non-trivial and need to be done on both ink! side and polkadot.js side. It also has some of the issues Substrate metadata having, such as shared namespace for all type names and not able to handle generic types properly.
Have a unified way to represent type information and able to consume it in SDKs. This information can have two representations: Human readable JSON format, or compact binary format (using SCALE codec). The human readable one can includes document comments in the source code and intended to be distributed off-chain. The compact binary format should only store the only absolute minimal necessary information to represent a type and intended to be able to stored on-chain efficiently.
Issue: https://github.com/paritytech/substrate/issues/917
Substrate PoC:
ink: https://github.com/paritytech/ink/pull/104
New crate meta-type
(please suggest a better name) which is based on the PoC substrate-metadata crate. It proves a way to represent Rust type information (and possibly a super-set of be language agnostic) and able to serialized the representation into JSON (via optional serde feature) or SCALE (via optional parity-codec feature).
New crate meta-type-derive
which is based on the PoC substrate-metadata-derive create. It proves Rust macro MetaType
(name suggestion?) to derive the implementation to generate type information for meta-type
.
Ink! will be refactored to use meta-type
to generate the type information part of the ABI file.
New create substrate-codec
that offers Encode
and Decode
derive macro which generates both parity_codec::{Encode, Decode}
and meta-type::MetaType
implementation. This should minimized the code change on Substrate.
New metadata version is required to include all the necessary type information.
@polkadot/types add support of parsing type information generated by meta-type
and generate the Codec
confirming types at runtime.
Optionally generate .d.ts
file at built time to offer better IDE support and compile time check.
Then this can be used by both Substrate metadata handling and Smart Contract SDK generation.
General representation of a type in an language agnostic way
String[]
for better nested namespace support?IdentKind
TypeDefinition
s of all the types. This is needed to to avoid circular dependency and duplicate type definitionstypes: BTreeMap<TypeIdentifier, TypeDefinition>
fn register(&mut self, type_id: TypeIdentifier, f: Fn(& mut TypeRegistry) -> TypeDefinition)
type_id
is already registeredField[]
, where Field
is a struct with:
name
: name of the field, a FieldName
enum:
FieldName::Unnamed(u16)
FieldName::Named(String)
ident
: TypeIdentifier
of the fieldVariant[]
, where Variant
is a struct with:
name
: name of this variant.index
: index of this variant.fields
: associated data, which is a Field[]
.The default JSON format generated by serde-json should be enough?
This should be guarded via feature flag so we can disable it for Substrate usage.
The default parity-codec may be enough?
It won't be the most compact format, so may need to have custom encode/decode logic.
Have a new set of CompactTypeRegistry
, CompactTypeIndentifier
, CompactTypeDefinition
etc?
This should be guarded via feature flag.
or
or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up
Syntax | Example | Reference | |
---|---|---|---|
# Header | Header | 基本排版 | |
- Unordered List |
|
||
1. Ordered List |
|
||
- [ ] Todo List |
|
||
> Blockquote | Blockquote |
||
**Bold font** | Bold font | ||
*Italics font* | Italics font | ||
~~Strikethrough~~ | |||
19^th^ | 19th | ||
H~2~O | H2O | ||
++Inserted text++ | Inserted text | ||
==Marked text== | Marked text | ||
[link text](https:// "title") | Link | ||
 | Image | ||
`Code` | Code |
在筆記中貼入程式碼 | |
```javascript var i = 0; ``` |
|
||
:smile: | ![]() |
Emoji list | |
{%youtube youtube_id %} | Externals | ||
$L^aT_eX$ | LaTeX | ||
:::info This is a alert area. ::: |
This is a alert area. |
On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?
Please give us some advice and help us improve HackMD.
Do you want to remove this version name and description?
Syncing