Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Page properties
label


Status

Status
colourRedGreen
titleNOT STARTEDdecided

Stakeholders
OutcomeIt was decided to proceed an implement schema generation
Due date
Owner


...

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
language

...

js
{
  "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
language

...

js
{

...

  "alloc::string::String": "String",
  "bool": "Bool"
}


23Built-in containers 

  • Option / Result / Map / Vec / typle : basically we are interested in only inner values of the container

    Code Block
    languagejs
    [
    {
        "definition": "Option",
        "item"core::option::Option<iroha_data_model::isi::Instruction>": {
            "definitionOption" : "booliroha_data_model::isi::Instruction"
        }
    },
    {
        "definition"core::result::Result<i32, i32>": "Result",{
        "itemResult": {
            "definitionok": "inti32",
            "modeerr": "CompactFourBytei32"
        }
      },
    {
        "definition": "Vec",
        "itemsalloc::collections::BTreeMap<alloc::string::String, i32>": {
            "definitionMap": "bool"{
        }
    },
    {
        "definitionkey": "tuple",
        "items": [
            {
                "definition": "int",
          alloc::string::String",
          "modevalue": "CompactFourBytei32"
          }
      },
            {
                "definition": "Option",
                "itemalloc::vec::Vec<i32>": {
                    "definitionVec" : "booli32"
                }
            
            }
        ]
    }
    ]


43Custom 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 definitions declared inline for built-in types and declared a reference for custom types Enums


    Code Block
    languagebashjs
    {
        "definition"iroha_crypto::PublicKey": "struct",{
        "nameNamedStruct": "Foo", //fully qualified non ambiguous name{
        "codec": "SCALE", //possible values SCALE or JSON
        "properties"declarations": [
            {
                "name": "enableddigest_function", //optional name
                "typety": {
                    "definition": "bool"
        "alloc::string::String"
            }
            },
            {
                "name": "idpayload", //optional name
                "typety": {
                    "definition": "struct", //reference to other struct "alloc::vec::Vec<u8>"
            }
            "struct_name": "Id"
      ]
              }
            },
            {
                "name": "counter", //optional name
       "iroha_data_model::account::SignatureCheckCondition": {
             "typeUnnamedStruct": {
                    "definition"types": "int",
            [
            "mode": "FixedWidthiroha_data_model::expression::EvaluatesTo<bool>"
                }]
            }
        ]
    }
    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 overridden by attributes
    Code Block
    {
        "definition"iroha_data_model::events::pipeline::EntityType": "enum",{
        "nameEnum": "Bar", //fully qualified non ambiguous name{
        "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

...