You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
26 lines
815 B
26 lines
815 B
7 years ago
|
package com.xsn.explorer.helpers
|
||
|
|
||
|
import com.alexitc.playsonify.core.FutureApplicationResult
|
||
|
import com.xsn.explorer.errors.BlockNotFoundError
|
||
|
import com.xsn.explorer.models.Blockhash
|
||
|
import com.xsn.explorer.models.rpc.Block
|
||
|
import org.scalactic.{Good, One, Or}
|
||
|
|
||
|
import scala.concurrent.Future
|
||
|
|
||
|
class FileBasedXSNService extends DummyXSNService {
|
||
|
|
||
|
private lazy val blockMap = BlockLoader.all().map { block => block.hash -> block }.toMap
|
||
|
|
||
|
override def getBlock(blockhash: Blockhash): FutureApplicationResult[Block] = {
|
||
|
val maybe = blockMap.get(blockhash)
|
||
|
val result = Or.from(maybe, One(BlockNotFoundError))
|
||
|
Future.successful(result)
|
||
|
}
|
||
|
|
||
|
override def getLatestBlock(): FutureApplicationResult[Block] = {
|
||
|
val block = blockMap.values.maxBy(_.height.int)
|
||
|
Future.successful(Good(block))
|
||
|
}
|
||
|
}
|