From e6ee392974484033ce7aa64ba71cf76ae3002f30 Mon Sep 17 00:00:00 2001 From: Alexander Chepurnoy Date: Thu, 5 Sep 2024 20:46:34 +0300 Subject: [PATCH] SubBlockTransactionsSpec --- .../subblocks/SubBlockTransactionsData.scala | 9 +++++ .../subblocks/SubBlockTransactionsSpec.scala | 36 +++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 ergo-core/src/main/scala/org/ergoplatform/network/message/subblocks/SubBlockTransactionsData.scala create mode 100644 ergo-core/src/main/scala/org/ergoplatform/network/message/subblocks/SubBlockTransactionsSpec.scala diff --git a/ergo-core/src/main/scala/org/ergoplatform/network/message/subblocks/SubBlockTransactionsData.scala b/ergo-core/src/main/scala/org/ergoplatform/network/message/subblocks/SubBlockTransactionsData.scala new file mode 100644 index 0000000000..51b8cc204a --- /dev/null +++ b/ergo-core/src/main/scala/org/ergoplatform/network/message/subblocks/SubBlockTransactionsData.scala @@ -0,0 +1,9 @@ +package org.ergoplatform.network.message.subblocks + +import org.ergoplatform.modifiers.mempool.ErgoTransaction +import scorex.util.ModifierId + +// todo: send transactions or transactions id ? +case class SubBlockTransactionsData(subblockID: ModifierId, transactions: Seq[ErgoTransaction]){ + +} diff --git a/ergo-core/src/main/scala/org/ergoplatform/network/message/subblocks/SubBlockTransactionsSpec.scala b/ergo-core/src/main/scala/org/ergoplatform/network/message/subblocks/SubBlockTransactionsSpec.scala new file mode 100644 index 0000000000..3ebc8eda16 --- /dev/null +++ b/ergo-core/src/main/scala/org/ergoplatform/network/message/subblocks/SubBlockTransactionsSpec.scala @@ -0,0 +1,36 @@ +package org.ergoplatform.network.message.subblocks + +import org.ergoplatform.modifiers.mempool.ErgoTransactionSerializer +import org.ergoplatform.network.message.MessageConstants.MessageCode +import org.ergoplatform.network.message.MessageSpecSubblocks +import scorex.util.{bytesToId, idToBytes} +import scorex.util.serialization.{Reader, Writer} +import sigma.util.Extensions.LongOps + +object SubBlockTransactionsSpec extends MessageSpecSubblocks[SubBlockTransactionsData]{ + /** + * Code which identifies what message type is contained in the payload + */ + override val messageCode: MessageCode = 92: Byte + /** + * Name of this message type. For debug purposes only. + */ + override val messageName: String = "SubBlockTxs" + + override def serialize(obj: SubBlockTransactionsData, w: Writer): Unit = { + w.putBytes(idToBytes(obj.subblockID)) + w.putUInt(obj.transactions.size) + obj.transactions.foreach { tx => + ErgoTransactionSerializer.serialize(tx, w) + } + } + + override def parse(r: Reader): SubBlockTransactionsData = { + val subBlockId = bytesToId(r.getBytes(32)) + val txsCount = r.getUInt().toIntExact + val transactions = (1 to txsCount).map{_ => + ErgoTransactionSerializer.parse(r) + } + SubBlockTransactionsData(subBlockId, transactions) + } +}