RPC: rebind 'complete' for blocks and operations.
This commit is contained in:
parent
deec250be7
commit
ffc8fa0383
@ -12,8 +12,6 @@ open Store_sigs
|
|||||||
type t = Raw_store.t
|
type t = Raw_store.t
|
||||||
type global_store = t
|
type global_store = t
|
||||||
|
|
||||||
let init = Raw_store.init
|
|
||||||
|
|
||||||
(**************************************************************************
|
(**************************************************************************
|
||||||
* Net store under "net/"
|
* Net store under "net/"
|
||||||
**************************************************************************)
|
**************************************************************************)
|
||||||
@ -184,6 +182,7 @@ module Make_data_store
|
|||||||
Store_helpers.Make_indexed_substore
|
Store_helpers.Make_indexed_substore
|
||||||
(Store_helpers.Make_substore (S) (struct let name = ["data"] end))
|
(Store_helpers.Make_substore (S) (struct let name = ["data"] end))
|
||||||
(I)
|
(I)
|
||||||
|
|
||||||
module Discovery_time =
|
module Discovery_time =
|
||||||
Indexed_store.Make_map
|
Indexed_store.Make_map
|
||||||
(struct let name = ["discovery_time"] end)
|
(struct let name = ["discovery_time"] end)
|
||||||
@ -213,6 +212,7 @@ module Make_data_store
|
|||||||
(Indexed_store.Store)
|
(Indexed_store.Store)
|
||||||
(struct let name = ["validation_time"] end)
|
(struct let name = ["validation_time"] end)
|
||||||
(Store_helpers.Make_value(Time))
|
(Store_helpers.Make_value(Time))
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@ -270,6 +270,16 @@ module Operation = struct
|
|||||||
(Value)
|
(Value)
|
||||||
(Operation_hash.Set)
|
(Operation_hash.Set)
|
||||||
|
|
||||||
|
let register s =
|
||||||
|
Base58.register_resolver Operation_hash.b58check_encoding begin fun str ->
|
||||||
|
let pstr = Operation_hash.prefix_path str in
|
||||||
|
Net.Indexed_store.fold_indexes s ~init:[]
|
||||||
|
~f:begin fun net acc ->
|
||||||
|
Indexed_store.resolve_index (s, net) pstr >>= fun l ->
|
||||||
|
Lwt.return (List.rev_append l acc)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@ -381,6 +391,16 @@ module Block_header = struct
|
|||||||
let encoding = Operation_list_list_hash.path_encoding
|
let encoding = Operation_list_list_hash.path_encoding
|
||||||
end))
|
end))
|
||||||
|
|
||||||
|
let register s =
|
||||||
|
Base58.register_resolver Block_hash.b58check_encoding begin fun str ->
|
||||||
|
let pstr = Block_hash.prefix_path str in
|
||||||
|
Net.Indexed_store.fold_indexes s ~init:[]
|
||||||
|
~f:begin fun net acc ->
|
||||||
|
Indexed_store.resolve_index (s, net) pstr >>= fun l ->
|
||||||
|
Lwt.return (List.rev_append l acc)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@ -458,5 +478,19 @@ module Protocol = struct
|
|||||||
(Store_helpers.Make_value(Tezos_compiler.Protocol))
|
(Store_helpers.Make_value(Tezos_compiler.Protocol))
|
||||||
(Protocol_hash.Set)
|
(Protocol_hash.Set)
|
||||||
|
|
||||||
|
let register s =
|
||||||
|
Base58.register_resolver Protocol_hash.b58check_encoding begin fun str ->
|
||||||
|
let pstr = Protocol_hash.prefix_path str in
|
||||||
|
Indexed_store.resolve_index s pstr
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
let init dir =
|
||||||
|
Raw_store.init dir >>=? fun s ->
|
||||||
|
Block_header.register s ;
|
||||||
|
Operation.register s ;
|
||||||
|
Protocol.register s ;
|
||||||
|
return s
|
||||||
|
|
||||||
|
@ -119,7 +119,7 @@ module Make_indexed_substore (S : STORE) (I : INDEX) = struct
|
|||||||
let list t k = S.fold t k ~init:[] ~f:(fun k acc -> Lwt.return (k :: acc))
|
let list t k = S.fold t k ~init:[] ~f:(fun k acc -> Lwt.return (k :: acc))
|
||||||
let resolve_index t prefix =
|
let resolve_index t prefix =
|
||||||
let rec loop i prefix = function
|
let rec loop i prefix = function
|
||||||
| [] when i >= I.path_length -> begin
|
| [] when i = I.path_length -> begin
|
||||||
match I.of_path prefix with
|
match I.of_path prefix with
|
||||||
| None -> assert false
|
| None -> assert false
|
||||||
| Some path -> Lwt.return [path]
|
| Some path -> Lwt.return [path]
|
||||||
@ -129,7 +129,7 @@ module Make_indexed_substore (S : STORE) (I : INDEX) = struct
|
|||||||
Lwt_list.map_p (function
|
Lwt_list.map_p (function
|
||||||
| `Key prefix | `Dir prefix -> loop (i+1) prefix []) prefixes
|
| `Key prefix | `Dir prefix -> loop (i+1) prefix []) prefixes
|
||||||
>|= List.flatten
|
>|= List.flatten
|
||||||
| [d] ->
|
| [d] when i = I.path_length - 1 ->
|
||||||
if (i >= I.path_length) then invalid_arg "IO.resolve" ;
|
if (i >= I.path_length) then invalid_arg "IO.resolve" ;
|
||||||
list t prefix >>= fun prefixes ->
|
list t prefix >>= fun prefixes ->
|
||||||
Lwt_list.map_p (function
|
Lwt_list.map_p (function
|
||||||
@ -139,6 +139,11 @@ module Make_indexed_substore (S : STORE) (I : INDEX) = struct
|
|||||||
| Some _ -> loop (i+1) prefix [])
|
| Some _ -> loop (i+1) prefix [])
|
||||||
prefixes
|
prefixes
|
||||||
>|= List.flatten
|
>|= List.flatten
|
||||||
|
| "" :: ds ->
|
||||||
|
list t prefix >>= fun prefixes ->
|
||||||
|
Lwt_list.map_p (function
|
||||||
|
| `Key prefix | `Dir prefix -> loop (i+1) prefix ds) prefixes
|
||||||
|
>|= List.flatten
|
||||||
| d :: ds ->
|
| d :: ds ->
|
||||||
if (i >= I.path_length) then invalid_arg "IO.resolve" ;
|
if (i >= I.path_length) then invalid_arg "IO.resolve" ;
|
||||||
S.known_dir t (prefix @ [d]) >>= function
|
S.known_dir t (prefix @ [d]) >>= function
|
||||||
|
@ -253,19 +253,19 @@ module MakeResolvers(R: sig
|
|||||||
partial_decode ?alphabet request encoding.encoded_length in
|
partial_decode ?alphabet request encoding.encoded_length in
|
||||||
let len = String.length prefix in
|
let len = String.length prefix in
|
||||||
let ignored = String.length encoding.prefix in
|
let ignored = String.length encoding.prefix in
|
||||||
if len <= ignored then
|
let msg =
|
||||||
Lwt.return_nil
|
if len <= ignored then ""
|
||||||
else begin
|
else begin
|
||||||
assert (String.sub prefix 0 ignored = encoding.prefix) ;
|
assert (String.sub prefix 0 ignored = encoding.prefix) ;
|
||||||
let msg = String.sub prefix ignored (len - ignored) in
|
String.sub prefix ignored (len - ignored)
|
||||||
resolver context msg >|= fun msgs ->
|
end in
|
||||||
filter_map
|
resolver context msg >|= fun msgs ->
|
||||||
(fun msg ->
|
filter_map
|
||||||
let res = simple_encode encoding ?alphabet msg in
|
(fun msg ->
|
||||||
Utils.remove_prefix ~prefix:request res |>
|
let res = simple_encode encoding ?alphabet msg in
|
||||||
Utils.map_option ~f:(fun _ -> res))
|
Utils.remove_prefix ~prefix:request res |>
|
||||||
msgs
|
Utils.map_option ~f:(fun _ -> res))
|
||||||
end in
|
msgs in
|
||||||
find request !resolvers
|
find request !resolvers
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -146,7 +146,9 @@ let test_expand s =
|
|||||||
Base58.complete (Block_hash.to_short_b58check bh2) >>= fun res ->
|
Base58.complete (Block_hash.to_short_b58check bh2) >>= fun res ->
|
||||||
Assert.equal_string_list ~msg:__LOC__ res [Block_hash.to_b58check bh2] ;
|
Assert.equal_string_list ~msg:__LOC__ res [Block_hash.to_b58check bh2] ;
|
||||||
Base58.complete (Block_hash.to_short_b58check bh3) >>= fun res ->
|
Base58.complete (Block_hash.to_short_b58check bh3) >>= fun res ->
|
||||||
Assert.equal_string_list ~msg:__LOC__ res [Block_hash.to_b58check bh3] ;
|
Assert.equal_string_list ~msg:__LOC__
|
||||||
|
(List.sort String.compare res)
|
||||||
|
[Block_hash.to_b58check bh3' ; Block_hash.to_b58check bh3] ;
|
||||||
Lwt.return_unit
|
Lwt.return_unit
|
||||||
|
|
||||||
|
|
||||||
@ -431,7 +433,7 @@ let tests_raw : (string * (Raw_store.t -> unit Lwt.t)) list = [
|
|||||||
|
|
||||||
|
|
||||||
let tests : (string * (Store.t -> unit Lwt.t)) list = [
|
let tests : (string * (Store.t -> unit Lwt.t)) list = [
|
||||||
(* "expand", test_expand ; *) (* FIXME GRGR *)
|
"expand", test_expand ;
|
||||||
"operation", test_operation ;
|
"operation", test_operation ;
|
||||||
"block", test_block ;
|
"block", test_block ;
|
||||||
]
|
]
|
||||||
|
Loading…
Reference in New Issue
Block a user