Skip to content

Commit

Permalink
currentContext API method (with no OpenAPI description)
Browse files Browse the repository at this point in the history
  • Loading branch information
kushti committed Nov 4, 2022
1 parent aef48d7 commit 563f70c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 11 additions & 1 deletion src/main/scala/org/ergoplatform/http/api/ScriptApiRoute.scala
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ case class ScriptApiRoute(readersHolder: ActorRef, ergoSettings: ErgoSettings)
p2sAddressR ~
addressToTreeR ~
addressToBytesR ~
executeWithContextR
executeWithContextR ~
currentContextR
}
}

Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 563f70c

Please sign in to comment.