Skip to content

Commit

Permalink
SubBlockTransactionsSpec
Browse files Browse the repository at this point in the history
  • Loading branch information
kushti committed Sep 5, 2024
1 parent 222c850 commit e6ee392
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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]){

}
Original file line number Diff line number Diff line change
@@ -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)
}
}

0 comments on commit e6ee392

Please sign in to comment.