...
Page properties | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| ||||||||||||||||
|
...
- Iroha 2 peer receive messages from it clients primarily serialized in SCALE codec, but also some endpoint receive accept JSON messages
- Iroha 2 has some client libraries in development (Rust, Java/Kotlin, JavaScript, Python)
- Scale codec do not need the name of the properties and containers, but JSON do need
Problem
...
Basically we can consider 3 types of items
1. Scalars
...
In SCALE integers can be encoded as fixed-width integer and compact integer. Compact integer itself has 4 modes. So generally we have 5 ways to serde integer (1 fixed-width + 4 modes of compact integers)
Code Block | |
---|---|
|
...
| |
{
|
...
"u8": { "Int": " |
...
FixedWidth" }, |
...
"iroha_introspect::Compact<u8>": { "Int": "Compact" } } |
2. Built-in basic types
- bool: no tricks here
- String "CompactTwoByte" //possible values FixedWidth, CompactSingleByte, CompactTwoByte, CompactFourByte, CompactBigInteger, }bool: no tricks here
Code Block | |
---|---|
|
...
| |
{
|
...
"alloc::string::String": "String", "bool": "Bool" } |
23. Built-in containers
Option / Result / Map / Vec / typle : basically we are interested in only inner values of the container
Code Block language js [ { "type": "Option", "item_typecore::option::Option<iroha_data_model::isi::Instruction>": { "typeOption" : "booliroha_data_model::isi::Instruction" } }, { "type"core::result::Result<i32, i32>": "Result",{ "item_typeResult": { "typeok": "inti32", "modeerr": "CompactFourBytei32" } }, { "type": "Vec", "item_type"alloc::collections::BTreeMap<alloc::string::String, i32>": { "typeMap": "bool"{ } }, { "typekey": "tuple", "items": [ { "type": "int", alloc::string::String", "modevalue": "CompactFourBytei32" } }, { "type": "Option", "item_type"alloc::vec::Vec<i32>": { "typeVec" : "booli32" } } ] } ]
34. Custom containers
- Named structures – structures which have field names
- Unnamed structures – structures with no field names (like zero sized structures in rust, or tuples, or struct WrappedTuple(i32, i32))
- Structures: in structures declare definitions inline for built-in types and declare a reference for custom types Enums
Enums: similar to Structures but also every variant of enum has a discriminator that used in Scale. By default based on 0Code Block language bashjs { "typeiroha_crypto::PublicKey": "struct",{ "nameNamedStruct": "Foo",{ "codec": "SCALE", //possible values SCALE or JSON "propertiesdeclarations": [ { "name": "enableddigest_function", //optional name "definitionty": { "type": "bool" } "alloc::string::String" }, { "name": "idpayload", //optional name "definitionty": { "type": "struct", //reference to other struct "alloc::vec::Vec<u8>" } "struct_name": "Id" ] } }, { "nameiroha_data_model::account::SignatureCheckCondition": "counter", //optional name{ "definition"UnnamedStruct": { "typetypes": "int", [ "mode": "FixedWidth"iroha_data_model::expression::EvaluatesTo<bool>" } ] } ] }
but can be overriden by attributes,
Code Block { "typeiroha_data_model::events::pipeline::EntityType": "enum",{ "nameEnum": "Bar", "codec": "SCALE", //possible values SCALE or JSON { "variants": [ { "name": "FirstVariantBlock", "discriminatordiscriminant": 10, "propertiesty": {null ... } }, { "name": "SecondVariantTransaction", "discriminatordiscriminant": 21, "propertiesty": {null } ... ] } } ] }}, }
Concerns
Currently we are not support polymorphism via TraitObjects, but it can be implemented if necessary
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]