<commit_before>package examples.hybrid.api.http

import javax.ws.rs.Path

import akka.actor.{ActorRef, ActorRefFactory}
import akka.http.scaladsl.server.Route
import akka.pattern.ask
import examples.hybrid.blocks.{HybridPersistentNodeViewModifier, PosBlock, PowBlock}
import examples.hybrid.history.HybridHistory
import examples.hybrid.mempool.HMemPool
import examples.hybrid.state.HBoxStoredState
import examples.hybrid.wallet.HWallet
import io.circe.syntax._
import io.swagger.annotations._
import scorex.core.NodeViewHolder.{CurrentView, GetCurrentView}
import scorex.core.api.http.ApiRoute
import scorex.core.settings.Settings
import scorex.crypto.encode.Base58

import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.Future


@Path("/debug")
@Api(value = "/debug", description = "Useful functions", position = 3, produces = "application/json")
case class DebugApiRoute(override val settings: Settings, nodeViewHolderRef: ActorRef)
                        (implicit val context: ActorRefFactory) extends ApiRoute {

  def getView(): Future[CurrentView[HybridHistory, HBoxStoredState, HWallet, HMemPool]] = {
    (nodeViewHolderRef ? GetCurrentView)
      .mapTo[CurrentView[HybridHistory, HBoxStoredState, HWallet, HMemPool]]
  }

  override val route = pathPrefix("debug") {
    infoRoute ~ chain
  }

  @Path("/info")
  @ApiOperation(value = "Info", notes = "Debug info about blockchain", httpMethod = "GET")
  @ApiResponses(Array(
    new ApiResponse(code = 200, message = "Json with peer list or error")
  ))
  def infoRoute: Route = path("info") {
    getJsonRoute {
      getView().map { view =>
        Map(
          "height" -> view.history.powHeight.asJson,
          "stateVersion" -> Base58.encode(view.state.version).asJson
        ).asJson
      }
    }
  }

  @Path("/chain")
  @ApiOperation(value = "Chain", notes = "Print full chain", httpMethod = "GET")
  @ApiResponses(Array(
    new ApiResponse(code = 200, message = "Json with peer list or error")
  ))
  def chain: Route = path("chain") {
    getJsonRoute {
      getView().map { view =>
        Map(
          "history" -> view.history.toString
        ).asJson<commit_msg>Best PoW/PoS blocks to debug info<commit_after>package examples.hybrid.api.http

import javax.ws.rs.Path

import akka.actor.{ActorRef, ActorRefFactory}
import akka.http.scaladsl.server.Route
import akka.pattern.ask
import examples.hybrid.blocks.{HybridPersistentNodeViewModifier, PosBlock, PowBlock}
import examples.hybrid.history.HybridHistory
import examples.hybrid.mempool.HMemPool
import examples.hybrid.state.HBoxStoredState
import examples.hybrid.wallet.HWallet
import io.circe.syntax._
import io.swagger.annotations._
import scorex.core.NodeViewHolder.{CurrentView, GetCurrentView}
import scorex.core.api.http.ApiRoute
import scorex.core.settings.Settings
import scorex.crypto.encode.Base58

import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.Future


@Path("/debug")
@Api(value = "/debug", description = "Useful functions", position = 3, produces = "application/json")
case class DebugApiRoute(override val settings: Settings, nodeViewHolderRef: ActorRef)
                        (implicit val context: ActorRefFactory) extends ApiRoute {

  def getView(): Future[CurrentView[HybridHistory, HBoxStoredState, HWallet, HMemPool]] = {
    (nodeViewHolderRef ? GetCurrentView)
      .mapTo[CurrentView[HybridHistory, HBoxStoredState, HWallet, HMemPool]]
  }

  override val route = pathPrefix("debug") {
    infoRoute ~ chain
  }

  @Path("/info")
  @ApiOperation(value = "Info", notes = "Debug info about blockchain", httpMethod = "GET")
  @ApiResponses(Array(
    new ApiResponse(code = 200, message = "Json with peer list or error")
  ))
  def infoRoute: Route = path("info") {
    getJsonRoute {
      getView().map { view =>
        Map(
          "height" -> view.history.powHeight.asJson,
          "bestPoS" -> Base58.encode(view.history.bestPosId).asJson,
          "bestPoW" -> Base58.encode(view.history.bestPowId).asJson,
          "stateVersion" -> Base58.encode(view.state.version).asJson
        ).asJson
      }
    }
  }

  @Path("/chain")
  @ApiOperation(value = "Chain", notes = "Print full chain", httpMethod = "GET")
  @ApiResponses(Array(
    new ApiResponse(code = 200, message = "Json with peer list or error")
  ))
  def chain: Route = path("chain") {
    getJsonRoute {
      getView().map { view =>
        Map(
          "history" -> view.history.toString
        ).asJson
{'fraction_non_alphanumeric': 0.11901595744680851, 'fraction_numerical': 0.00576241134751773, 'mean_word_length': 3.8894907908992415, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4045180', 'n_tokens_mistral': 1409, 'n_tokens_neox': 1371, 'n_words': 302}