スキーマの記述

新しいトランザクションタイプを含む、新しい Catapult プラグインを記述しようとしていますか?

このガイドでは transfer.cats がどのように構築されるかを検証します。同じ手順を用いて新しいスキーマを定義することもできます。

インストラクション

  1. catbuffer リポジトリをクローンしてください。
 git clone https://github.com/nemtech/catbuffer.git

2. Create a new file under the schemas folder. In our case, we have named the file transfer.cats.

  1. トランザクション本体の構造体を定義。

構造体を同じメモリブロックに格納したい一連のプロパティとして考えます。

トランザクション本体には基本的なトランザクションとは異なる追加のプロパティが含まれています。各属性は types.cats で定義されているタイプの 1 つを持つことができます。

 # binary layout for a transfer transaction
struct TransferTransactionBody
    # transaction recipient
    recipient = UnresolvedAddress
    # size of attached message
    messageSize = uint16
    # number of attached mosaics
    mosaicsCount = uint8
    # transaction message
    message = array(byte, messageSize)
    # attached mosaics
    mosaics = array(UnresolvedMosaic, mosaicsCount, sort_key=mosaicId)

4. Define a second transaction struct in the same file. This will contain information about the version of the entity and its identifier. The underlying transaction properties and the particular transaction body are appended as inlines.

 # binary layout for a non-embedded transfer transaction
struct TransferTransaction
    const uint8 version = 3
    const EntityType entityType = 0x4154
    inline Transaction
    inline TransferTransactionBody

5. Define an EmbeddedTransaction struct to serialize the inner transactions within an aggregate. The embedded transaction and the body transaction are added as inlines.

 # binary layout for an embedded transaction
struct EmbeddedTransaction
    inline SizePrefixedEntity
    inline EntityBody

6. The catbuffer library allows you to generate the transaction builders from the schema we have defined. For example, run the following command to generate C++ code:

 python main.py --schema schemas/transfer/transfer.cats --generator cpp_builder

ジェネレータは _generated/cpp_builder フォルダの下にトランザクションビルダーファイルを作成します。