Shell/RPC: also list embedded protocols

This commit is contained in:
Grégoire Henry 2018-04-21 13:44:24 +02:00 committed by Benjamin Canou
parent 04c920df29
commit 9bc7b1e573
4 changed files with 28 additions and 6 deletions

View File

@ -31,7 +31,7 @@ end
let () =
Format.printf {|
let () =
let module Ignored = Tezos_protocol_updater.Registered_protocol.Register
let module Ignored = Tezos_protocol_updater.Registered_protocol.Register_embedded
(Tezos_embedded_protocol_environment_%s.Environment)
(Tezos_embedded_raw_protocol_%s.Main)
(Source) in

View File

@ -42,6 +42,9 @@ module VersionTable = Protocol_hash.Table
let versions : (module T) VersionTable.t =
VersionTable.create 20
let sources : Protocol.t VersionTable.t =
VersionTable.create 20
let mem hash =
VersionTable.mem versions hash ||
Tezos_protocol_registerer.Registerer.mem hash
@ -57,7 +60,17 @@ let get hash =
try Some (get_exn hash)
with Not_found -> None
module Register
let list_embedded () =
VersionTable.fold (fun k _ acc -> k :: acc) sources []
let get_embedded_sources_exn hash =
VersionTable.find sources hash
let get_embedded_sources hash =
try Some (get_embedded_sources_exn hash)
with Not_found -> None
module Register_embedded
(Env : Tezos_protocol_environment_shell.V1)
(Proto : Env.Updater.PROTOCOL)
(Source : sig
@ -73,7 +86,8 @@ module Register
let module Name = struct
let name = Protocol_hash.to_b58check hash
end in
(* TODO add a memory table for "embedded" sources... *)
VersionTable.add
sources hash Source.sources ;
VersionTable.add
versions hash
(module struct

View File

@ -25,8 +25,12 @@ val mem: Protocol_hash.t -> bool
val get: Protocol_hash.t -> t option
val get_exn: Protocol_hash.t -> t
val list_embedded: unit -> Protocol_hash.t list
module Register
val get_embedded_sources: Protocol_hash.t -> Protocol.t option
val get_embedded_sources_exn: Protocol_hash.t -> Protocol.t
module Register_embedded
(Env : Tezos_protocol_environment_shell.V1)
(Proto : Env.Updater.PROTOCOL)
(Source : sig

View File

@ -17,12 +17,16 @@ let build_rpc_directory state =
gen_register0 Protocol_services.S.list begin fun () () ->
State.Protocol.list state >>= fun set ->
let protocols = Protocol_hash.Set.elements set in
let protocols =
Protocol_hash.Set.elements set @
Registered_protocol.list_embedded () in
RPC_answer.return protocols
end ;
register1 Protocol_services.S.contents begin fun hash () () ->
State.Protocol.read state hash
match Registered_protocol.get_embedded_sources hash with
| Some p -> return p
| None -> State.Protocol.read state hash
end ;
!dir