-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
eadc40e
commit 306b138
Showing
7 changed files
with
101 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,14 @@ | ||
(executables | ||
(names scilla_runner eval_runner type_checker scilla_checker scilla_server | ||
disambiguate_state_json scilla_fmt scilla_merger) | ||
disambiguate_state_json scilla_fmt scilla_merger scilla_server_http) | ||
(public_names scilla-runner eval-runner type-checker scilla-checker | ||
scilla-server disambiguate_state_json scilla-fmt scilla-merger) | ||
scilla-server disambiguate_state_json scilla-fmt scilla-merger scilla-server-http) | ||
(package scilla) | ||
(modules scilla_runner eval_runner type_checker scilla_checker scilla_server | ||
disambiguate_state_json scilla_fmt scilla_merger) | ||
disambiguate_state_json scilla_fmt scilla_merger scilla_server_http) | ||
(libraries core core_unix.command_unix angstrom yojson cryptokit fileutils | ||
scilla_base scilla_eval scilla_server_lib scilla_crypto scilla_format | ||
scilla_merge cmdliner) | ||
scilla_merge cmdliner opium) | ||
(modes byte native) | ||
(preprocess | ||
(pps ppx_sexp_conv ppx_deriving_yojson ppx_let ppx_deriving.show bisect_ppx --conditional))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
open Core | ||
open Scilla_eval | ||
open Opium | ||
open Yojson.Safe | ||
open Core | ||
open Scilla_base | ||
open Scilla_server_lib.Api | ||
open IPCUtil | ||
open ErrorUtils | ||
|
||
module M = Idl.IdM | ||
module IDL = Idl.Make (M) | ||
module Server = API (IDL.GenServer ()) | ||
|
||
let mk_handler_no_args callback () = | ||
try IDL.ErrM.return @@ callback () | ||
with FatalError msg -> | ||
IDL.ErrM.return_err RPCError.{ code = 0; message = msg } | ||
|
||
(* Makes a handler that executes the given [callback] with [args] and returns it. **) | ||
let mk_handler callback args = | ||
(* Force the -jsonerrors flag *) | ||
let args = "-jsonerrors" :: args in | ||
try IDL.ErrM.return @@ callback (Some args) | ||
with FatalError msg -> | ||
IDL.ErrM.return_err RPCError.{ code = 0; message = msg } | ||
|
||
let server_implementation () = | ||
let runner args = | ||
let output, _ = Runner.run args ~exe_name:"scilla-runner" in | ||
Yojson.Basic.pretty_to_string output | ||
in | ||
let disambiguator args = | ||
Disambiguator.run args ~exe_name:"scilla-disambiguator" | ||
in | ||
let version () = | ||
let major, minor, patch = Syntax.scilla_version in | ||
Printf.sprintf "{ \"scilla_version\": \"%d.%d.%d\" }" major minor patch | ||
in | ||
(* Handlers *) | ||
Server.runner @@ mk_handler runner; | ||
Server.checker @@ mk_handler (Checker.run ~exe_name:"scilla-checker"); | ||
Server.disambiguator @@ mk_handler disambiguator; | ||
Server.version @@ mk_handler_no_args version; | ||
Server.implementation | ||
|
||
let run_handler req = | ||
let open Lwt.Syntax in | ||
let+ req = Request.to_plain_text req in | ||
let req = Jsonrpc.call_of_string req in | ||
|
||
let rpc = IDL.server (server_implementation ()) in | ||
let res = | ||
try M.run (rpc req) | ||
with e -> | ||
print_endline (Exn.to_string e); | ||
Rpc.failure | ||
(RPCError.rpc_of_t | ||
RPCError. | ||
{ code = 0; message = "scilla-server: incorrect invocation" }) | ||
in | ||
let str = Jsonrpc.string_of_response ~version:Jsonrpc.V2 res in | ||
|
||
Response.of_plain_text str | ||
;; | ||
|
||
let _ = | ||
App.empty | ||
|> App.post "/run" run_handler | ||
|> App.run_command | ||
;; |