Skip to content

Instantly share code, notes, and snippets.

@kushti
Created February 4, 2021 18:55
Show Gist options
  • Save kushti/490d7726a9280a843783606f743e4783 to your computer and use it in GitHub Desktop.
Save kushti/490d7726a9280a843783606f743e4783 to your computer and use it in GitHub Desktop.
object v2testing extends App {
implicit val ec: scala.concurrent.ExecutionContext = scala.concurrent.ExecutionContext.global
private val ergoSettings: ErgoSettings = ErgoSettings.read(Args(Some("/home/kushti/ergo/mainnet/mainnet.conf"), Some(NetworkType.MainNet)))
val ntp = new NetworkTimeProvider(ergoSettings.scorexSettings.ntp)
val ldc = new LinearDifficultyControl(ergoSettings.chainSettings)
val eh = ErgoHistory.readOrGenerate(ergoSettings, ntp)
val heights = ldc.previousHeadersRequiredForRecalculation(417792 + 1024 +1)
println(heights)
val headerOpts = heights.map(eh.bestHeaderIdAtHeight).map(idOpt => idOpt.flatMap(id => eh.typedModifierById[Header](id)))
println(headerOpts.map(_.map(_.id)))
val epochEnd = System.currentTimeMillis() + 1000 * 60 * 60 * 24 * 4
import java.text.DateFormat
import java.text.SimpleDateFormat
val dateFormat = new SimpleDateFormat("dd MMM yyyy HH:mm:ss:SSS Z")
val date = new Date(epochEnd)
System.out.println(dateFormat.format(date))
val headers = headerOpts.map{_ match {
case None => headerOpts.head.get.copy(height = 418816, nBits = 107976917L, timestamp = epochEnd)
case Some(h) if h.height == 418816 => headerOpts.head.get.copy(height = 418816, nBits = 107976917L, timestamp = epochEnd)
case Some(h) => h
}}
println(ldc.calculate(headers))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment