LoginSignup
3
1

More than 1 year has passed since last update.

TransferTransactionのスキーマを読み解こうその2

Last updated at Posted at 2022-06-22

inlineを展開する

さて構造体に定義されない定数は設定できたので、
次はinlineで格納されているスキーマを展開しよう

# Send mosaics and messages between two accounts.
struct TransferTransaction
	TRANSACTION_VERSION = make_const(uint8, 1)
	TRANSACTION_TYPE = make_const(TransactionType, TRANSFER)

	inline Transaction // ここと
	inline TransferTransactionBody // ここ

この二つを展開すると以下のようになります。


struct TransferTransaction
	TRANSACTION_VERSION = make_const(uint8, 1)
	TRANSACTION_TYPE = make_const(TransactionType, TRANSFER)

# ここはTransactionの部分

# binary layout for a transaction
@size(size)
@initializes(version, TRANSACTION_VERSION)
@initializes(type, TRANSACTION_TYPE)
@discriminator(type)
@is_aligned
abstract struct Transaction
	inline SizePrefixedEntity
	inline VerifiableEntity
	inline EntityBody

	# transaction type
	type = TransactionType

	# transaction fee
	fee = Amount

	# transaction deadline
	deadline = Timestamp

# ここはTransferTransactionBodyの部分
inline struct TransferTransactionBody
	# recipient address
	recipient_address = UnresolvedAddress

	# size of attached message
	message_size = uint16

	# number of attached mosaics
	mosaics_count = uint8

	# reserved padding to align mosaics on 8-byte boundary
	transfer_transaction_body_reserved_1 = make_reserved(uint8, 0)

	# reserved padding to align mosaics on 8-byte boundary
	transfer_transaction_body_reserved_2 = make_reserved(uint32, 0)

	# attached mosaics
	@sort_key(mosaic_id)
	mosaics = array(UnresolvedMosaic, mosaics_count)

	# attached message
	message = array(uint8, message_size)

いっぱいいろんな新しい単語も出てきましたね。難しそう。

ジャガーさんのコメント
size(x): x フィールドが(可変長の)構造体のフルサイズを含むことを示す。

initializes(x, Y): xフィールドがY定数で初期化されるべきであることを示す。

discriminator(x [, y ]+): (x, ...y)プロパティがファクトリー生成時に識別器として使用されるべきであることを示す
(抽象構造に対してのみ意味を持つ)。

is_aligned: すべての構造体フィールドがアライメントされた境界上に配置されることを示す。

size(size) => sizeフィールドの値は構造体全体のサイズ(バイト)である。

initializes(version, TRANSACTION_VERSION) => versionフィールドはTRANSACTION_VERSIONの値で初期化される必要がある。

@discriminator(type) => ファクトリー作成時に、インスタンス化する具象クラスを区別するために、typeフィールドを使用する。

全体像としてはこんな感じです。

スクリーンショット 2022-06-24 1.51.56.png

まぁこれだと結局トランザクションとトランスファートランザクションボディがどういう定義をされているのかわからないと
やっている意味がないので、次の記事はトランザクションの構造体を読み解いていきます

スクリーンショット 2022-06-24 1.53.10.png

3
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1