Everywhere: return_{none,some,nil,true,false}
This commit is contained in:
parent
103d5355f2
commit
1c2a771832
@ -92,7 +92,7 @@ let fill_in ?(show_optionals=true) input schema =
|
|||||||
Lwt.return acc
|
Lwt.return acc
|
||||||
else
|
else
|
||||||
element (string_of_int n :: path) elt >>= fun json ->
|
element (string_of_int n :: path) elt >>= fun json ->
|
||||||
(if n < min then Lwt.return true else input.continue title path) >>= function
|
(if n < min then Lwt.return_true else input.continue title path) >>= function
|
||||||
| true -> fill_loop (json :: acc) min (succ n) max
|
| true -> fill_loop (json :: acc) min (succ n) max
|
||||||
| false -> Lwt.return (json :: acc)
|
| false -> Lwt.return (json :: acc)
|
||||||
in
|
in
|
||||||
|
@ -119,16 +119,16 @@ let init_node ?sandbox ?checkpoint (config : Node_config_file.t) =
|
|||||||
| None -> Lwt.return_none
|
| None -> Lwt.return_none
|
||||||
| Some sandbox_param ->
|
| Some sandbox_param ->
|
||||||
match sandbox_param with
|
match sandbox_param with
|
||||||
| None -> Lwt.return None
|
| None -> Lwt.return_none
|
||||||
| Some file ->
|
| Some file ->
|
||||||
Lwt_utils_unix.Json.read_file file >>= function
|
Lwt_utils_unix.Json.read_file file >>= function
|
||||||
| Error err ->
|
| Error err ->
|
||||||
lwt_warn
|
lwt_warn
|
||||||
"Can't parse sandbox parameters: %s" file >>= fun () ->
|
"Can't parse sandbox parameters: %s" file >>= fun () ->
|
||||||
lwt_debug "%a" pp_print_error err >>= fun () ->
|
lwt_debug "%a" pp_print_error err >>= fun () ->
|
||||||
Lwt.return None
|
Lwt.return_none
|
||||||
| Ok json ->
|
| Ok json ->
|
||||||
Lwt.return (Some json)
|
Lwt.return_some json
|
||||||
end >>= fun sandbox_param ->
|
end >>= fun sandbox_param ->
|
||||||
(* TODO "WARN" when pow is below our expectation. *)
|
(* TODO "WARN" when pow is below our expectation. *)
|
||||||
begin
|
begin
|
||||||
@ -146,10 +146,10 @@ let init_node ?sandbox ?checkpoint (config : Node_config_file.t) =
|
|||||||
match listening_addr, sandbox with
|
match listening_addr, sandbox with
|
||||||
| Some addr, Some _
|
| Some addr, Some _
|
||||||
when Ipaddr.V6.(compare addr unspecified) = 0 ->
|
when Ipaddr.V6.(compare addr unspecified) = 0 ->
|
||||||
return None
|
return_none
|
||||||
| Some addr, Some _ when not (Ipaddr.V6.is_private addr) ->
|
| Some addr, Some _ when not (Ipaddr.V6.is_private addr) ->
|
||||||
fail (Non_private_sandbox addr)
|
fail (Non_private_sandbox addr)
|
||||||
| None, Some _ -> return None
|
| None, Some _ -> return_none
|
||||||
| _ ->
|
| _ ->
|
||||||
(Node_config_file.resolve_bootstrap_addrs
|
(Node_config_file.resolve_bootstrap_addrs
|
||||||
config.p2p.bootstrap_peers) >>= fun trusted_points ->
|
config.p2p.bootstrap_peers) >>= fun trusted_points ->
|
||||||
@ -172,7 +172,7 @@ let init_node ?sandbox ?checkpoint (config : Node_config_file.t) =
|
|||||||
disable_mempool = config.p2p.disable_mempool ;
|
disable_mempool = config.p2p.disable_mempool ;
|
||||||
}
|
}
|
||||||
in
|
in
|
||||||
return (Some (p2p_config, config.p2p.limits))
|
return_some (p2p_config, config.p2p.limits)
|
||||||
end >>=? fun p2p_config ->
|
end >>=? fun p2p_config ->
|
||||||
let node_config : Node.config = {
|
let node_config : Node.config = {
|
||||||
genesis ;
|
genesis ;
|
||||||
@ -201,7 +201,7 @@ let init_rpc (rpc_config: Node_config_file.rpc) node =
|
|||||||
match rpc_config.listen_addr with
|
match rpc_config.listen_addr with
|
||||||
| None ->
|
| None ->
|
||||||
lwt_log_notice "Not listening to RPC calls." >>= fun () ->
|
lwt_log_notice "Not listening to RPC calls." >>= fun () ->
|
||||||
return None
|
return_none
|
||||||
| Some addr ->
|
| Some addr ->
|
||||||
Node_config_file.resolve_rpc_listening_addrs addr >>= function
|
Node_config_file.resolve_rpc_listening_addrs addr >>= function
|
||||||
| [] ->
|
| [] ->
|
||||||
@ -228,7 +228,7 @@ let init_rpc (rpc_config: Node_config_file.rpc) node =
|
|||||||
~media_types:Media_type.all_media_types
|
~media_types:Media_type.all_media_types
|
||||||
~cors:{ allowed_origins = rpc_config.cors_origins ;
|
~cors:{ allowed_origins = rpc_config.cors_origins ;
|
||||||
allowed_headers = cors_headers } >>= fun server ->
|
allowed_headers = cors_headers } >>= fun server ->
|
||||||
return (Some server))
|
return_some server)
|
||||||
(function
|
(function
|
||||||
|Unix.Unix_error(Unix.EADDRINUSE, "bind","") ->
|
|Unix.Unix_error(Unix.EADDRINUSE, "bind","") ->
|
||||||
fail (RPC_Port_already_in_use [(addr,port)])
|
fail (RPC_Port_already_in_use [(addr,port)])
|
||||||
@ -284,7 +284,7 @@ let process sandbox verbosity checkpoint args =
|
|||||||
end >>=? fun () ->
|
end >>=? fun () ->
|
||||||
begin
|
begin
|
||||||
match checkpoint with
|
match checkpoint with
|
||||||
| None -> return None
|
| None -> return_none
|
||||||
| Some s ->
|
| Some s ->
|
||||||
match String.split ',' s with
|
match String.split ',' s with
|
||||||
| [ lvl ; block ] ->
|
| [ lvl ; block ] ->
|
||||||
@ -296,7 +296,7 @@ let process sandbox verbosity checkpoint args =
|
|||||||
| Some lvl ->
|
| Some lvl ->
|
||||||
return lvl
|
return lvl
|
||||||
end >>=? fun lvl ->
|
end >>=? fun lvl ->
|
||||||
return (Some (lvl, block))
|
return_some (lvl, block)
|
||||||
| [] -> assert false
|
| [] -> assert false
|
||||||
| [_] ->
|
| [_] ->
|
||||||
failwith "Checkoints are expected to follow the format \
|
failwith "Checkoints are expected to follow the format \
|
||||||
|
@ -23,9 +23,9 @@ let run (cctxt : #Client_context.wallet) ~hosts ?magic_bytes ~require_auth mode
|
|||||||
RPC_directory.register0 dir Signer_services.authorized_keys begin fun () () ->
|
RPC_directory.register0 dir Signer_services.authorized_keys begin fun () () ->
|
||||||
if require_auth then
|
if require_auth then
|
||||||
Handler.Authorized_key.load cctxt >>=? fun keys ->
|
Handler.Authorized_key.load cctxt >>=? fun keys ->
|
||||||
return (Some (keys |> List.split |> snd |> List.map Signature.Public_key.hash))
|
return_some (keys |> List.split |> snd |> List.map Signature.Public_key.hash)
|
||||||
else
|
else
|
||||||
return None
|
return_none
|
||||||
end in
|
end in
|
||||||
Lwt.catch
|
Lwt.catch
|
||||||
(fun () ->
|
(fun () ->
|
||||||
|
@ -564,8 +564,8 @@ let parse_arg :
|
|||||||
match spec with
|
match spec with
|
||||||
| Arg { parameter = (long, _) ; kind = { converter ; _ } ; _ } ->
|
| Arg { parameter = (long, _) ; kind = { converter ; _ } ; _ } ->
|
||||||
begin match TzString.Map.find long args_dict with
|
begin match TzString.Map.find long args_dict with
|
||||||
| exception Not_found -> return None
|
| exception Not_found -> return_none
|
||||||
| [] -> return None
|
| [] -> return_none
|
||||||
| [ s ] ->
|
| [ s ] ->
|
||||||
(trace
|
(trace
|
||||||
(Bad_option_argument ("--" ^ long, command))
|
(Bad_option_argument ("--" ^ long, command))
|
||||||
@ -595,9 +595,9 @@ let parse_arg :
|
|||||||
end
|
end
|
||||||
| Switch { parameter = (long, _) ; _ } ->
|
| Switch { parameter = (long, _) ; _ } ->
|
||||||
begin match TzString.Map.find long args_dict with
|
begin match TzString.Map.find long args_dict with
|
||||||
| exception Not_found -> return false
|
| exception Not_found -> return_false
|
||||||
| [] -> return false
|
| [] -> return_false
|
||||||
| [ _ ] -> return true
|
| [ _ ] -> return_true
|
||||||
| _ :: _ -> fail (Multiple_occurences (long, command))
|
| _ :: _ -> fail (Multiple_occurences (long, command))
|
||||||
end
|
end
|
||||||
| Constant c -> return c
|
| Constant c -> return c
|
||||||
@ -984,7 +984,7 @@ let rec list_args : type arg ctx. (arg, ctx) args -> string list = function
|
|||||||
|
|
||||||
let complete_func autocomplete cctxt =
|
let complete_func autocomplete cctxt =
|
||||||
match autocomplete with
|
match autocomplete with
|
||||||
| None -> return []
|
| None -> return_nil
|
||||||
| Some autocomplete -> autocomplete cctxt
|
| Some autocomplete -> autocomplete cctxt
|
||||||
|
|
||||||
let list_command_args (Command { options = Argument { spec ; _ } ; _ }) =
|
let list_command_args (Command { options = Argument { spec ; _ } ; _ }) =
|
||||||
@ -994,8 +994,8 @@ let complete_arg : type a ctx. ctx -> (a, ctx) arg -> string list tzresult Lwt.t
|
|||||||
fun ctx -> function
|
fun ctx -> function
|
||||||
| Arg { kind = { autocomplete ; _ } ; _ } -> complete_func autocomplete ctx
|
| Arg { kind = { autocomplete ; _ } ; _ } -> complete_func autocomplete ctx
|
||||||
| DefArg { kind = { autocomplete ; _ } ; _ } -> complete_func autocomplete ctx
|
| DefArg { kind = { autocomplete ; _ } ; _ } -> complete_func autocomplete ctx
|
||||||
| Switch _ -> return []
|
| Switch _ -> return_nil
|
||||||
| Constant _ -> return []
|
| Constant _ -> return_nil
|
||||||
|
|
||||||
let rec remaining_spec :
|
let rec remaining_spec :
|
||||||
type a ctx. TzString.Set.t -> (a, ctx) args -> string list =
|
type a ctx. TzString.Set.t -> (a, ctx) args -> string list =
|
||||||
@ -1013,7 +1013,7 @@ let complete_options (type ctx) continuation args args_spec ind (ctx : ctx) =
|
|||||||
let arities = make_arities_dict args_spec TzString.Map.empty in
|
let arities = make_arities_dict args_spec TzString.Map.empty in
|
||||||
let rec complete_spec : type a. string -> (a, ctx) args -> string list tzresult Lwt.t =
|
let rec complete_spec : type a. string -> (a, ctx) args -> string list tzresult Lwt.t =
|
||||||
fun name -> function
|
fun name -> function
|
||||||
| NoArgs -> return []
|
| NoArgs -> return_nil
|
||||||
| AddArg (Constant _, rest) ->
|
| AddArg (Constant _, rest) ->
|
||||||
complete_spec name rest
|
complete_spec name rest
|
||||||
| AddArg (arg, rest) ->
|
| AddArg (arg, rest) ->
|
||||||
@ -1057,7 +1057,7 @@ let complete_next_tree cctxt = function
|
|||||||
| TParam { autocomplete ; _ } ->
|
| TParam { autocomplete ; _ } ->
|
||||||
complete_func autocomplete cctxt
|
complete_func autocomplete cctxt
|
||||||
| TStop command -> return (list_command_args command)
|
| TStop command -> return (list_command_args command)
|
||||||
| TEmpty -> return []
|
| TEmpty -> return_nil
|
||||||
|
|
||||||
let complete_tree cctxt tree index args =
|
let complete_tree cctxt tree index args =
|
||||||
let rec help tree args ind =
|
let rec help tree args ind =
|
||||||
@ -1069,14 +1069,14 @@ let complete_tree cctxt tree index args =
|
|||||||
| TPrefix { prefix ; _ }, hd :: tl ->
|
| TPrefix { prefix ; _ }, hd :: tl ->
|
||||||
begin
|
begin
|
||||||
try help (List.assoc hd prefix) tl (ind - 1)
|
try help (List.assoc hd prefix) tl (ind - 1)
|
||||||
with Not_found -> return []
|
with Not_found -> return_nil
|
||||||
end
|
end
|
||||||
| TParam { tree ; _ }, _ :: tl ->
|
| TParam { tree ; _ }, _ :: tl ->
|
||||||
help tree tl (ind - 1)
|
help tree tl (ind - 1)
|
||||||
| TStop Command { options = Argument { spec ; _ } ; conv ;_ }, args ->
|
| TStop Command { options = Argument { spec ; _ } ; conv ;_ }, args ->
|
||||||
complete_options (fun _ _ -> return []) args spec ind (conv cctxt)
|
complete_options (fun _ _ -> return_nil) args spec ind (conv cctxt)
|
||||||
| (TParam _ | TPrefix _), []
|
| (TParam _ | TPrefix _), []
|
||||||
| TEmpty, _ -> return []
|
| TEmpty, _ -> return_nil
|
||||||
in help tree args index
|
in help tree args index
|
||||||
|
|
||||||
let autocompletion ~script ~cur_arg ~prev_arg ~args ~global_options commands cctxt =
|
let autocompletion ~script ~cur_arg ~prev_arg ~args ~global_options commands cctxt =
|
||||||
@ -1097,7 +1097,7 @@ let autocompletion ~script ~cur_arg ~prev_arg ~args ~global_options commands cct
|
|||||||
else
|
else
|
||||||
match ind 0 args with
|
match ind 0 args with
|
||||||
| None ->
|
| None ->
|
||||||
return []
|
return_nil
|
||||||
| Some index ->
|
| Some index ->
|
||||||
begin
|
begin
|
||||||
let Argument { spec ; _ } = global_options in
|
let Argument { spec ; _ } = global_options in
|
||||||
|
@ -106,13 +106,13 @@ module Alias = functor (Entity : Entity) -> struct
|
|||||||
|
|
||||||
let autocomplete wallet =
|
let autocomplete wallet =
|
||||||
load wallet >>= function
|
load wallet >>= function
|
||||||
| Error _ -> return []
|
| Error _ -> return_nil
|
||||||
| Ok list -> return (List.map fst list)
|
| Ok list -> return (List.map fst list)
|
||||||
|
|
||||||
let find_opt (wallet : #wallet) name =
|
let find_opt (wallet : #wallet) name =
|
||||||
load wallet >>=? fun list ->
|
load wallet >>=? fun list ->
|
||||||
try return (Some (List.assoc name list))
|
try return_some (List.assoc name list)
|
||||||
with Not_found -> return None
|
with Not_found -> return_none
|
||||||
|
|
||||||
let find (wallet : #wallet) name =
|
let find (wallet : #wallet) name =
|
||||||
load wallet >>=? fun list ->
|
load wallet >>=? fun list ->
|
||||||
@ -122,16 +122,16 @@ module Alias = functor (Entity : Entity) -> struct
|
|||||||
|
|
||||||
let rev_find (wallet : #wallet) v =
|
let rev_find (wallet : #wallet) v =
|
||||||
load wallet >>=? fun list ->
|
load wallet >>=? fun list ->
|
||||||
try return (Some (List.find (fun (_, v') -> v = v') list |> fst))
|
try return_some (List.find (fun (_, v') -> v = v') list |> fst)
|
||||||
with Not_found -> return None
|
with Not_found -> return_none
|
||||||
|
|
||||||
let mem (wallet : #wallet) name =
|
let mem (wallet : #wallet) name =
|
||||||
load wallet >>=? fun list ->
|
load wallet >>=? fun list ->
|
||||||
try
|
try
|
||||||
ignore (List.assoc name list) ;
|
ignore (List.assoc name list) ;
|
||||||
return true
|
return_true
|
||||||
with
|
with
|
||||||
| Not_found -> return false
|
| Not_found -> return_false
|
||||||
|
|
||||||
let add ~force (wallet : #wallet) name value =
|
let add ~force (wallet : #wallet) name value =
|
||||||
let keep = ref false in
|
let keep = ref false in
|
||||||
|
@ -66,7 +66,7 @@ let wait_for_operation_inclusion
|
|||||||
"Error while fetching block (ignored): %a"
|
"Error while fetching block (ignored): %a"
|
||||||
pp_print_error err >>= fun () ->
|
pp_print_error err >>= fun () ->
|
||||||
(* Will be retried when a new head arrives *)
|
(* Will be retried when a new head arrives *)
|
||||||
Lwt.return [] in
|
Lwt.return_nil in
|
||||||
|
|
||||||
(* Check whether a block as enough confirmations. This function
|
(* Check whether a block as enough confirmations. This function
|
||||||
assumes that the block predecessor has been processed already. *)
|
assumes that the block predecessor has been processed already. *)
|
||||||
@ -81,9 +81,9 @@ let wait_for_operation_inclusion
|
|||||||
(n+1) Block_hash.pp hash >>= fun () ->
|
(n+1) Block_hash.pp hash >>= fun () ->
|
||||||
Block_hash.Table.add blocks hash (Some (block_with_op, n+1)) ;
|
Block_hash.Table.add blocks hash (Some (block_with_op, n+1)) ;
|
||||||
if n+1 < confirmations then begin
|
if n+1 < confirmations then begin
|
||||||
return None
|
return_none
|
||||||
end else
|
end else
|
||||||
return (Some block_with_op)
|
return_some block_with_op
|
||||||
| None ->
|
| None ->
|
||||||
Shell_services.Blocks.Operation_hashes.operation_hashes
|
Shell_services.Blocks.Operation_hashes.operation_hashes
|
||||||
ctxt ~chain ~block () >>=? fun operations ->
|
ctxt ~chain ~block () >>=? fun operations ->
|
||||||
@ -101,16 +101,16 @@ let wait_for_operation_inclusion
|
|||||||
match in_block with
|
match in_block with
|
||||||
| None ->
|
| None ->
|
||||||
Block_hash.Table.add blocks hash None ;
|
Block_hash.Table.add blocks hash None ;
|
||||||
return None
|
return_none
|
||||||
| Some (i, j) -> begin
|
| Some (i, j) -> begin
|
||||||
ctxt#answer
|
ctxt#answer
|
||||||
"Operation found in block: %a (pass: %d, offset: %d)"
|
"Operation found in block: %a (pass: %d, offset: %d)"
|
||||||
Block_hash.pp hash i j >>= fun () ->
|
Block_hash.pp hash i j >>= fun () ->
|
||||||
Block_hash.Table.add blocks hash (Some ((hash, i, j), 0)) ;
|
Block_hash.Table.add blocks hash (Some ((hash, i, j), 0)) ;
|
||||||
if confirmations <= 0 then
|
if confirmations <= 0 then
|
||||||
return (Some (hash, i, j))
|
return_some (hash, i, j)
|
||||||
else begin
|
else begin
|
||||||
return None
|
return_none
|
||||||
end
|
end
|
||||||
end in
|
end in
|
||||||
|
|
||||||
@ -138,8 +138,8 @@ let wait_for_operation_inclusion
|
|||||||
Lwt_stream.find_s
|
Lwt_stream.find_s
|
||||||
(fun (hash, header) ->
|
(fun (hash, header) ->
|
||||||
process hash header >>= function
|
process hash header >>= function
|
||||||
| Ok None -> Lwt.return false
|
| Ok None -> Lwt.return_false
|
||||||
| Ok (Some _) -> Lwt.return true
|
| Ok (Some _) -> Lwt.return_true
|
||||||
| Error err ->
|
| Error err ->
|
||||||
Lwt.fail (WrapError err)) stream >>= return)
|
Lwt.fail (WrapError err)) stream >>= return)
|
||||||
(function
|
(function
|
||||||
|
@ -219,12 +219,12 @@ let raw_get_key (cctxt : #Client_context.wallet) pkh =
|
|||||||
| Some n ->
|
| Some n ->
|
||||||
Secret_key.find_opt cctxt n >>=? fun sk_uri ->
|
Secret_key.find_opt cctxt n >>=? fun sk_uri ->
|
||||||
Public_key.find_opt cctxt n >>=? begin function
|
Public_key.find_opt cctxt n >>=? begin function
|
||||||
| None -> return None
|
| None -> return_none
|
||||||
| Some (_, Some pk) -> return (Some pk)
|
| Some (_, Some pk) -> return_some pk
|
||||||
| Some (pk_uri, None) ->
|
| Some (pk_uri, None) ->
|
||||||
public_key pk_uri >>=? fun pk ->
|
public_key pk_uri >>=? fun pk ->
|
||||||
Public_key.update cctxt n (pk_uri, Some pk) >>=? fun () ->
|
Public_key.update cctxt n (pk_uri, Some pk) >>=? fun () ->
|
||||||
return (Some pk)
|
return_some pk
|
||||||
end >>=? fun pk ->
|
end >>=? fun pk ->
|
||||||
return (n, pk, sk_uri)
|
return (n, pk, sk_uri)
|
||||||
end >>= function
|
end >>= function
|
||||||
@ -268,7 +268,7 @@ let get_keys (cctxt : #Client_context.wallet) =
|
|||||||
end >>=? fun pk ->
|
end >>=? fun pk ->
|
||||||
return (name, pkh, pk, sk_uri)
|
return (name, pkh, pk, sk_uri)
|
||||||
end >>= function
|
end >>= function
|
||||||
| Ok r -> Lwt.return (Some r)
|
| Ok r -> Lwt.return_some r
|
||||||
| Error _ -> Lwt.return_none
|
| Error _ -> Lwt.return_none
|
||||||
end sks >>= fun keys ->
|
end sks >>= fun keys ->
|
||||||
return keys
|
return keys
|
||||||
@ -287,8 +287,8 @@ let list_keys cctxt =
|
|||||||
let alias_keys cctxt name =
|
let alias_keys cctxt name =
|
||||||
Public_key_hash.find cctxt name >>=? fun pkh ->
|
Public_key_hash.find cctxt name >>=? fun pkh ->
|
||||||
raw_get_key cctxt pkh >>= function
|
raw_get_key cctxt pkh >>= function
|
||||||
| Ok (_name, pk, sk_uri) -> return (Some (pkh, pk, sk_uri))
|
| Ok (_name, pk, sk_uri) -> return_some (pkh, pk, sk_uri)
|
||||||
| Error _ -> return None
|
| Error _ -> return_none
|
||||||
|
|
||||||
let force_switch () =
|
let force_switch () =
|
||||||
Clic.switch
|
Clic.switch
|
||||||
|
@ -173,12 +173,12 @@ let wait_parameter () =
|
|||||||
parameter
|
parameter
|
||||||
(fun _ wait ->
|
(fun _ wait ->
|
||||||
match wait with
|
match wait with
|
||||||
| "no" | "none" -> return None
|
| "no" | "none" -> return_none
|
||||||
| _ ->
|
| _ ->
|
||||||
try
|
try
|
||||||
let w = int_of_string wait in
|
let w = int_of_string wait in
|
||||||
if 0 <= w then
|
if 0 <= w then
|
||||||
return (Some w)
|
return_some w
|
||||||
else
|
else
|
||||||
fail (Invalid_wait_arg wait)
|
fail (Invalid_wait_arg wait)
|
||||||
with _ -> fail (Invalid_wait_arg wait))
|
with _ -> fail (Invalid_wait_arg wait))
|
||||||
@ -193,7 +193,7 @@ let protocol_parameter () =
|
|||||||
(Protocol_hash.to_b58check hash))
|
(Protocol_hash.to_b58check hash))
|
||||||
(Client_commands.get_versions ())
|
(Client_commands.get_versions ())
|
||||||
in
|
in
|
||||||
return (Some hash)
|
return_some hash
|
||||||
with Not_found -> fail (Invalid_protocol_argument arg)
|
with Not_found -> fail (Invalid_protocol_argument arg)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -123,8 +123,8 @@ let rec input_fundraiser_params (cctxt : #Client_context.io_wallet) =
|
|||||||
cctxt#prompt "%s %s: " msg prompt >>=? fun gen ->
|
cctxt#prompt "%s %s: " msg prompt >>=? fun gen ->
|
||||||
match default, String.lowercase_ascii gen with
|
match default, String.lowercase_ascii gen with
|
||||||
| default, "" -> return default
|
| default, "" -> return default
|
||||||
| _, "y" -> return true
|
| _, "y" -> return_true
|
||||||
| _, "n" -> return false
|
| _, "n" -> return_false
|
||||||
| _, "q" -> failwith "Exit by user request."
|
| _, "q" -> failwith "Exit by user request."
|
||||||
| _ -> get_boolean_answer cctxt ~msg ~default in
|
| _ -> get_boolean_answer cctxt ~msg ~default in
|
||||||
cctxt#prompt "Enter the e-mail used for the paper wallet: " >>=? fun email ->
|
cctxt#prompt "Enter the e-mail used for the paper wallet: " >>=? fun email ->
|
||||||
|
@ -319,6 +319,16 @@ module Make(Prefix : sig val id : string end) = struct
|
|||||||
|
|
||||||
let return_unit = Lwt.return (Ok ())
|
let return_unit = Lwt.return (Ok ())
|
||||||
|
|
||||||
|
let return_none = Lwt.return (Ok None)
|
||||||
|
|
||||||
|
let return_some x = Lwt.return (Ok (Some x))
|
||||||
|
|
||||||
|
let return_nil = Lwt.return (Ok [])
|
||||||
|
|
||||||
|
let return_true = Lwt.return (Ok true)
|
||||||
|
|
||||||
|
let return_false = Lwt.return (Ok false)
|
||||||
|
|
||||||
let error s = Error [ s ]
|
let error s = Error [ s ]
|
||||||
|
|
||||||
let ok v = Ok v
|
let ok v = Ok v
|
||||||
@ -342,7 +352,7 @@ module Make(Prefix : sig val id : string end) = struct
|
|||||||
|
|
||||||
let rec map_s f l =
|
let rec map_s f l =
|
||||||
match l with
|
match l with
|
||||||
| [] -> return []
|
| [] -> return_nil
|
||||||
| h :: t ->
|
| h :: t ->
|
||||||
f h >>=? fun rh ->
|
f h >>=? fun rh ->
|
||||||
map_s f t >>=? fun rt ->
|
map_s f t >>=? fun rt ->
|
||||||
@ -351,7 +361,7 @@ module Make(Prefix : sig val id : string end) = struct
|
|||||||
let mapi_s f l =
|
let mapi_s f l =
|
||||||
let rec mapi_s f i l =
|
let rec mapi_s f i l =
|
||||||
match l with
|
match l with
|
||||||
| [] -> return []
|
| [] -> return_nil
|
||||||
| h :: t ->
|
| h :: t ->
|
||||||
f i h >>=? fun rh ->
|
f i h >>=? fun rh ->
|
||||||
mapi_s f (i+1) t >>=? fun rt ->
|
mapi_s f (i+1) t >>=? fun rt ->
|
||||||
@ -362,7 +372,7 @@ module Make(Prefix : sig val id : string end) = struct
|
|||||||
let rec map_p f l =
|
let rec map_p f l =
|
||||||
match l with
|
match l with
|
||||||
| [] ->
|
| [] ->
|
||||||
return []
|
return_nil
|
||||||
| x :: l ->
|
| x :: l ->
|
||||||
let tx = f x and tl = map_p f l in
|
let tx = f x and tl = map_p f l in
|
||||||
tx >>= fun x ->
|
tx >>= fun x ->
|
||||||
@ -377,7 +387,7 @@ module Make(Prefix : sig val id : string end) = struct
|
|||||||
let rec mapi_p f i l =
|
let rec mapi_p f i l =
|
||||||
match l with
|
match l with
|
||||||
| [] ->
|
| [] ->
|
||||||
return []
|
return_nil
|
||||||
| x :: l ->
|
| x :: l ->
|
||||||
let tx = f i x and tl = mapi_p f (i+1) l in
|
let tx = f i x and tl = mapi_p f (i+1) l in
|
||||||
tx >>= fun x ->
|
tx >>= fun x ->
|
||||||
@ -391,7 +401,7 @@ module Make(Prefix : sig val id : string end) = struct
|
|||||||
|
|
||||||
let rec map2_s f l1 l2 =
|
let rec map2_s f l1 l2 =
|
||||||
match l1, l2 with
|
match l1, l2 with
|
||||||
| [], [] -> return []
|
| [], [] -> return_nil
|
||||||
| _ :: _, [] | [], _ :: _ -> invalid_arg "Error_monad.map2_s"
|
| _ :: _, [] | [], _ :: _ -> invalid_arg "Error_monad.map2_s"
|
||||||
| h1 :: t1, h2 :: t2 ->
|
| h1 :: t1, h2 :: t2 ->
|
||||||
f h1 h2 >>=? fun rh ->
|
f h1 h2 >>=? fun rh ->
|
||||||
@ -401,7 +411,7 @@ module Make(Prefix : sig val id : string end) = struct
|
|||||||
let mapi2_s f l1 l2 =
|
let mapi2_s f l1 l2 =
|
||||||
let rec mapi2_s i f l1 l2 =
|
let rec mapi2_s i f l1 l2 =
|
||||||
match l1, l2 with
|
match l1, l2 with
|
||||||
| [], [] -> return []
|
| [], [] -> return_nil
|
||||||
| _ :: _, [] | [], _ :: _ -> invalid_arg "Error_monad.mapi2_s"
|
| _ :: _, [] | [], _ :: _ -> invalid_arg "Error_monad.mapi2_s"
|
||||||
| h1 :: t1, h2 :: t2 ->
|
| h1 :: t1, h2 :: t2 ->
|
||||||
f i h1 h2 >>=? fun rh ->
|
f i h1 h2 >>=? fun rh ->
|
||||||
@ -420,7 +430,7 @@ module Make(Prefix : sig val id : string end) = struct
|
|||||||
|
|
||||||
let rec filter_map_s f l =
|
let rec filter_map_s f l =
|
||||||
match l with
|
match l with
|
||||||
| [] -> return []
|
| [] -> return_nil
|
||||||
| h :: t ->
|
| h :: t ->
|
||||||
f h >>=? function
|
f h >>=? function
|
||||||
| None -> filter_map_s f t
|
| None -> filter_map_s f t
|
||||||
@ -430,7 +440,7 @@ module Make(Prefix : sig val id : string end) = struct
|
|||||||
|
|
||||||
let rec filter_map_p f l =
|
let rec filter_map_p f l =
|
||||||
match l with
|
match l with
|
||||||
| [] -> return []
|
| [] -> return_nil
|
||||||
| h :: t ->
|
| h :: t ->
|
||||||
let th = f h
|
let th = f h
|
||||||
and tt = filter_map_p f t in
|
and tt = filter_map_p f t in
|
||||||
@ -442,7 +452,7 @@ module Make(Prefix : sig val id : string end) = struct
|
|||||||
|
|
||||||
let rec filter_s f l =
|
let rec filter_s f l =
|
||||||
match l with
|
match l with
|
||||||
| [] -> return []
|
| [] -> return_nil
|
||||||
| h :: t ->
|
| h :: t ->
|
||||||
f h >>=? function
|
f h >>=? function
|
||||||
| false -> filter_s f t
|
| false -> filter_s f t
|
||||||
@ -452,7 +462,7 @@ module Make(Prefix : sig val id : string end) = struct
|
|||||||
|
|
||||||
let rec filter_p f l =
|
let rec filter_p f l =
|
||||||
match l with
|
match l with
|
||||||
| [] -> return []
|
| [] -> return_nil
|
||||||
| h :: t ->
|
| h :: t ->
|
||||||
let jh = f h
|
let jh = f h
|
||||||
and t = filter_p f t in
|
and t = filter_p f t in
|
||||||
|
@ -83,6 +83,21 @@ module type S = sig
|
|||||||
(** Sucessful return of [()] *)
|
(** Sucessful return of [()] *)
|
||||||
val return_unit : unit tzresult Lwt.t
|
val return_unit : unit tzresult Lwt.t
|
||||||
|
|
||||||
|
(** Sucessful return of [None] *)
|
||||||
|
val return_none : 'a option tzresult Lwt.t
|
||||||
|
|
||||||
|
(** [return_some x] is a sucessful return of [Some x] *)
|
||||||
|
val return_some : 'a -> 'a option tzresult Lwt.t
|
||||||
|
|
||||||
|
(** Sucessful return of [[]] *)
|
||||||
|
val return_nil : 'a list tzresult Lwt.t
|
||||||
|
|
||||||
|
(** Sucessful return of [true] *)
|
||||||
|
val return_true : bool tzresult Lwt.t
|
||||||
|
|
||||||
|
(** Sucessful return of [false] *)
|
||||||
|
val return_false : bool tzresult Lwt.t
|
||||||
|
|
||||||
(** Erroneous result *)
|
(** Erroneous result *)
|
||||||
val error : error -> 'a tzresult
|
val error : error -> 'a tzresult
|
||||||
|
|
||||||
|
@ -146,13 +146,13 @@ let create_maintenance_worker limits pool =
|
|||||||
|
|
||||||
let may_create_welcome_worker config limits pool =
|
let may_create_welcome_worker config limits pool =
|
||||||
match config.listening_port with
|
match config.listening_port with
|
||||||
| None -> Lwt.return None
|
| None -> Lwt.return_none
|
||||||
| Some port ->
|
| Some port ->
|
||||||
P2p_welcome.run
|
P2p_welcome.run
|
||||||
~backlog:limits.backlog pool
|
~backlog:limits.backlog pool
|
||||||
?addr:config.listening_addr
|
?addr:config.listening_addr
|
||||||
port >>= fun w ->
|
port >>= fun w ->
|
||||||
Lwt.return (Some w)
|
Lwt.return_some w
|
||||||
|
|
||||||
type ('msg, 'peer_meta, 'conn_meta) connection =
|
type ('msg, 'peer_meta, 'conn_meta) connection =
|
||||||
('msg, 'peer_meta, 'conn_meta) P2p_pool.connection
|
('msg, 'peer_meta, 'conn_meta) P2p_pool.connection
|
||||||
@ -233,7 +233,7 @@ module Real = struct
|
|||||||
net.pool ~init:[]
|
net.pool ~init:[]
|
||||||
~f:begin fun _peer_id conn acc ->
|
~f:begin fun _peer_id conn acc ->
|
||||||
(P2p_pool.is_readable conn >>= function
|
(P2p_pool.is_readable conn >>= function
|
||||||
| Ok () -> Lwt.return (Some conn)
|
| Ok () -> Lwt.return_some conn
|
||||||
| Error _ -> Lwt_utils.never_ending ()) :: acc
|
| Error _ -> Lwt_utils.never_ending ()) :: acc
|
||||||
end in
|
end in
|
||||||
Lwt.pick (
|
Lwt.pick (
|
||||||
@ -616,7 +616,7 @@ let build_rpc_directory net =
|
|||||||
RPC_directory.register0 dir P2p_services.Connections.S.list
|
RPC_directory.register0 dir P2p_services.Connections.S.list
|
||||||
begin fun () () ->
|
begin fun () () ->
|
||||||
match net.pool with
|
match net.pool with
|
||||||
| None -> return []
|
| None -> return_nil
|
||||||
| Some pool ->
|
| Some pool ->
|
||||||
return @@
|
return @@
|
||||||
P2p_pool.Connection.fold
|
P2p_pool.Connection.fold
|
||||||
@ -632,7 +632,7 @@ let build_rpc_directory net =
|
|||||||
RPC_directory.register0 dir P2p_services.Peers.S.list
|
RPC_directory.register0 dir P2p_services.Peers.S.list
|
||||||
begin fun q () ->
|
begin fun q () ->
|
||||||
match net.pool with
|
match net.pool with
|
||||||
| None -> return []
|
| None -> return_nil
|
||||||
| Some pool ->
|
| Some pool ->
|
||||||
return @@
|
return @@
|
||||||
P2p_pool.Peers.fold_known pool
|
P2p_pool.Peers.fold_known pool
|
||||||
@ -651,7 +651,7 @@ let build_rpc_directory net =
|
|||||||
RPC_directory.opt_register1 dir P2p_services.Peers.S.info
|
RPC_directory.opt_register1 dir P2p_services.Peers.S.info
|
||||||
begin fun peer_id () () ->
|
begin fun peer_id () () ->
|
||||||
match net.pool with
|
match net.pool with
|
||||||
| None -> return None
|
| None -> return_none
|
||||||
| Some pool ->
|
| Some pool ->
|
||||||
return @@
|
return @@
|
||||||
Option.map ~f:(info_of_peer_info pool)
|
Option.map ~f:(info_of_peer_info pool)
|
||||||
@ -713,9 +713,9 @@ let build_rpc_directory net =
|
|||||||
RPC_directory.register1 dir P2p_services.Peers.S.banned
|
RPC_directory.register1 dir P2p_services.Peers.S.banned
|
||||||
begin fun peer_id () () ->
|
begin fun peer_id () () ->
|
||||||
match net.pool with
|
match net.pool with
|
||||||
| None -> return false
|
| None -> return_false
|
||||||
| Some pool when (P2p_pool.Peers.get_trusted pool peer_id) ->
|
| Some pool when (P2p_pool.Peers.get_trusted pool peer_id) ->
|
||||||
return false
|
return_false
|
||||||
| Some pool ->
|
| Some pool ->
|
||||||
return (P2p_pool.Peers.banned pool peer_id)
|
return (P2p_pool.Peers.banned pool peer_id)
|
||||||
end in
|
end in
|
||||||
@ -726,7 +726,7 @@ let build_rpc_directory net =
|
|||||||
RPC_directory.register0 dir P2p_services.Points.S.list
|
RPC_directory.register0 dir P2p_services.Points.S.list
|
||||||
begin fun q () ->
|
begin fun q () ->
|
||||||
match net.pool with
|
match net.pool with
|
||||||
| None -> return []
|
| None -> return_nil
|
||||||
| Some pool ->
|
| Some pool ->
|
||||||
return @@
|
return @@
|
||||||
P2p_pool.Points.fold_known
|
P2p_pool.Points.fold_known
|
||||||
@ -745,7 +745,7 @@ let build_rpc_directory net =
|
|||||||
RPC_directory.opt_register1 dir P2p_services.Points.S.info
|
RPC_directory.opt_register1 dir P2p_services.Points.S.info
|
||||||
begin fun point () () ->
|
begin fun point () () ->
|
||||||
match net.pool with
|
match net.pool with
|
||||||
| None -> return None
|
| None -> return_none
|
||||||
| Some pool ->
|
| Some pool ->
|
||||||
return @@
|
return @@
|
||||||
Option.map
|
Option.map
|
||||||
|
@ -138,7 +138,7 @@ module Info = struct
|
|||||||
Lwt_utils_unix.Json.read_file path >>=? fun json ->
|
Lwt_utils_unix.Json.read_file path >>=? fun json ->
|
||||||
return (Data_encoding.Json.destruct enc json)
|
return (Data_encoding.Json.destruct enc json)
|
||||||
else
|
else
|
||||||
return []
|
return_nil
|
||||||
|
|
||||||
let save path peer_metadata_encoding peers =
|
let save path peer_metadata_encoding peers =
|
||||||
let open Data_encoding in
|
let open Data_encoding in
|
||||||
|
@ -904,7 +904,7 @@ and create_connection pool p2p_conn id_point point_info peer_info _version =
|
|||||||
private_node_warn
|
private_node_warn
|
||||||
"Receive requests for peers addresses from %a"
|
"Receive requests for peers addresses from %a"
|
||||||
P2p_peer.Id.pp peer_id >>= fun () ->
|
P2p_peer.Id.pp peer_id >>= fun () ->
|
||||||
Lwt.return []
|
Lwt.return_nil
|
||||||
) ;
|
) ;
|
||||||
swap_request =
|
swap_request =
|
||||||
(fun _point _peer_id ->
|
(fun _point _peer_id ->
|
||||||
@ -987,7 +987,7 @@ and list_known_points ?(ignore_private = false) pool conn =
|
|||||||
if P2p_socket.private_node conn.conn then
|
if P2p_socket.private_node conn.conn then
|
||||||
private_node_warn "Private peer (%a) asked other peers addresses"
|
private_node_warn "Private peer (%a) asked other peers addresses"
|
||||||
P2p_peer.Id.pp (P2p_peer_state.Info.peer_id conn.peer_info) >>= fun () ->
|
P2p_peer.Id.pp (P2p_peer_state.Info.peer_id conn.peer_info) >>= fun () ->
|
||||||
Lwt.return []
|
Lwt.return_nil
|
||||||
else
|
else
|
||||||
let knowns =
|
let knowns =
|
||||||
P2p_point.Table.fold
|
P2p_point.Table.fold
|
||||||
|
@ -319,10 +319,10 @@ module Reader = struct
|
|||||||
let open Data_encoding.Binary in
|
let open Data_encoding.Binary in
|
||||||
match status with
|
match status with
|
||||||
| Success { result ; size ; stream } ->
|
| Success { result ; size ; stream } ->
|
||||||
return (Some (result, size, stream))
|
return_some (result, size, stream)
|
||||||
| Error _ ->
|
| Error _ ->
|
||||||
lwt_debug "[read_message] incremental decoding error" >>= fun () ->
|
lwt_debug "[read_message] incremental decoding error" >>= fun () ->
|
||||||
return None
|
return_none
|
||||||
| Await decode_next_buf ->
|
| Await decode_next_buf ->
|
||||||
protect ~canceler:st.canceler begin fun () ->
|
protect ~canceler:st.canceler begin fun () ->
|
||||||
Crypto.read_chunk st.conn.fd st.conn.cryptobox_data
|
Crypto.read_chunk st.conn.fd st.conn.cryptobox_data
|
||||||
@ -341,12 +341,12 @@ module Reader = struct
|
|||||||
| None ->
|
| None ->
|
||||||
protect ~canceler:st.canceler begin fun () ->
|
protect ~canceler:st.canceler begin fun () ->
|
||||||
Lwt_pipe.push st.messages (Error [P2p_errors.Decoding_error]) >>= fun () ->
|
Lwt_pipe.push st.messages (Error [P2p_errors.Decoding_error]) >>= fun () ->
|
||||||
return None
|
return_none
|
||||||
end
|
end
|
||||||
| Some (msg, size, stream) ->
|
| Some (msg, size, stream) ->
|
||||||
protect ~canceler:st.canceler begin fun () ->
|
protect ~canceler:st.canceler begin fun () ->
|
||||||
Lwt_pipe.push st.messages (Ok (size, msg)) >>= fun () ->
|
Lwt_pipe.push st.messages (Ok (size, msg)) >>= fun () ->
|
||||||
return (Some stream)
|
return_some stream
|
||||||
end
|
end
|
||||||
end >>= function
|
end >>= function
|
||||||
| Ok (Some stream) ->
|
| Ok (Some stream) ->
|
||||||
|
@ -141,7 +141,7 @@ let wait_all processes =
|
|||||||
| [] -> loop remaining
|
| [] -> loop remaining
|
||||||
| Ok () :: finished -> handle finished
|
| Ok () :: finished -> handle finished
|
||||||
| Error err :: _ ->
|
| Error err :: _ ->
|
||||||
Lwt.return (Some (err, remaining)) in
|
Lwt.return_some (err, remaining) in
|
||||||
handle finished in
|
handle finished in
|
||||||
loop (List.map (fun p -> p.termination) processes) >>= function
|
loop (List.map (fun p -> p.termination) processes) >>= function
|
||||||
| None ->
|
| None ->
|
||||||
|
@ -37,7 +37,7 @@ let accept main_socket =
|
|||||||
|
|
||||||
let rec accept_n main_socket n =
|
let rec accept_n main_socket n =
|
||||||
if n <= 0 then
|
if n <= 0 then
|
||||||
return []
|
return_nil
|
||||||
else
|
else
|
||||||
accept_n main_socket (n-1) >>=? fun acc ->
|
accept_n main_socket (n-1) >>=? fun acc ->
|
||||||
accept main_socket >>=? fun conn ->
|
accept main_socket >>=? fun conn ->
|
||||||
|
@ -75,6 +75,21 @@ val return : 'a -> 'a tzresult Lwt.t
|
|||||||
(** Sucessful return of [()] *)
|
(** Sucessful return of [()] *)
|
||||||
val return_unit : unit tzresult Lwt.t
|
val return_unit : unit tzresult Lwt.t
|
||||||
|
|
||||||
|
(** Sucessful return of [None] *)
|
||||||
|
val return_none : 'a option tzresult Lwt.t
|
||||||
|
|
||||||
|
(** [return_some x] is a sucessful return of [Some x] *)
|
||||||
|
val return_some : 'a -> 'a option tzresult Lwt.t
|
||||||
|
|
||||||
|
(** Sucessful return of [[]] *)
|
||||||
|
val return_nil : 'a list tzresult Lwt.t
|
||||||
|
|
||||||
|
(** Sucessful return of [true] *)
|
||||||
|
val return_true : bool tzresult Lwt.t
|
||||||
|
|
||||||
|
(** Sucessful return of [false] *)
|
||||||
|
val return_false : bool tzresult Lwt.t
|
||||||
|
|
||||||
(** Erroneous result *)
|
(** Erroneous result *)
|
||||||
val error : error -> 'a tzresult
|
val error : error -> 'a tzresult
|
||||||
|
|
||||||
|
@ -46,23 +46,23 @@ let do_compile hash p =
|
|||||||
end >>= function
|
end >>= function
|
||||||
| Error err ->
|
| Error err ->
|
||||||
log_error "Error %a" pp_print_error err ;
|
log_error "Error %a" pp_print_error err ;
|
||||||
Lwt.return false
|
Lwt.return_false
|
||||||
| Ok (Unix.WSIGNALED _ | Unix.WSTOPPED _) ->
|
| Ok (Unix.WSIGNALED _ | Unix.WSTOPPED _) ->
|
||||||
log_error "INTERRUPTED COMPILATION (%s)" log_file;
|
log_error "INTERRUPTED COMPILATION (%s)" log_file;
|
||||||
Lwt.return false
|
Lwt.return_false
|
||||||
| Ok (Unix.WEXITED x) when x <> 0 ->
|
| Ok (Unix.WEXITED x) when x <> 0 ->
|
||||||
log_error "COMPILATION ERROR (%s)" log_file;
|
log_error "COMPILATION ERROR (%s)" log_file;
|
||||||
Lwt.return false
|
Lwt.return_false
|
||||||
| Ok (Unix.WEXITED _) ->
|
| Ok (Unix.WEXITED _) ->
|
||||||
try Dynlink.loadfile_private (plugin_file ^ ".cmxs"); Lwt.return true
|
try Dynlink.loadfile_private (plugin_file ^ ".cmxs"); Lwt.return_true
|
||||||
with Dynlink.Error err ->
|
with Dynlink.Error err ->
|
||||||
log_error "Can't load plugin: %s (%s)"
|
log_error "Can't load plugin: %s (%s)"
|
||||||
(Dynlink.error_message err) plugin_file;
|
(Dynlink.error_message err) plugin_file;
|
||||||
Lwt.return false
|
Lwt.return_false
|
||||||
|
|
||||||
let compile hash p =
|
let compile hash p =
|
||||||
if Tezos_protocol_registerer.Registerer.mem hash then
|
if Tezos_protocol_registerer.Registerer.mem hash then
|
||||||
Lwt.return true
|
Lwt.return_true
|
||||||
else begin
|
else begin
|
||||||
do_compile hash p >>= fun success ->
|
do_compile hash p >>= fun success ->
|
||||||
let loaded = Tezos_protocol_registerer.Registerer.mem hash in
|
let loaded = Tezos_protocol_registerer.Registerer.mem hash in
|
||||||
|
@ -382,7 +382,7 @@ let validate w
|
|||||||
bv.protocol_validator
|
bv.protocol_validator
|
||||||
?peer ~timeout:bv.limits.protocol_timeout
|
?peer ~timeout:bv.limits.protocol_timeout
|
||||||
block ;
|
block ;
|
||||||
return None
|
return_none
|
||||||
| None ->
|
| None ->
|
||||||
map_p (map_p (fun op ->
|
map_p (map_p (fun op ->
|
||||||
let op_hash = Operation.hash op in
|
let op_hash = Operation.hash op in
|
||||||
|
@ -29,7 +29,7 @@ let head chain_state =
|
|||||||
let mem chain_state hash =
|
let mem chain_state hash =
|
||||||
State.read_chain_data chain_state begin fun chain_store data ->
|
State.read_chain_data chain_state begin fun chain_store data ->
|
||||||
if Block_hash.equal (State.Block.hash data.current_head) hash then
|
if Block_hash.equal (State.Block.hash data.current_head) hash then
|
||||||
Lwt.return true
|
Lwt.return_true
|
||||||
else
|
else
|
||||||
Store.Chain_data.In_main_branch.known (chain_store, hash)
|
Store.Chain_data.In_main_branch.known (chain_store, hash)
|
||||||
end
|
end
|
||||||
|
@ -14,7 +14,7 @@ let path (b1: Block.t) (b2: Block.t) =
|
|||||||
invalid_arg "Chain_traversal.path" ;
|
invalid_arg "Chain_traversal.path" ;
|
||||||
let rec loop acc current =
|
let rec loop acc current =
|
||||||
if Block.equal b1 current then
|
if Block.equal b1 current then
|
||||||
Lwt.return (Some acc)
|
Lwt.return_some acc
|
||||||
else
|
else
|
||||||
Block.predecessor current >>= function
|
Block.predecessor current >>= function
|
||||||
| Some pred -> loop (current :: acc) pred
|
| Some pred -> loop (current :: acc) pred
|
||||||
|
@ -138,7 +138,7 @@ module Operation_hashes_storage = struct
|
|||||||
| None -> Lwt.return_none
|
| None -> Lwt.return_none
|
||||||
| Some b ->
|
| Some b ->
|
||||||
State.Block.operation_hashes b i >>= fun (ops, _) ->
|
State.Block.operation_hashes b i >>= fun (ops, _) ->
|
||||||
Lwt.return (Some ops)
|
Lwt.return_some ops
|
||||||
let read_exn chain_state (h, i) =
|
let read_exn chain_state (h, i) =
|
||||||
State.Block.read_exn chain_state h >>= fun b ->
|
State.Block.read_exn chain_state h >>= fun b ->
|
||||||
State.Block.operation_hashes b i >>= fun (ops, _) ->
|
State.Block.operation_hashes b i >>= fun (ops, _) ->
|
||||||
@ -216,7 +216,7 @@ module Operations_storage = struct
|
|||||||
| None -> Lwt.return_none
|
| None -> Lwt.return_none
|
||||||
| Some b ->
|
| Some b ->
|
||||||
State.Block.operations b i >>= fun (ops, _) ->
|
State.Block.operations b i >>= fun (ops, _) ->
|
||||||
Lwt.return (Some ops)
|
Lwt.return_some ops
|
||||||
let read_exn chain_state (h, i) =
|
let read_exn chain_state (h, i) =
|
||||||
State.Block.read_exn chain_state h >>= fun b ->
|
State.Block.read_exn chain_state h >>= fun b ->
|
||||||
State.Block.operations b i >>= fun (ops, _) ->
|
State.Block.operations b i >>= fun (ops, _) ->
|
||||||
|
@ -135,7 +135,7 @@ end = struct
|
|||||||
let read_opt s k =
|
let read_opt s k =
|
||||||
match Memory_table.find s.memory k with
|
match Memory_table.find s.memory k with
|
||||||
| exception Not_found -> Disk_table.read_opt s.disk k
|
| exception Not_found -> Disk_table.read_opt s.disk k
|
||||||
| Found v -> Lwt.return (Some v)
|
| Found v -> Lwt.return_some v
|
||||||
| Pending _ -> Lwt.return_none
|
| Pending _ -> Lwt.return_none
|
||||||
|
|
||||||
let read_exn s k =
|
let read_exn s k =
|
||||||
@ -528,7 +528,7 @@ end = struct
|
|||||||
param ;
|
param ;
|
||||||
queue = Lwt_pipe.create () ;
|
queue = Lwt_pipe.create () ;
|
||||||
pending = Table.create 17 ;
|
pending = Table.create 17 ;
|
||||||
events = Lwt.return [] ;
|
events = Lwt.return_nil ;
|
||||||
canceler = Lwt_canceler.create () ;
|
canceler = Lwt_canceler.create () ;
|
||||||
worker = Lwt.return_unit ;
|
worker = Lwt.return_unit ;
|
||||||
} in
|
} in
|
||||||
|
@ -29,7 +29,7 @@ let build_rpc_directory validator mainchain_validator =
|
|||||||
Chain.head chain_state >>= fun head ->
|
Chain.head chain_state >>= fun head ->
|
||||||
let head_hash = State.Block.hash head in
|
let head_hash = State.Block.hash head in
|
||||||
let head_header = State.Block.header head in
|
let head_header = State.Block.header head in
|
||||||
Lwt.return (Some (head_hash, head_header.shell.timestamp))
|
Lwt.return_some (head_hash, head_header.shell.timestamp)
|
||||||
end else begin
|
end else begin
|
||||||
Lwt.pick [
|
Lwt.pick [
|
||||||
( Lwt_stream.get block_stream >|=
|
( Lwt_stream.get block_stream >|=
|
||||||
|
@ -81,7 +81,7 @@ let start_prevalidation
|
|||||||
timestamp >>= fun predecessor_context ->
|
timestamp >>= fun predecessor_context ->
|
||||||
begin
|
begin
|
||||||
match protocol_data with
|
match protocol_data with
|
||||||
| None -> return None
|
| None -> return_none
|
||||||
| Some protocol_data ->
|
| Some protocol_data ->
|
||||||
match
|
match
|
||||||
Data_encoding.Binary.of_bytes
|
Data_encoding.Binary.of_bytes
|
||||||
@ -89,7 +89,7 @@ let start_prevalidation
|
|||||||
protocol_data
|
protocol_data
|
||||||
with
|
with
|
||||||
| None -> failwith "Invalid block header"
|
| None -> failwith "Invalid block header"
|
||||||
| Some protocol_data -> return (Some protocol_data)
|
| Some protocol_data -> return_some protocol_data
|
||||||
end >>=? fun protocol_data ->
|
end >>=? fun protocol_data ->
|
||||||
Proto.begin_construction
|
Proto.begin_construction
|
||||||
~predecessor_context
|
~predecessor_context
|
||||||
|
@ -43,7 +43,7 @@ let rec worker_loop bv =
|
|||||||
(* no need to tag 'invalid' protocol on disk,
|
(* no need to tag 'invalid' protocol on disk,
|
||||||
the economic protocol prevents us from
|
the economic protocol prevents us from
|
||||||
being spammed with protocol validation. *)
|
being spammed with protocol validation. *)
|
||||||
return true
|
return_true
|
||||||
end >>=? fun _ ->
|
end >>=? fun _ ->
|
||||||
match wakener with
|
match wakener with
|
||||||
| None ->
|
| None ->
|
||||||
|
@ -674,8 +674,8 @@ module Block = struct
|
|||||||
end
|
end
|
||||||
let read_opt chain_state ?pred hash =
|
let read_opt chain_state ?pred hash =
|
||||||
read chain_state ?pred hash >>= function
|
read chain_state ?pred hash >>= function
|
||||||
| Error _ -> Lwt.return None
|
| Error _ -> Lwt.return_none
|
||||||
| Ok v -> Lwt.return (Some v)
|
| Ok v -> Lwt.return_some v
|
||||||
let read_exn chain_state ?(pred = 0) hash =
|
let read_exn chain_state ?(pred = 0) hash =
|
||||||
Shared.use chain_state.block_store begin fun store ->
|
Shared.use chain_state.block_store begin fun store ->
|
||||||
begin
|
begin
|
||||||
@ -696,8 +696,8 @@ module Block = struct
|
|||||||
return header.shell.predecessor
|
return header.shell.predecessor
|
||||||
let read_predecessor_opt chain_state hash =
|
let read_predecessor_opt chain_state hash =
|
||||||
read_predecessor chain_state hash >>= function
|
read_predecessor chain_state hash >>= function
|
||||||
| Error _ -> Lwt.return None
|
| Error _ -> Lwt.return_none
|
||||||
| Ok v -> Lwt.return (Some v)
|
| Ok v -> Lwt.return_some v
|
||||||
let read_predecessor_exn chain_state hash =
|
let read_predecessor_exn chain_state hash =
|
||||||
read_exn chain_state hash >>= fun { contents = { header } } ->
|
read_exn chain_state hash >>= fun { contents = { header } } ->
|
||||||
Lwt.return header.shell.predecessor
|
Lwt.return header.shell.predecessor
|
||||||
@ -707,7 +707,7 @@ module Block = struct
|
|||||||
Lwt.return_none (* we are at genesis *)
|
Lwt.return_none (* we are at genesis *)
|
||||||
else
|
else
|
||||||
read_exn chain_state header.shell.predecessor >>= fun block ->
|
read_exn chain_state header.shell.predecessor >>= fun block ->
|
||||||
Lwt.return (Some block)
|
Lwt.return_some block
|
||||||
|
|
||||||
let predecessor_n b n =
|
let predecessor_n b n =
|
||||||
Shared.use b.chain_state.block_store begin fun block_store ->
|
Shared.use b.chain_state.block_store begin fun block_store ->
|
||||||
@ -739,7 +739,7 @@ module Block = struct
|
|||||||
fail_when known_invalid (failure "Known invalid") >>=? fun () ->
|
fail_when known_invalid (failure "Known invalid") >>=? fun () ->
|
||||||
Store.Block.Contents.known (store, hash) >>= fun known ->
|
Store.Block.Contents.known (store, hash) >>= fun known ->
|
||||||
if known then
|
if known then
|
||||||
return None
|
return_none
|
||||||
else begin
|
else begin
|
||||||
(* safety check: never ever commit a block that is not compatible
|
(* safety check: never ever commit a block that is not compatible
|
||||||
with the current checkpoint. *)
|
with the current checkpoint. *)
|
||||||
@ -806,7 +806,7 @@ module Block = struct
|
|||||||
let block = { chain_state ; hash ; contents } in
|
let block = { chain_state ; hash ; contents } in
|
||||||
Lwt_watcher.notify chain_state.block_watcher block ;
|
Lwt_watcher.notify chain_state.block_watcher block ;
|
||||||
Lwt_watcher.notify chain_state.global_state.block_watcher block ;
|
Lwt_watcher.notify chain_state.global_state.block_watcher block ;
|
||||||
return (Some block)
|
return_some block
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -818,11 +818,11 @@ module Block = struct
|
|||||||
fail_when known_valid (failure "Known valid") >>=? fun () ->
|
fail_when known_valid (failure "Known valid") >>=? fun () ->
|
||||||
Store.Block.Invalid_block.known store hash >>= fun known_invalid ->
|
Store.Block.Invalid_block.known store hash >>= fun known_invalid ->
|
||||||
if known_invalid then
|
if known_invalid then
|
||||||
return false
|
return_false
|
||||||
else
|
else
|
||||||
Store.Block.Invalid_block.store store hash
|
Store.Block.Invalid_block.store store hash
|
||||||
{ level = block_header.shell.level ; errors } >>= fun () ->
|
{ level = block_header.shell.level ; errors } >>= fun () ->
|
||||||
return true
|
return_true
|
||||||
end
|
end
|
||||||
|
|
||||||
let watcher (state : chain_state) =
|
let watcher (state : chain_state) =
|
||||||
@ -959,7 +959,7 @@ let read_block { global_data } ?pred hash =
|
|||||||
| None ->
|
| None ->
|
||||||
Block.read_opt chain_state ?pred hash >>= function
|
Block.read_opt chain_state ?pred hash >>= function
|
||||||
| None -> acc
|
| None -> acc
|
||||||
| Some block -> Lwt.return (Some block))
|
| Some block -> Lwt.return_some block)
|
||||||
chains
|
chains
|
||||||
Lwt.return_none
|
Lwt.return_none
|
||||||
end
|
end
|
||||||
@ -1079,11 +1079,11 @@ module Protocol = struct
|
|||||||
Shared.use global_state.protocol_store begin fun store ->
|
Shared.use global_state.protocol_store begin fun store ->
|
||||||
Store.Protocol.Contents.known store hash >>= fun known ->
|
Store.Protocol.Contents.known store hash >>= fun known ->
|
||||||
if known then
|
if known then
|
||||||
Lwt.return None
|
Lwt.return_none
|
||||||
else
|
else
|
||||||
Store.Protocol.RawContents.store (store, hash) bytes >>= fun () ->
|
Store.Protocol.RawContents.store (store, hash) bytes >>= fun () ->
|
||||||
Lwt_watcher.notify global_state.protocol_watcher hash ;
|
Lwt_watcher.notify global_state.protocol_watcher hash ;
|
||||||
Lwt.return (Some hash)
|
Lwt.return_some hash
|
||||||
end
|
end
|
||||||
|
|
||||||
let remove global_state hash =
|
let remove global_state hash =
|
||||||
@ -1113,8 +1113,7 @@ module Current_mempool = struct
|
|||||||
let set chain_state ~head mempool =
|
let set chain_state ~head mempool =
|
||||||
update_chain_data chain_state begin fun _chain_data_store data ->
|
update_chain_data chain_state begin fun _chain_data_store data ->
|
||||||
if Block_hash.equal head (Block.hash data.current_head) then
|
if Block_hash.equal head (Block.hash data.current_head) then
|
||||||
Lwt.return (Some { data with current_mempool = mempool },
|
Lwt.return (Some { data with current_mempool = mempool }, ())
|
||||||
())
|
|
||||||
else
|
else
|
||||||
Lwt.return (None, ())
|
Lwt.return (None, ())
|
||||||
end
|
end
|
||||||
|
@ -181,7 +181,7 @@ module Make
|
|||||||
match w.timeout with
|
match w.timeout with
|
||||||
| None ->
|
| None ->
|
||||||
Lwt_pipe.pop message_queue >>= fun m ->
|
Lwt_pipe.pop message_queue >>= fun m ->
|
||||||
return (Some m)
|
return_some m
|
||||||
| Some timeout ->
|
| Some timeout ->
|
||||||
Lwt_pipe.pop_with_timeout
|
Lwt_pipe.pop_with_timeout
|
||||||
(Lwt_unix.sleep timeout) message_queue >>= fun m ->
|
(Lwt_unix.sleep timeout) message_queue >>= fun m ->
|
||||||
@ -193,7 +193,7 @@ module Make
|
|||||||
match w.timeout with
|
match w.timeout with
|
||||||
| None ->
|
| None ->
|
||||||
Lwt_dropbox.take message_box >>= fun m ->
|
Lwt_dropbox.take message_box >>= fun m ->
|
||||||
return (Some m)
|
return_some m
|
||||||
| Some timeout ->
|
| Some timeout ->
|
||||||
Lwt_dropbox.take_with_timeout
|
Lwt_dropbox.take_with_timeout
|
||||||
(Lwt_unix.sleep timeout) message_box >>= fun m ->
|
(Lwt_unix.sleep timeout) message_box >>= fun m ->
|
||||||
|
@ -38,11 +38,11 @@ module Raw = struct
|
|||||||
let encrypted_sk = MBytes.sub encrypted_sk salt_len (len - salt_len) in
|
let encrypted_sk = MBytes.sub encrypted_sk salt_len (len - salt_len) in
|
||||||
let key = Crypto_box.Secretbox.unsafe_of_bytes (pbkdf ~salt ~password) in
|
let key = Crypto_box.Secretbox.unsafe_of_bytes (pbkdf ~salt ~password) in
|
||||||
match Crypto_box.Secretbox.box_open key encrypted_sk nonce with
|
match Crypto_box.Secretbox.box_open key encrypted_sk nonce with
|
||||||
| None -> return None
|
| None -> return_none
|
||||||
| Some bytes ->
|
| Some bytes ->
|
||||||
match Data_encoding.Binary.of_bytes Signature.Secret_key.encoding bytes with
|
match Data_encoding.Binary.of_bytes Signature.Secret_key.encoding bytes with
|
||||||
| None -> failwith "Corrupted wallet, deciphered key is invalid"
|
| None -> failwith "Corrupted wallet, deciphered key is invalid"
|
||||||
| Some sk -> return (Some sk)
|
| Some sk -> return_some sk
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -69,11 +69,11 @@ let rec interactive_decrypt_loop
|
|||||||
return sk
|
return sk
|
||||||
|
|
||||||
let rec noninteractice_decrypt_loop ~encrypted_sk = function
|
let rec noninteractice_decrypt_loop ~encrypted_sk = function
|
||||||
| [] -> return None
|
| [] -> return_none
|
||||||
| password :: passwords ->
|
| password :: passwords ->
|
||||||
Raw.decrypt ~password ~encrypted_sk >>=? function
|
Raw.decrypt ~password ~encrypted_sk >>=? function
|
||||||
| None -> noninteractice_decrypt_loop ~encrypted_sk passwords
|
| None -> noninteractice_decrypt_loop ~encrypted_sk passwords
|
||||||
| Some sk -> return (Some sk)
|
| Some sk -> return_some sk
|
||||||
|
|
||||||
let decrypt_payload cctxt ?name encrypted_sk =
|
let decrypt_payload cctxt ?name encrypted_sk =
|
||||||
match Base58.safe_decode encrypted_sk with
|
match Base58.safe_decode encrypted_sk with
|
||||||
|
@ -98,8 +98,8 @@ module Make(N : sig val scheme : string end) = struct
|
|||||||
P.authenticate
|
P.authenticate
|
||||||
authorized_keys
|
authorized_keys
|
||||||
(Signer_messages.Sign.Request.to_sign ~pkh ~data:msg) >>=? fun signature ->
|
(Signer_messages.Sign.Request.to_sign ~pkh ~data:msg) >>=? fun signature ->
|
||||||
return (Some signature)
|
return_some signature
|
||||||
| None -> return None
|
| None -> return_none
|
||||||
end >>=? fun signature ->
|
end >>=? fun signature ->
|
||||||
RPC_client.call_service
|
RPC_client.call_service
|
||||||
~logger: P.logger
|
~logger: P.logger
|
||||||
|
@ -103,17 +103,17 @@ module Ledger = struct
|
|||||||
(cur_pkh, (pk, curve)) :: of_pkh
|
(cur_pkh, (pk, curve)) :: of_pkh
|
||||||
end (false, [], []) curves in
|
end (false, [], []) curves in
|
||||||
match pkh with
|
match pkh with
|
||||||
| None -> return (Some (create ~device_info ~of_curve ~of_pkh))
|
| None -> return_some (create ~device_info ~of_curve ~of_pkh)
|
||||||
| Some _ when pkh_found ->
|
| Some _ when pkh_found ->
|
||||||
return (Some (create ~device_info ~of_curve ~of_pkh))
|
return_some (create ~device_info ~of_curve ~of_pkh)
|
||||||
| _ -> return None
|
| _ -> return_none
|
||||||
end
|
end
|
||||||
|
|
||||||
let find_ledgers ?pkh () =
|
let find_ledgers ?pkh () =
|
||||||
let ledgers = Hidapi.enumerate ~vendor_id ~product_id () in
|
let ledgers = Hidapi.enumerate ~vendor_id ~product_id () in
|
||||||
filter_map_s begin fun device_info ->
|
filter_map_s begin fun device_info ->
|
||||||
match Hidapi.(open_path device_info.path) with
|
match Hidapi.(open_path device_info.path) with
|
||||||
| None -> return None
|
| None -> return_none
|
||||||
| Some h ->
|
| Some h ->
|
||||||
Lwt.finalize
|
Lwt.finalize
|
||||||
(fun () -> Ledger.of_hidapi ?pkh device_info h)
|
(fun () -> Ledger.of_hidapi ?pkh device_info h)
|
||||||
|
@ -96,16 +96,16 @@ let read_base_uri_from_env () =
|
|||||||
Sys.getenv_opt "TEZOS_SIGNER_TCP_HOST",
|
Sys.getenv_opt "TEZOS_SIGNER_TCP_HOST",
|
||||||
Sys.getenv_opt "TEZOS_SIGNER_HTTP_HOST",
|
Sys.getenv_opt "TEZOS_SIGNER_HTTP_HOST",
|
||||||
Sys.getenv_opt "TEZOS_SIGNER_HTTPS_HOST" with
|
Sys.getenv_opt "TEZOS_SIGNER_HTTPS_HOST" with
|
||||||
| None, None, None, None -> return None
|
| None, None, None, None -> return_none
|
||||||
| Some path, None, None, None ->
|
| Some path, None, None, None ->
|
||||||
return (Some (Socket.make_unix_base path))
|
return_some (Socket.make_unix_base path)
|
||||||
| None, Some host, None, None -> begin
|
| None, Some host, None, None -> begin
|
||||||
try
|
try
|
||||||
let port =
|
let port =
|
||||||
match Sys.getenv_opt "TEZOS_SIGNER_TCP_PORT" with
|
match Sys.getenv_opt "TEZOS_SIGNER_TCP_PORT" with
|
||||||
| None -> 7732
|
| None -> 7732
|
||||||
| Some port -> int_of_string port in
|
| Some port -> int_of_string port in
|
||||||
return (Some (Socket.make_tcp_base host port))
|
return_some (Socket.make_tcp_base host port)
|
||||||
with Invalid_argument _ ->
|
with Invalid_argument _ ->
|
||||||
failwith "Failed to parse TEZOS_SIGNER_TCP_PORT.@."
|
failwith "Failed to parse TEZOS_SIGNER_TCP_PORT.@."
|
||||||
end
|
end
|
||||||
@ -115,7 +115,7 @@ let read_base_uri_from_env () =
|
|||||||
match Sys.getenv_opt "TEZOS_SIGNER_HTTP_PORT" with
|
match Sys.getenv_opt "TEZOS_SIGNER_HTTP_PORT" with
|
||||||
| None -> 6732
|
| None -> 6732
|
||||||
| Some port -> int_of_string port in
|
| Some port -> int_of_string port in
|
||||||
return (Some (Http.make_base host port))
|
return_some (Http.make_base host port)
|
||||||
with Invalid_argument _ ->
|
with Invalid_argument _ ->
|
||||||
failwith "Failed to parse TEZOS_SIGNER_HTTP_PORT.@."
|
failwith "Failed to parse TEZOS_SIGNER_HTTP_PORT.@."
|
||||||
end
|
end
|
||||||
@ -125,7 +125,7 @@ let read_base_uri_from_env () =
|
|||||||
match Sys.getenv_opt "TEZOS_SIGNER_HTTPS_PORT" with
|
match Sys.getenv_opt "TEZOS_SIGNER_HTTPS_PORT" with
|
||||||
| None -> 443
|
| None -> 443
|
||||||
| Some port -> int_of_string port in
|
| Some port -> int_of_string port in
|
||||||
return (Some (Https.make_base host port))
|
return_some (Https.make_base host port)
|
||||||
with Invalid_argument _ ->
|
with Invalid_argument _ ->
|
||||||
failwith "Failed to parse TEZOS_SIGNER_HTTPS_PORT.@."
|
failwith "Failed to parse TEZOS_SIGNER_HTTPS_PORT.@."
|
||||||
end
|
end
|
||||||
|
@ -32,11 +32,11 @@ module Make(P : sig
|
|||||||
Lwt.return authorized_keys >>=? fun authorized_keys ->
|
Lwt.return authorized_keys >>=? fun authorized_keys ->
|
||||||
Lwt_unix.close conn >>= fun () ->
|
Lwt_unix.close conn >>= fun () ->
|
||||||
begin match authorized_keys with
|
begin match authorized_keys with
|
||||||
| No_authentication -> return None
|
| No_authentication -> return_none
|
||||||
| Authorized_keys authorized_keys ->
|
| Authorized_keys authorized_keys ->
|
||||||
P.authenticate authorized_keys
|
P.authenticate authorized_keys
|
||||||
(Sign.Request.to_sign ~pkh ~data:msg) >>=? fun signature ->
|
(Sign.Request.to_sign ~pkh ~data:msg) >>=? fun signature ->
|
||||||
return (Some signature)
|
return_some signature
|
||||||
end
|
end
|
||||||
end >>=? fun signature ->
|
end >>=? fun signature ->
|
||||||
let req = { Sign.Request.pkh ; data = msg ; signature } in
|
let req = { Sign.Request.pkh ; data = msg ; signature } in
|
||||||
|
@ -78,7 +78,7 @@ let rec take_with_timeout timeout dropbox =
|
|||||||
| Some elt ->
|
| Some elt ->
|
||||||
Lwt.cancel timeout ;
|
Lwt.cancel timeout ;
|
||||||
dropbox.data <- None ;
|
dropbox.data <- None ;
|
||||||
Lwt.return (Some elt)
|
Lwt.return_some elt
|
||||||
| None ->
|
| None ->
|
||||||
if Lwt.is_sleeping timeout then
|
if Lwt.is_sleeping timeout then
|
||||||
if dropbox.closed then
|
if dropbox.closed then
|
||||||
|
@ -37,14 +37,14 @@ let blocking_create
|
|||||||
| Some duration -> with_timeout (Lwt_unix.sleep duration) (fun _ -> create ())
|
| Some duration -> with_timeout (Lwt_unix.sleep duration) (fun _ -> create ())
|
||||||
|
|
||||||
let is_locked fn =
|
let is_locked fn =
|
||||||
if not @@ Sys.file_exists fn then return false else
|
if not @@ Sys.file_exists fn then return_false else
|
||||||
protect begin fun () ->
|
protect begin fun () ->
|
||||||
Lwt_unix.openfile fn [Unix.O_RDONLY] 0o644 >>= fun fd ->
|
Lwt_unix.openfile fn [Unix.O_RDONLY] 0o644 >>= fun fd ->
|
||||||
Lwt.finalize (fun () ->
|
Lwt.finalize (fun () ->
|
||||||
Lwt.try_bind
|
Lwt.try_bind
|
||||||
(fun () -> Lwt_unix.(lockf fd F_TEST 0))
|
(fun () -> Lwt_unix.(lockf fd F_TEST 0))
|
||||||
(fun () -> return false)
|
(fun () -> return_false)
|
||||||
(fun _ -> return true))
|
(fun _ -> return_true))
|
||||||
(fun () -> Lwt_unix.close fd)
|
(fun () -> Lwt_unix.close fd)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -102,7 +102,7 @@ let checkout index key =
|
|||||||
| Some commit ->
|
| Some commit ->
|
||||||
GitStore.Commit.tree commit >>= fun tree ->
|
GitStore.Commit.tree commit >>= fun tree ->
|
||||||
let ctxt = { index ; tree ; parents = [commit] } in
|
let ctxt = { index ; tree ; parents = [commit] } in
|
||||||
Lwt.return (Some ctxt)
|
Lwt.return_some ctxt
|
||||||
|
|
||||||
let checkout_exn index key =
|
let checkout_exn index key =
|
||||||
checkout index key >>= function
|
checkout index key >>= function
|
||||||
|
@ -201,7 +201,7 @@ module Make_indexed_substore (S : STORE) (I : INDEX) = struct
|
|||||||
let read_opt s i =
|
let read_opt s i =
|
||||||
read s i >>= function
|
read s i >>= function
|
||||||
| Error _ -> Lwt.return_none
|
| Error _ -> Lwt.return_none
|
||||||
| Ok v -> Lwt.return (Some v)
|
| Ok v -> Lwt.return_some v
|
||||||
let read_exn s i =
|
let read_exn s i =
|
||||||
read s i >>= function
|
read s i >>= function
|
||||||
| Error _ -> Lwt.fail Not_found
|
| Error _ -> Lwt.fail Not_found
|
||||||
@ -305,7 +305,7 @@ module Make_map (S : STORE) (I : INDEX) (V : VALUE) = struct
|
|||||||
let read_opt s i =
|
let read_opt s i =
|
||||||
read s i >>= function
|
read s i >>= function
|
||||||
| Error _ -> Lwt.return_none
|
| Error _ -> Lwt.return_none
|
||||||
| Ok v -> Lwt.return (Some v)
|
| Ok v -> Lwt.return_some v
|
||||||
let read_exn s i =
|
let read_exn s i =
|
||||||
read s i >>= function
|
read s i >>= function
|
||||||
| Error _ -> Lwt.fail Not_found
|
| Error _ -> Lwt.fail Not_found
|
||||||
|
@ -32,8 +32,8 @@ let transfer (cctxt : #Proto_alpha.full)
|
|||||||
begin match arg with
|
begin match arg with
|
||||||
| Some arg ->
|
| Some arg ->
|
||||||
parse_expression arg >>=? fun { expanded = arg } ->
|
parse_expression arg >>=? fun { expanded = arg } ->
|
||||||
return (Some arg)
|
return_some arg
|
||||||
| None -> return None
|
| None -> return_none
|
||||||
end >>=? fun parameters ->
|
end >>=? fun parameters ->
|
||||||
let parameters = Option.map ~f:Script.lazy_expr parameters in
|
let parameters = Option.map ~f:Script.lazy_expr parameters in
|
||||||
let contents = Transaction { amount ; parameters ; destination } in
|
let contents = Transaction { amount ; parameters ; destination } in
|
||||||
|
@ -45,8 +45,8 @@ module ContractAlias = struct
|
|||||||
match Contract.is_implicit c with
|
match Contract.is_implicit c with
|
||||||
| Some hash -> begin
|
| Some hash -> begin
|
||||||
Client_keys.Public_key_hash.rev_find cctxt hash >>=? function
|
Client_keys.Public_key_hash.rev_find cctxt hash >>=? function
|
||||||
| Some name -> return (Some ("key:" ^ name))
|
| Some name -> return_some ("key:" ^ name)
|
||||||
| None -> return None
|
| None -> return_none
|
||||||
end
|
end
|
||||||
| None -> RawContractAlias.rev_find cctxt c
|
| None -> RawContractAlias.rev_find cctxt c
|
||||||
|
|
||||||
|
@ -46,11 +46,11 @@ let preapply (type t)
|
|||||||
| _ -> Signature.Generic_operation in
|
| _ -> Signature.Generic_operation in
|
||||||
begin
|
begin
|
||||||
match src_sk with
|
match src_sk with
|
||||||
| None -> return None
|
| None -> return_none
|
||||||
| Some src_sk ->
|
| Some src_sk ->
|
||||||
Client_keys.sign cctxt
|
Client_keys.sign cctxt
|
||||||
~watermark src_sk bytes >>=? fun signature ->
|
~watermark src_sk bytes >>=? fun signature ->
|
||||||
return (Some signature)
|
return_some signature
|
||||||
end >>=? fun signature ->
|
end >>=? fun signature ->
|
||||||
let op : _ Operation.t =
|
let op : _ Operation.t =
|
||||||
{ shell = { branch } ;
|
{ shell = { branch } ;
|
||||||
|
@ -35,9 +35,9 @@ let report_michelson_errors ?(no_print_source=false) ~msg (cctxt : #Client_conte
|
|||||||
~show_source: (not no_print_source)
|
~show_source: (not no_print_source)
|
||||||
?parsed:None) errs >>= fun () ->
|
?parsed:None) errs >>= fun () ->
|
||||||
cctxt#error "%s" msg >>= fun () ->
|
cctxt#error "%s" msg >>= fun () ->
|
||||||
Lwt.return None
|
Lwt.return_none
|
||||||
| Ok data ->
|
| Ok data ->
|
||||||
Lwt.return (Some data)
|
Lwt.return_some data
|
||||||
|
|
||||||
let file_parameter =
|
let file_parameter =
|
||||||
Clic.parameter (fun _ p ->
|
Clic.parameter (fun _ p ->
|
||||||
|
@ -66,7 +66,7 @@ let blocks_from_current_cycle cctxt ?(chain = `Main) block ?(offset = 0l) () =
|
|||||||
Alpha_services.Helpers.levels_in_current_cycle
|
Alpha_services.Helpers.levels_in_current_cycle
|
||||||
cctxt ~offset (chain, block) >>= function
|
cctxt ~offset (chain, block) >>= function
|
||||||
| Error [RPC_context.Not_found _] ->
|
| Error [RPC_context.Not_found _] ->
|
||||||
return []
|
return_nil
|
||||||
| Error _ as err -> Lwt.return err
|
| Error _ as err -> Lwt.return err
|
||||||
| Ok (first, last) ->
|
| Ok (first, last) ->
|
||||||
let length = Int32.to_int (Int32.sub level (Raw_level.to_int32 first)) in
|
let length = Int32.to_int (Int32.sub level (Raw_level.to_int32 first)) in
|
||||||
|
@ -19,8 +19,8 @@ let get_signing_slots cctxt ?(chain = `Main) block delegate level =
|
|||||||
~levels:[level]
|
~levels:[level]
|
||||||
~delegates:[delegate]
|
~delegates:[delegate]
|
||||||
(chain, block) >>=? function
|
(chain, block) >>=? function
|
||||||
| [{ slots }] -> return (Some slots)
|
| [{ slots }] -> return_some slots
|
||||||
| _ -> return None
|
| _ -> return_none
|
||||||
|
|
||||||
let inject_endorsement
|
let inject_endorsement
|
||||||
(cctxt : #Proto_alpha.full)
|
(cctxt : #Proto_alpha.full)
|
||||||
@ -48,7 +48,7 @@ let check_endorsement cctxt level pkh =
|
|||||||
|
|
||||||
let previously_endorsed_level cctxt pkh new_lvl =
|
let previously_endorsed_level cctxt pkh new_lvl =
|
||||||
State.get cctxt pkh >>=? function
|
State.get cctxt pkh >>=? function
|
||||||
| None -> return false
|
| None -> return_false
|
||||||
| Some last_lvl ->
|
| Some last_lvl ->
|
||||||
return (Raw_level.(last_lvl >= new_lvl))
|
return (Raw_level.(last_lvl >= new_lvl))
|
||||||
|
|
||||||
@ -128,7 +128,7 @@ let allowed_to_endorse cctxt bi delegate =
|
|||||||
| None | Some [] ->
|
| None | Some [] ->
|
||||||
lwt_debug "No slot found for %a/%s"
|
lwt_debug "No slot found for %a/%s"
|
||||||
Block_hash.pp_short bi.hash name >>= fun () ->
|
Block_hash.pp_short bi.hash name >>= fun () ->
|
||||||
return false
|
return_false
|
||||||
| Some (_ :: _ as slots) ->
|
| Some (_ :: _ as slots) ->
|
||||||
lwt_debug "Found slots for %a/%s (%d)"
|
lwt_debug "Found slots for %a/%s (%d)"
|
||||||
Block_hash.pp_short bi.hash name (List.length slots) >>= fun () ->
|
Block_hash.pp_short bi.hash name (List.length slots) >>= fun () ->
|
||||||
@ -136,9 +136,9 @@ let allowed_to_endorse cctxt bi delegate =
|
|||||||
| true ->
|
| true ->
|
||||||
lwt_debug "Level %a (or higher) previously endorsed: do not endorse."
|
lwt_debug "Level %a (or higher) previously endorsed: do not endorse."
|
||||||
Raw_level.pp level >>= fun () ->
|
Raw_level.pp level >>= fun () ->
|
||||||
return false
|
return_false
|
||||||
| false ->
|
| false ->
|
||||||
return true
|
return_true
|
||||||
|
|
||||||
let prepare_endorsement ~(max_past:int64) () (cctxt : #Proto_alpha.full) state bi =
|
let prepare_endorsement ~(max_past:int64) () (cctxt : #Proto_alpha.full) state bi =
|
||||||
if Time.diff (Time.now ()) bi.Client_baking_blocks.timestamp > max_past then
|
if Time.diff (Time.now ()) bi.Client_baking_blocks.timestamp > max_past then
|
||||||
|
@ -146,9 +146,9 @@ let sort_operations_by_fee ?(threshold = Tez.zero) (operations : Proto_alpha.ope
|
|||||||
(fun op ->
|
(fun op ->
|
||||||
get_operation_fee op >>=? fun fee ->
|
get_operation_fee op >>=? fun fee ->
|
||||||
if Tez.(<) fee threshold then
|
if Tez.(<) fee threshold then
|
||||||
return None
|
return_none
|
||||||
else
|
else
|
||||||
return (Some (op, fee)))
|
return_some (op, fee))
|
||||||
operations >>=? fun operations ->
|
operations >>=? fun operations ->
|
||||||
let compare_fee (_, fee1) (_, fee2) =
|
let compare_fee (_, fee1) (_, fee2) =
|
||||||
(* NOTE: inverted fee comparison to invert the order of sort *)
|
(* NOTE: inverted fee comparison to invert the order of sort *)
|
||||||
@ -354,7 +354,7 @@ module State = Daemon_state.Make(struct let name = "block" end)
|
|||||||
|
|
||||||
let previously_baked_level cctxt pkh new_lvl =
|
let previously_baked_level cctxt pkh new_lvl =
|
||||||
State.get cctxt pkh >>=? function
|
State.get cctxt pkh >>=? function
|
||||||
| None -> return false
|
| None -> return_false
|
||||||
| Some last_lvl ->
|
| Some last_lvl ->
|
||||||
return (Raw_level.(last_lvl >= new_lvl))
|
return (Raw_level.(last_lvl >= new_lvl))
|
||||||
|
|
||||||
@ -371,11 +371,11 @@ let get_baking_slot cctxt
|
|||||||
| Error errs ->
|
| Error errs ->
|
||||||
lwt_log_error "Error while fetching baking possibilities:\n%a"
|
lwt_log_error "Error while fetching baking possibilities:\n%a"
|
||||||
pp_print_error errs >>= fun () ->
|
pp_print_error errs >>= fun () ->
|
||||||
Lwt.return []
|
Lwt.return_nil
|
||||||
| Ok [] ->
|
| Ok [] ->
|
||||||
lwt_log_info "Found no baking rights for level %a"
|
lwt_log_info "Found no baking rights for level %a"
|
||||||
Raw_level.pp level >>= fun () ->
|
Raw_level.pp level >>= fun () ->
|
||||||
Lwt.return []
|
Lwt.return_nil
|
||||||
| Ok slots ->
|
| Ok slots ->
|
||||||
let slots =
|
let slots =
|
||||||
List.filter_map
|
List.filter_map
|
||||||
@ -419,12 +419,12 @@ let get_unrevealed_nonces
|
|||||||
cctxt block ~offset:(-1l) () >>=? fun blocks ->
|
cctxt block ~offset:(-1l) () >>=? fun blocks ->
|
||||||
filter_map_s (fun hash ->
|
filter_map_s (fun hash ->
|
||||||
Client_baking_nonces.find cctxt hash >>=? function
|
Client_baking_nonces.find cctxt hash >>=? function
|
||||||
| None -> return None
|
| None -> return_none
|
||||||
| Some nonce ->
|
| Some nonce ->
|
||||||
Alpha_block_services.metadata
|
Alpha_block_services.metadata
|
||||||
cctxt ~chain ~block:(`Hash (hash, 0)) () >>=? fun { protocol_data = { level } } ->
|
cctxt ~chain ~block:(`Hash (hash, 0)) () >>=? fun { protocol_data = { level } } ->
|
||||||
if force then
|
if force then
|
||||||
return (Some (hash, (level.level, nonce)))
|
return_some (hash, (level.level, nonce))
|
||||||
else
|
else
|
||||||
Alpha_services.Nonce.get
|
Alpha_services.Nonce.get
|
||||||
cctxt (chain, block) level.level >>=? function
|
cctxt (chain, block) level.level >>=? function
|
||||||
@ -433,13 +433,13 @@ let get_unrevealed_nonces
|
|||||||
cctxt#warning "Found nonce for %a (level: %a)@."
|
cctxt#warning "Found nonce for %a (level: %a)@."
|
||||||
Block_hash.pp_short hash
|
Block_hash.pp_short hash
|
||||||
Level.pp level >>= fun () ->
|
Level.pp level >>= fun () ->
|
||||||
return (Some (hash, (level.level, nonce)))
|
return_some (hash, (level.level, nonce))
|
||||||
| Missing _nonce_hash ->
|
| Missing _nonce_hash ->
|
||||||
cctxt#error "Incoherent nonce for level %a"
|
cctxt#error "Incoherent nonce for level %a"
|
||||||
Raw_level.pp level.level >>= fun () ->
|
Raw_level.pp level.level >>= fun () ->
|
||||||
return None
|
return_none
|
||||||
| Forgotten -> return None
|
| Forgotten -> return_none
|
||||||
| Revealed _ -> return None)
|
| Revealed _ -> return_none)
|
||||||
blocks
|
blocks
|
||||||
|
|
||||||
let safe_get_unrevealed_nonces cctxt block =
|
let safe_get_unrevealed_nonces cctxt block =
|
||||||
@ -447,7 +447,7 @@ let safe_get_unrevealed_nonces cctxt block =
|
|||||||
| Ok r -> Lwt.return r
|
| Ok r -> Lwt.return r
|
||||||
| Error err ->
|
| Error err ->
|
||||||
lwt_warn "Cannot read nonces: %a@." pp_print_error err >>= fun () ->
|
lwt_warn "Cannot read nonces: %a@." pp_print_error err >>= fun () ->
|
||||||
Lwt.return []
|
Lwt.return_nil
|
||||||
|
|
||||||
let insert_block
|
let insert_block
|
||||||
?max_priority
|
?max_priority
|
||||||
@ -521,8 +521,8 @@ let filter_invalid_operations (cctxt : #full) state block_info (operations : pac
|
|||||||
Operation_hash.pp (Operation.hash_packed op)
|
Operation_hash.pp (Operation.hash_packed op)
|
||||||
pp_print_error errs
|
pp_print_error errs
|
||||||
>>= fun () ->
|
>>= fun () ->
|
||||||
return None
|
return_none
|
||||||
| Ok inc -> return (Some inc)
|
| Ok inc -> return_some inc
|
||||||
in
|
in
|
||||||
let filter_valid_operations inc ops =
|
let filter_valid_operations inc ops =
|
||||||
fold_left_s (fun (inc, acc) op ->
|
fold_left_s (fun (inc, acc) op ->
|
||||||
@ -534,10 +534,10 @@ let filter_invalid_operations (cctxt : #full) state block_info (operations : pac
|
|||||||
(* Invalid endorsements are detected during block finalization *)
|
(* Invalid endorsements are detected during block finalization *)
|
||||||
let is_valid_endorsement inc endorsement =
|
let is_valid_endorsement inc endorsement =
|
||||||
validate_operation inc endorsement >>=? function
|
validate_operation inc endorsement >>=? function
|
||||||
| None -> return None
|
| None -> return_none
|
||||||
| Some inc' -> finalize_construction inc' >>= begin function
|
| Some inc' -> finalize_construction inc' >>= begin function
|
||||||
| Ok _ -> return (Some endorsement)
|
| Ok _ -> return_some endorsement
|
||||||
| Error _ -> return None
|
| Error _ -> return_none
|
||||||
end
|
end
|
||||||
in
|
in
|
||||||
filter_valid_operations initial_inc votes >>=? fun (inc, votes) ->
|
filter_valid_operations initial_inc votes >>=? fun (inc, votes) ->
|
||||||
@ -613,7 +613,7 @@ let bake_slot
|
|||||||
lwt_log_error "Client-side validation: error while filtering invalid operations :@\n%a"
|
lwt_log_error "Client-side validation: error while filtering invalid operations :@\n%a"
|
||||||
pp_print_error
|
pp_print_error
|
||||||
errs >>= fun () ->
|
errs >>= fun () ->
|
||||||
return None
|
return_none
|
||||||
| Ok operations ->
|
| Ok operations ->
|
||||||
Alpha_block_services.Helpers.Preapply.block
|
Alpha_block_services.Helpers.Preapply.block
|
||||||
cctxt ~chain ~block
|
cctxt ~chain ~block
|
||||||
@ -623,7 +623,7 @@ let bake_slot
|
|||||||
lwt_log_error "Error while prevalidating operations:@\n%a"
|
lwt_log_error "Error while prevalidating operations:@\n%a"
|
||||||
pp_print_error
|
pp_print_error
|
||||||
errs >>= fun () ->
|
errs >>= fun () ->
|
||||||
return None
|
return_none
|
||||||
| Ok (shell_header, operations) ->
|
| Ok (shell_header, operations) ->
|
||||||
lwt_debug
|
lwt_debug
|
||||||
"Computed candidate block after %a (slot %d): %a/%d fitness: %a"
|
"Computed candidate block after %a (slot %d): %a/%d fitness: %a"
|
||||||
|
@ -87,7 +87,7 @@ let reveal_block_nonces (cctxt : #Proto_alpha.full) block_hashes =
|
|||||||
Lwt.catch
|
Lwt.catch
|
||||||
(fun () ->
|
(fun () ->
|
||||||
Client_baking_blocks.info cctxt (`Hash (hash, 0)) >>= function
|
Client_baking_blocks.info cctxt (`Hash (hash, 0)) >>= function
|
||||||
| Ok bi -> Lwt.return (Some bi)
|
| Ok bi -> Lwt.return_some bi
|
||||||
| Error _ ->
|
| Error _ ->
|
||||||
Lwt.fail Not_found)
|
Lwt.fail Not_found)
|
||||||
(fun _ ->
|
(fun _ ->
|
||||||
@ -101,9 +101,9 @@ let reveal_block_nonces (cctxt : #Proto_alpha.full) block_hashes =
|
|||||||
| None ->
|
| None ->
|
||||||
cctxt#warning "Cannot find nonces for block %a (ignoring)@."
|
cctxt#warning "Cannot find nonces for block %a (ignoring)@."
|
||||||
Block_hash.pp_short bi.hash >>= fun () ->
|
Block_hash.pp_short bi.hash >>= fun () ->
|
||||||
return None
|
return_none
|
||||||
| Some nonce ->
|
| Some nonce ->
|
||||||
return (Some (bi.hash, (bi.level, nonce))))
|
return_some (bi.hash, (bi.level, nonce)))
|
||||||
block_infos >>=? fun blocks ->
|
block_infos >>=? fun blocks ->
|
||||||
do_reveal cctxt cctxt#block blocks
|
do_reveal cctxt cctxt#block blocks
|
||||||
|
|
||||||
|
@ -565,7 +565,7 @@ module Endorse = struct
|
|||||||
!rpc_ctxt ~delegates:[delegate] ~levels:[level]
|
!rpc_ctxt ~delegates:[delegate] ~levels:[level]
|
||||||
(`Main, block) >>=? function
|
(`Main, block) >>=? function
|
||||||
| [{ slots }] -> return slots
|
| [{ slots }] -> return slots
|
||||||
| _ -> return []
|
| _ -> return_nil
|
||||||
|
|
||||||
let endorse
|
let endorse
|
||||||
(contract : Account.t)
|
(contract : Account.t)
|
||||||
@ -606,7 +606,7 @@ module Endorse = struct
|
|||||||
~delegates:[delegate]
|
~delegates:[delegate]
|
||||||
(`Main, block) >>=? function
|
(`Main, block) >>=? function
|
||||||
| [{ level ; slots }] -> return (List.map (fun s -> (level, s)) slots)
|
| [{ level ; slots }] -> return (List.map (fun s -> (level, s)) slots)
|
||||||
| _ -> return []
|
| _ -> return_nil
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -275,6 +275,6 @@ let last_of_a_cycle ctxt l =
|
|||||||
let dawn_of_a_new_cycle ctxt =
|
let dawn_of_a_new_cycle ctxt =
|
||||||
let level = Level.current ctxt in
|
let level = Level.current ctxt in
|
||||||
if last_of_a_cycle ctxt level then
|
if last_of_a_cycle ctxt level then
|
||||||
return (Some level.cycle)
|
return_some level.cycle
|
||||||
else
|
else
|
||||||
return None
|
return_none
|
||||||
|
@ -163,14 +163,14 @@ let register () =
|
|||||||
register_opt_field S.storage (fun ctxt contract ->
|
register_opt_field S.storage (fun ctxt contract ->
|
||||||
Contract.get_script ctxt contract >>=? fun (ctxt, script) ->
|
Contract.get_script ctxt contract >>=? fun (ctxt, script) ->
|
||||||
match script with
|
match script with
|
||||||
| None -> return None
|
| None -> return_none
|
||||||
| Some script ->
|
| Some script ->
|
||||||
let ctxt = Gas.set_unlimited ctxt in
|
let ctxt = Gas.set_unlimited ctxt in
|
||||||
let open Script_ir_translator in
|
let open Script_ir_translator in
|
||||||
parse_script ctxt script >>=? fun (Ex_script script, ctxt) ->
|
parse_script ctxt script >>=? fun (Ex_script script, ctxt) ->
|
||||||
unparse_script ctxt Readable script >>=? fun (script, _ctxt) ->
|
unparse_script ctxt Readable script >>=? fun (script, _ctxt) ->
|
||||||
Lwt.return (Script.force_decode script.storage) >>=? fun storage ->
|
Lwt.return (Script.force_decode script.storage) >>=? fun storage ->
|
||||||
return (Some storage)) ;
|
return_some storage) ;
|
||||||
register_field S.info (fun ctxt contract ->
|
register_field S.info (fun ctxt contract ->
|
||||||
Contract.get_balance ctxt contract >>=? fun balance ->
|
Contract.get_balance ctxt contract >>=? fun balance ->
|
||||||
Contract.get_manager ctxt contract >>=? fun manager ->
|
Contract.get_manager ctxt contract >>=? fun manager ->
|
||||||
|
@ -275,12 +275,12 @@ let delete c contract =
|
|||||||
|
|
||||||
let allocated c contract =
|
let allocated c contract =
|
||||||
Storage.Contract.Counter.get_option c contract >>=? function
|
Storage.Contract.Counter.get_option c contract >>=? function
|
||||||
| None -> return false
|
| None -> return_false
|
||||||
| Some _ -> return true
|
| Some _ -> return_true
|
||||||
|
|
||||||
let exists c contract =
|
let exists c contract =
|
||||||
match Contract_repr.is_implicit contract with
|
match Contract_repr.is_implicit contract with
|
||||||
| Some _ -> return true
|
| Some _ -> return_true
|
||||||
| None -> allocated c contract
|
| None -> allocated c contract
|
||||||
|
|
||||||
let must_exist c contract =
|
let must_exist c contract =
|
||||||
@ -307,8 +307,8 @@ let originated_from_current_nonce ~since: ctxt_since ~until: ctxt_until =
|
|||||||
Lwt.return (Raw_context.origination_nonce ctxt_until) >>=? fun until ->
|
Lwt.return (Raw_context.origination_nonce ctxt_until) >>=? fun until ->
|
||||||
filter_map_s
|
filter_map_s
|
||||||
(fun contract -> exists ctxt_until contract >>=? function
|
(fun contract -> exists ctxt_until contract >>=? function
|
||||||
| true -> return (Some contract)
|
| true -> return_some contract
|
||||||
| false -> return None)
|
| false -> return_none)
|
||||||
(Contract_repr.originated_contracts ~since ~until)
|
(Contract_repr.originated_contracts ~since ~until)
|
||||||
|
|
||||||
let check_counter_increment c contract counter =
|
let check_counter_increment c contract counter =
|
||||||
@ -369,9 +369,9 @@ let get_manager_key c contract =
|
|||||||
|
|
||||||
let is_manager_key_revealed c contract =
|
let is_manager_key_revealed c contract =
|
||||||
Storage.Contract.Manager.get_option c contract >>=? function
|
Storage.Contract.Manager.get_option c contract >>=? function
|
||||||
| None -> return false
|
| None -> return_false
|
||||||
| Some (Manager_repr.Hash _) -> return false
|
| Some (Manager_repr.Hash _) -> return_false
|
||||||
| Some (Manager_repr.Public_key _) -> return true
|
| Some (Manager_repr.Public_key _) -> return_true
|
||||||
|
|
||||||
let reveal_manager_key c contract public_key =
|
let reveal_manager_key c contract public_key =
|
||||||
Storage.Contract.Manager.get c contract >>=? function
|
Storage.Contract.Manager.get c contract >>=? function
|
||||||
@ -396,7 +396,7 @@ let get_balance c contract =
|
|||||||
let is_delegatable = Delegate_storage.is_delegatable
|
let is_delegatable = Delegate_storage.is_delegatable
|
||||||
let is_spendable c contract =
|
let is_spendable c contract =
|
||||||
match Contract_repr.is_implicit contract with
|
match Contract_repr.is_implicit contract with
|
||||||
| Some _ -> return true
|
| Some _ -> return_true
|
||||||
| None ->
|
| None ->
|
||||||
Storage.Contract.Spendable.mem c contract >>= return
|
Storage.Contract.Spendable.mem c contract >>= return
|
||||||
|
|
||||||
|
@ -175,7 +175,7 @@ let register () =
|
|||||||
(fun pkh -> Delegate.deactivated ctxt pkh)
|
(fun pkh -> Delegate.deactivated ctxt pkh)
|
||||||
delegates >>= return
|
delegates >>= return
|
||||||
else
|
else
|
||||||
return []
|
return_nil
|
||||||
end ;
|
end ;
|
||||||
register1 S.info begin fun ctxt pkh () () ->
|
register1 S.info begin fun ctxt pkh () () ->
|
||||||
Delegate.full_balance ctxt pkh >>=? fun balance ->
|
Delegate.full_balance ctxt pkh >>=? fun balance ->
|
||||||
@ -354,10 +354,10 @@ module Baking_rights = struct
|
|||||||
let delegate = Signature.Public_key.hash pk in
|
let delegate = Signature.Public_key.hash pk in
|
||||||
begin
|
begin
|
||||||
match pred_timestamp with
|
match pred_timestamp with
|
||||||
| None -> return None
|
| None -> return_none
|
||||||
| Some pred_timestamp ->
|
| Some pred_timestamp ->
|
||||||
Baking.minimal_time ctxt priority pred_timestamp >>=? fun t ->
|
Baking.minimal_time ctxt priority pred_timestamp >>=? fun t ->
|
||||||
return (Some t)
|
return_some t
|
||||||
end>>=? fun timestamp ->
|
end>>=? fun timestamp ->
|
||||||
let acc =
|
let acc =
|
||||||
{ level = level.level ; delegate ; priority ; timestamp } :: acc in
|
{ level = level.level ; delegate ; priority ; timestamp } :: acc in
|
||||||
|
@ -116,7 +116,7 @@ let () =
|
|||||||
let is_delegatable c contract =
|
let is_delegatable c contract =
|
||||||
match Contract_repr.is_implicit contract with
|
match Contract_repr.is_implicit contract with
|
||||||
| Some _ ->
|
| Some _ ->
|
||||||
return false
|
return_false
|
||||||
| None ->
|
| None ->
|
||||||
Storage.Contract.Delegatable.mem c contract >>= return
|
Storage.Contract.Delegatable.mem c contract >>= return
|
||||||
|
|
||||||
@ -144,8 +144,8 @@ let unlink c contract balance =
|
|||||||
let known c delegate =
|
let known c delegate =
|
||||||
Storage.Contract.Manager.get_option
|
Storage.Contract.Manager.get_option
|
||||||
c (Contract_repr.implicit_contract delegate) >>=? function
|
c (Contract_repr.implicit_contract delegate) >>=? function
|
||||||
| None | Some (Manager_repr.Hash _) -> return false
|
| None | Some (Manager_repr.Hash _) -> return_false
|
||||||
| Some (Manager_repr.Public_key _) -> return true
|
| Some (Manager_repr.Public_key _) -> return_true
|
||||||
|
|
||||||
(* A delegate is registered if its "implicit account"
|
(* A delegate is registered if its "implicit account"
|
||||||
delegates to itself. *)
|
delegates to itself. *)
|
||||||
@ -223,7 +223,7 @@ let set c contract delegate =
|
|||||||
set_base c is_delegatable contract delegate
|
set_base c is_delegatable contract delegate
|
||||||
|
|
||||||
let set_from_script c contract delegate =
|
let set_from_script c contract delegate =
|
||||||
set_base c (fun _ _ -> return true) contract delegate
|
set_base c (fun _ _ -> return_true) contract delegate
|
||||||
|
|
||||||
let remove ctxt contract =
|
let remove ctxt contract =
|
||||||
Storage.Contract.Balance.get ctxt contract >>=? fun balance ->
|
Storage.Contract.Balance.get ctxt contract >>=? fun balance ->
|
||||||
@ -386,10 +386,10 @@ let punish ctxt delegate cycle =
|
|||||||
let has_frozen_balance ctxt delegate cycle =
|
let has_frozen_balance ctxt delegate cycle =
|
||||||
let contract = Contract_repr.implicit_contract delegate in
|
let contract = Contract_repr.implicit_contract delegate in
|
||||||
get_frozen_deposit ctxt contract cycle >>=? fun deposit ->
|
get_frozen_deposit ctxt contract cycle >>=? fun deposit ->
|
||||||
if Tez_repr.(deposit <> zero) then return true
|
if Tez_repr.(deposit <> zero) then return_true
|
||||||
else
|
else
|
||||||
get_frozen_fees ctxt contract cycle >>=? fun fees ->
|
get_frozen_fees ctxt contract cycle >>=? fun fees ->
|
||||||
if Tez_repr.(fees <> zero) then return true
|
if Tez_repr.(fees <> zero) then return_true
|
||||||
else
|
else
|
||||||
get_frozen_rewards ctxt contract cycle >>=? fun rewards ->
|
get_frozen_rewards ctxt contract cycle >>=? fun rewards ->
|
||||||
return Tez_repr.(rewards <> zero)
|
return Tez_repr.(rewards <> zero)
|
||||||
|
@ -175,7 +175,7 @@ let traverse_rolls ctxt head =
|
|||||||
|
|
||||||
let get_rolls ctxt delegate =
|
let get_rolls ctxt delegate =
|
||||||
Storage.Roll.Delegate_roll_list.get_option ctxt delegate >>=? function
|
Storage.Roll.Delegate_roll_list.get_option ctxt delegate >>=? function
|
||||||
| None -> return []
|
| None -> return_nil
|
||||||
| Some head_roll -> traverse_rolls ctxt head_roll
|
| Some head_roll -> traverse_rolls ctxt head_roll
|
||||||
|
|
||||||
let get_change c delegate =
|
let get_change c delegate =
|
||||||
|
@ -96,7 +96,7 @@ let unparse_stack ctxt (stack, stack_ty) =
|
|||||||
let rec unparse_stack
|
let rec unparse_stack
|
||||||
: type a. a stack * a stack_ty -> (Script.expr * string option) list tzresult Lwt.t
|
: type a. a stack * a stack_ty -> (Script.expr * string option) list tzresult Lwt.t
|
||||||
= function
|
= function
|
||||||
| Empty, Empty_t -> return []
|
| Empty, Empty_t -> return_nil
|
||||||
| Item (v, rest), Item_t (ty, rest_ty, annot) ->
|
| Item (v, rest), Item_t (ty, rest_ty, annot) ->
|
||||||
unparse_data ctxt Readable ty v >>=? fun (data, _ctxt) ->
|
unparse_data ctxt Readable ty v >>=? fun (data, _ctxt) ->
|
||||||
unparse_stack (rest, rest_ty) >>=? fun rest ->
|
unparse_stack (rest, rest_ty) >>=? fun rest ->
|
||||||
|
@ -216,13 +216,13 @@ let build_directory : type key. key t -> key RPC_directory.t =
|
|||||||
fun dir path ->
|
fun dir path ->
|
||||||
match !dir with
|
match !dir with
|
||||||
| Empty -> Opt_handler { encoding = Data_encoding.unit ;
|
| Empty -> Opt_handler { encoding = Data_encoding.unit ;
|
||||||
get = fun _ _ -> return None }
|
get = fun _ _ -> return_none }
|
||||||
| Value { get ; encoding } ->
|
| Value { get ; encoding } ->
|
||||||
let handler =
|
let handler =
|
||||||
Opt_handler {
|
Opt_handler {
|
||||||
encoding ;
|
encoding ;
|
||||||
get =
|
get =
|
||||||
fun k i -> if Compare.Int.(i < 0) then return None else get k
|
fun k i -> if Compare.Int.(i < 0) then return_none else get k
|
||||||
} in
|
} in
|
||||||
register path handler ;
|
register path handler ;
|
||||||
handler
|
handler
|
||||||
@ -239,10 +239,10 @@ let build_directory : type key. key t -> key RPC_directory.t =
|
|||||||
{ encoding = handler.encoding ;
|
{ encoding = handler.encoding ;
|
||||||
get = fun k i ->
|
get = fun k i ->
|
||||||
if Compare.Int.(i < 0) then
|
if Compare.Int.(i < 0) then
|
||||||
return None
|
return_none
|
||||||
else
|
else
|
||||||
handler.get k (i-1) >>=? fun v ->
|
handler.get k (i-1) >>=? fun v ->
|
||||||
return (Some v) } in
|
return_some v } in
|
||||||
register path handler ;
|
register path handler ;
|
||||||
handler
|
handler
|
||||||
| IndexedDir { arg ; arg_encoding ; list ; subdir } ->
|
| IndexedDir { arg ; arg_encoding ; list ; subdir } ->
|
||||||
@ -265,8 +265,8 @@ let build_directory : type key. key t -> key RPC_directory.t =
|
|||||||
(fun (key, value) -> (key, Some value)) ;
|
(fun (key, value) -> (key, Some value)) ;
|
||||||
] in
|
] in
|
||||||
let get k i =
|
let get k i =
|
||||||
if Compare.Int.(i < 0) then return None
|
if Compare.Int.(i < 0) then return_none
|
||||||
else if Compare.Int.(i = 0) then return (Some [])
|
else if Compare.Int.(i = 0) then return_some []
|
||||||
else
|
else
|
||||||
list k >>=? fun keys ->
|
list k >>=? fun keys ->
|
||||||
map_p
|
map_p
|
||||||
@ -277,7 +277,7 @@ let build_directory : type key. key t -> key RPC_directory.t =
|
|||||||
handler.get (k, key) (i-1) >>=? fun value ->
|
handler.get (k, key) (i-1) >>=? fun value ->
|
||||||
return (key, value))
|
return (key, value))
|
||||||
keys >>=? fun values ->
|
keys >>=? fun values ->
|
||||||
return (Some values) in
|
return_some values in
|
||||||
let handler =
|
let handler =
|
||||||
Opt_handler {
|
Opt_handler {
|
||||||
encoding = Data_encoding.(list (dynamic_size encoding)) ;
|
encoding = Data_encoding.(list (dynamic_size encoding)) ;
|
||||||
|
@ -85,11 +85,11 @@ module Make_single_data_storage (C : Raw_context.T) (N : NAME) (V : VALUE)
|
|||||||
Lwt.return (of_bytes ~key b)
|
Lwt.return (of_bytes ~key b)
|
||||||
let get_option t =
|
let get_option t =
|
||||||
C.get_option t N.name >>= function
|
C.get_option t N.name >>= function
|
||||||
| None -> return None
|
| None -> return_none
|
||||||
| Some b ->
|
| Some b ->
|
||||||
let key = C.absolute_key t N.name in
|
let key = C.absolute_key t N.name in
|
||||||
match of_bytes ~key b with
|
match of_bytes ~key b with
|
||||||
| Ok v -> return (Some v)
|
| Ok v -> return_some v
|
||||||
| Error _ as err -> Lwt.return err
|
| Error _ as err -> Lwt.return err
|
||||||
let init t v =
|
let init t v =
|
||||||
C.init t N.name (to_bytes v) >>=? fun t ->
|
C.init t N.name (to_bytes v) >>=? fun t ->
|
||||||
@ -200,8 +200,8 @@ module Make_data_set_storage (C : Raw_context.T) (I : INDEX)
|
|||||||
~get:(fun c ->
|
~get:(fun c ->
|
||||||
let (c, k) = unpack c in
|
let (c, k) = unpack c in
|
||||||
mem c k >>= function
|
mem c k >>= function
|
||||||
| true -> return (Some true)
|
| true -> return_some true
|
||||||
| false -> return None)
|
| false -> return_none)
|
||||||
(register_indexed_subcontext
|
(register_indexed_subcontext
|
||||||
~list:(fun c -> elements c >>= return)
|
~list:(fun c -> elements c >>= return)
|
||||||
C.description I.args)
|
C.description I.args)
|
||||||
@ -227,11 +227,11 @@ module Make_indexed_data_storage
|
|||||||
Lwt.return (of_bytes ~key b)
|
Lwt.return (of_bytes ~key b)
|
||||||
let get_option s i =
|
let get_option s i =
|
||||||
C.get_option s (I.to_path i []) >>= function
|
C.get_option s (I.to_path i []) >>= function
|
||||||
| None -> return None
|
| None -> return_none
|
||||||
| Some b ->
|
| Some b ->
|
||||||
let key = C.absolute_key s (I.to_path i []) in
|
let key = C.absolute_key s (I.to_path i []) in
|
||||||
match of_bytes ~key b with
|
match of_bytes ~key b with
|
||||||
| Ok v -> return (Some v)
|
| Ok v -> return_some v
|
||||||
| Error _ as err -> Lwt.return err
|
| Error _ as err -> Lwt.return err
|
||||||
let set s i v =
|
let set s i v =
|
||||||
C.set s (I.to_path i []) (to_bytes v) >>=? fun t ->
|
C.set s (I.to_path i []) (to_bytes v) >>=? fun t ->
|
||||||
@ -634,8 +634,8 @@ module Make_indexed_subcontext (C : Raw_context.T) (I : INDEX)
|
|||||||
~get:(fun c ->
|
~get:(fun c ->
|
||||||
let (c, k) = unpack c in
|
let (c, k) = unpack c in
|
||||||
mem c k >>= function
|
mem c k >>= function
|
||||||
| true -> return (Some true)
|
| true -> return_some true
|
||||||
| false -> return None)
|
| false -> return_none)
|
||||||
(register_named_subcontext Raw_context.description N.name)
|
(register_named_subcontext Raw_context.description N.name)
|
||||||
Data_encoding.bool
|
Data_encoding.bool
|
||||||
|
|
||||||
@ -655,11 +655,11 @@ module Make_indexed_subcontext (C : Raw_context.T) (I : INDEX)
|
|||||||
Lwt.return (of_bytes ~key b)
|
Lwt.return (of_bytes ~key b)
|
||||||
let get_option s i =
|
let get_option s i =
|
||||||
Raw_context.get_option (pack s i) N.name >>= function
|
Raw_context.get_option (pack s i) N.name >>= function
|
||||||
| None -> return None
|
| None -> return_none
|
||||||
| Some b ->
|
| Some b ->
|
||||||
let key = Raw_context.absolute_key (pack s i) N.name in
|
let key = Raw_context.absolute_key (pack s i) N.name in
|
||||||
match of_bytes ~key b with
|
match of_bytes ~key b with
|
||||||
| Ok v -> return (Some v)
|
| Ok v -> return_some v
|
||||||
| Error _ as err -> Lwt.return err
|
| Error _ as err -> Lwt.return err
|
||||||
let set s i v =
|
let set s i v =
|
||||||
Raw_context.set (pack s i) N.name (to_bytes v) >>=? fun c ->
|
Raw_context.set (pack s i) N.name (to_bytes v) >>=? fun c ->
|
||||||
|
@ -24,7 +24,7 @@ let traverse_rolls ctxt head =
|
|||||||
|
|
||||||
let get_rolls ctxt delegate =
|
let get_rolls ctxt delegate =
|
||||||
Storage.Roll.Delegate_roll_list.get_option ctxt delegate >>= wrap >>=? function
|
Storage.Roll.Delegate_roll_list.get_option ctxt delegate >>= wrap >>=? function
|
||||||
| None -> return []
|
| None -> return_nil
|
||||||
| Some head_roll -> traverse_rolls ctxt head_roll
|
| Some head_roll -> traverse_rolls ctxt head_roll
|
||||||
|
|
||||||
let check_rolls b (account:Account.t) =
|
let check_rolls b (account:Account.t) =
|
||||||
|
@ -168,12 +168,12 @@ let rpc_services = Services.rpc_services
|
|||||||
let sandbox_param_key = [ "sandbox_parameter" ]
|
let sandbox_param_key = [ "sandbox_parameter" ]
|
||||||
let get_sandbox_param ctxt =
|
let get_sandbox_param ctxt =
|
||||||
Context.get ctxt sandbox_param_key >>= function
|
Context.get ctxt sandbox_param_key >>= function
|
||||||
| None -> return None
|
| None -> return_none
|
||||||
| Some bytes ->
|
| Some bytes ->
|
||||||
match Data_encoding.Binary.of_bytes Data_encoding.json bytes with
|
match Data_encoding.Binary.of_bytes Data_encoding.json bytes with
|
||||||
| None ->
|
| None ->
|
||||||
failwith "Internal error: failed to parse the sandbox parameter."
|
failwith "Internal error: failed to parse the sandbox parameter."
|
||||||
| Some json -> return (Some json)
|
| Some json -> return_some json
|
||||||
|
|
||||||
let init ctxt block_header =
|
let init ctxt block_header =
|
||||||
Data.Init.tag_first_block ctxt >>=? fun ctxt ->
|
Data.Init.tag_first_block ctxt >>=? fun ctxt ->
|
||||||
|
Loading…
Reference in New Issue
Block a user