From 563f70c286f042d2b146f49b82b96593f0d28196 Mon Sep 17 00:00:00 2001 From: Alexander Chepurnoy Date: Fri, 4 Nov 2022 20:06:05 +0300 Subject: [PATCH] currentContext API method (with no OpenAPI description) --- .../org/ergoplatform/http/api/ErgoBaseApiRoute.scala | 6 ++++++ .../org/ergoplatform/http/api/ScriptApiRoute.scala | 12 +++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/main/scala/org/ergoplatform/http/api/ErgoBaseApiRoute.scala b/src/main/scala/org/ergoplatform/http/api/ErgoBaseApiRoute.scala index 97949231c4..39140d2e29 100644 --- a/src/main/scala/org/ergoplatform/http/api/ErgoBaseApiRoute.scala +++ b/src/main/scala/org/ergoplatform/http/api/ErgoBaseApiRoute.scala @@ -34,6 +34,12 @@ trait ErgoBaseApiRoute extends ApiRoute with ApiCodecs { } } + protected def getState(readersHolder: ActorRef): Future[ErgoStateReader] = { + (readersHolder ? GetReaders).mapTo[Readers].map { rs => + rs.s + } + } + private def getStateAndPool(readersHolder: ActorRef): Future[(ErgoStateReader, ErgoMemPoolReader)] = { (readersHolder ? GetReaders).mapTo[Readers].map { rs => (rs.s, rs.m) diff --git a/src/main/scala/org/ergoplatform/http/api/ScriptApiRoute.scala b/src/main/scala/org/ergoplatform/http/api/ScriptApiRoute.scala index 510b0a451e..508406eee4 100644 --- a/src/main/scala/org/ergoplatform/http/api/ScriptApiRoute.scala +++ b/src/main/scala/org/ergoplatform/http/api/ScriptApiRoute.scala @@ -43,7 +43,8 @@ case class ScriptApiRoute(readersHolder: ActorRef, ergoSettings: ErgoSettings) p2sAddressR ~ addressToTreeR ~ addressToBytesR ~ - executeWithContextR + executeWithContextR ~ + currentContextR } } @@ -96,6 +97,15 @@ case class ScriptApiRoute(readersHolder: ActorRef, ergoSettings: ErgoSettings) } } + def currentContextR: Route = (path("currentContext") & get) { + ApiResponse( + getState(readersHolder).map { stateReader => + val stateContext = stateReader.stateContext + stateContext.asInstanceOf[ErgoLikeContext].asJson + } + ) + } + def executeWithContextR: Route = (path("executeWithContext") & post & entity(as[ExecuteRequest])) { req => compileSource(req.script, req.env).fold(