-
Notifications
You must be signed in to change notification settings - Fork 171
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
45 additions
and
0 deletions.
There are no files selected for viewing
9 changes: 9 additions & 0 deletions
9
.../src/main/scala/org/ergoplatform/network/message/subblocks/SubBlockTransactionsData.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]){ | ||
|
||
} |
36 changes: 36 additions & 0 deletions
36
.../src/main/scala/org/ergoplatform/network/message/subblocks/SubBlockTransactionsSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |