Skip to content

Commit

Permalink
fixed bug with genesis timestamp
Browse files Browse the repository at this point in the history
  • Loading branch information
gagarin55 committed Apr 19, 2016
1 parent ebf1ba9 commit 639cba2
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/main/scala/scorex/waves/Application.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
38 changes: 38 additions & 0 deletions src/main/scala/scorex/waves/block/WavesBlock.scala
Original file line number Diff line number Diff line change
@@ -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)))
}
}

0 comments on commit 639cba2

Please sign in to comment.