diff --git a/src/main/scala/scorex/waves/Application.scala b/src/main/scala/scorex/waves/Application.scala index 56177f36810..e0e62f44e87 100644 --- a/src/main/scala/scorex/waves/Application.scala +++ b/src/main/scala/scorex/waves/Application.scala @@ -10,6 +10,7 @@ import scorex.consensus.nxt.api.http.NxtConsensusApiRoute import scorex.network.{TransactionalMessagesRepo, UnconfirmedPoolSynchronizer} import scorex.transaction.{BalanceSheet, GenesisTransaction, SimpleTransactionModule, Transaction} import scorex.utils.ScorexLogging +import scorex.waves.block.WavesBlock import scorex.waves.http.{DebugApiRoute, ScorexApiRoute} import scorex.waves.settings.WavesSettings import scorex.waves.transaction.WavesTransactionModule @@ -74,6 +75,14 @@ class Application(val settingsFilename: String) extends scorex.app.Application { actorSystem.actorOf(Props(classOf[UnconfirmedPoolSynchronizer], this)) + override def checkGenesis(): Unit = { + + if (transactionModule.blockStorage.history.isEmpty) { + transactionModule.blockStorage.appendBlock(WavesBlock.genesis()) + log.info("Genesis block has been added to the state") + } + } + } object Application extends App with ScorexLogging { diff --git a/src/main/scala/scorex/waves/block/WavesBlock.scala b/src/main/scala/scorex/waves/block/WavesBlock.scala new file mode 100644 index 00000000000..bbc4327d1de --- /dev/null +++ b/src/main/scala/scorex/waves/block/WavesBlock.scala @@ -0,0 +1,38 @@ +package scorex.waves.block + +import scorex.account.PublicKeyAccount +import scorex.block._ +import scorex.consensus.ConsensusModule +import scorex.crypto.EllipticCurveImpl +import scorex.transaction.TransactionModule +import scorex.utils.ScorexLogging + +object WavesBlock extends ScorexLogging { + type BlockId = Array[Byte] + + val BlockIdLength = EllipticCurveImpl.SignatureLength + + /** + * We override Block.genesis to provide correct genesis' timestamp + */ + def genesis[CDT, TDT]()(implicit consModule: ConsensusModule[CDT], + transModule: TransactionModule[TDT]): Block = new Block { + override type ConsensusDataType = CDT + override type TransactionDataType = TDT + + override implicit val transactionModule: TransactionModule[TDT] = transModule + override implicit val consensusModule: ConsensusModule[CDT] = consModule + + override val versionField: ByteBlockField = ByteBlockField("version", 1) + override val transactionDataField: BlockField[TDT] = transactionModule.genesisData + override val referenceField: BlockIdField = BlockIdField("reference", Array.fill(BlockIdLength)(0: Byte)) + override val consensusDataField: BlockField[CDT] = consensusModule.genesisData + override val uniqueId: BlockId = Array.fill(BlockIdLength)(0: Byte) + + //todo: inject timestamp from settings + override val timestampField: LongBlockField = LongBlockField("timestamp", 1460678400000L) + + override val signerDataField: SignerDataBlockField = new SignerDataBlockField("signature", + SignerData(new PublicKeyAccount(Array.fill(32)(0)), Array.fill(EllipticCurveImpl.SignatureLength)(0))) + } +} \ No newline at end of file