Background
- Iroha 2 peer receive messages from it clients primarily serialized in SCALE codec, but also some endpoint receive JSON messages
- Iroha 2 has some client libraries in development (Java/Kotlin, JavaScript, Python)
- Scale codec do not need the name of the properties, but JSON do need
Problem
Iroha 2 has a lot of model-objects that peer can receive as input from blockchain clients and can respond with. Currently Iroha 2 in the active development process and set of this model-objects changes very often. These changes must be reflected in the Iroha 2 client's library and it requires a lot of affords to keep client's implementation up to date.
Solution
We can generate a scheme which would introspect details of object-models. The scheme brings such benefits:
- Code generation of models and serialization/deserialization tests
- Type safe checks in clients code (if programming language support type safety)
Requirements for scheme
Basically we can consider 3 types of items
1. Scalars
- int: in SCALE can be encoded as fixed-width integer and compact integer. Compact integer itself has 3 modes. So generally we have 4 ways to serde integer (1 fixed-width + 3 modes of compact integers)
{
"type": "int",
"mode": "CompactTwoByte" //possible values FixedWidth, CompactSingleByte, CompactTwoByte, CompactFourByte, CompactBigInteger,
} - bool: no tricks here
{
"type": "bool"
}
2. Built-in containers
- Option / Result / Vec / typle / array : basically we are interested in only inner values of the container
3. Custom containers
- Structures
- Enums: similar to Structures but also every variant of enum has a discriminator that used in Scale. By default based on 0, but can be overriden by attributes
Alternatives
Present at least two alternatives to the solution you suggested
Concerns
Write down all the things that worry you or other stakeholders
Assumptions
Document any assumption that you made
Risks
List all risks in form "description \[probability (from 0 to 9); impact (from 0 to 9)\]"
Additional Information
- Scale codec description in Substrate docs [https://substrate.dev/docs/en/knowledgebase/advanced/codec]
- Scale codec Github page [https://github.com/paritytech/parity-scale-codec]