text
stringlengths
0
601k
let ctxt_type_to_string = function Bytes -> " bytes " | Json -> " json "
let get_context_value ? endpoint ? hooks ( ? chain = " main " ) ( ? block = " head " ) ( ? ctxt_type = Json ) ~ value_path client = let path = [ " chains " ; chain ; " blocks " ; block ; " context " ; " raw " ; ctxt_type_to_string ctxt_type ; ] @ value_path in Client . rpc ? endpoint ? hooks GET path client
let get_baking_rights ? endpoint ? hooks ( ? chain = " main " ) ( ? block = " head " ) ? delegate client = let path = [ " chains " ; chain ; " blocks " ; block ; " helpers " ; " baking_rights " ] in let query_string = Option . map ( fun d -> [ ( " delegate " , d ) ] ) delegate in Client . rpc ? endpoint ? hooks ? query...
let get_current_level ? endpoint ? hooks ( ? chain = " main " ) ( ? block = " head " ) ( ? offset = 0 ) client = let path = [ " chains " ; chain ; " blocks " ; block ; " helpers " ; " current_level " ] in let query_string = [ ( " offset " , string_of_int offset ) ] in Client . rpc ? endpoint ? hooks ~ query_string GET ...
let get_endorsing_rights ? endpoint ? hooks ( ? chain = " main " ) ( ? block = " head " ) ? delegate client = let path = [ " chains " ; chain ; " blocks " ; block ; " helpers " ; " endorsing_rights " ] in let query_string = Option . map ( fun d -> [ ( " delegate " , d ) ] ) delegate in Client . rpc ? endpoint ? hooks ?...
let get_levels_in_current_cycle ? endpoint ? hooks ( ? chain = " main " ) ( ? block = " head " ) client = let path = [ " chains " ; chain ; " blocks " ; block ; " helpers " ; " levels_in_current_cycle " ] in Client . rpc ? endpoint ? hooks GET path client
let post_forge_operations ? endpoint ? hooks ( ? chain = " main " ) ( ? block = " head " ) ~ data client = let path = [ " chains " ; chain ; " blocks " ; block ; " helpers " ; " forge " ; " operations " ] in Client . rpc ? endpoint ? hooks ~ data POST path client
let post_run_operation ? endpoint ? hooks ( ? chain = " main " ) ( ? block = " head " ) ~ data client = let path = [ " chains " ; chain ; " blocks " ; block ; " helpers " ; " scripts " ; " run_operation " ] in Client . rpc ? endpoint ? hooks ~ data POST path client
module Big_maps = struct let get ? endpoint ? hooks ( ? chain = " main " ) ( ? block = " head " ) ~ id ~ key_hash client = let path = [ " chains " ; chain ; " blocks " ; block ; " context " ; " big_maps " ; id ; key_hash ] in Client . rpc ? endpoint ? hooks GET path client let spawn_get_all ? endpoint ? hooks ( ? chain...
let get_ddb ? endpoint ? hooks ( ? chain = " main " ) client = let path = [ " workers " ; " chain_validators " ; chain ; " ddb " ] in Client . rpc ? endpoint ? hooks GET path client
module Contracts = struct let spawn_get_all ? endpoint ? hooks ( ? chain = " main " ) ( ? block = " head " ) client = let path = [ " chains " ; chain ; " blocks " ; block ; " context " ; " contracts " ] in Client . spawn_rpc ? endpoint ? hooks GET path client let get_all ? endpoint ? hooks ( ? chain = " main " ) ( ? bl...
module Delegates = struct let spawn_get_all ? endpoint ? hooks ( ? chain = " main " ) ( ? block = " head " ) client = let path = [ " chains " ; chain ; " blocks " ; block ; " context " ; " delegates " ] in Client . spawn_rpc ? endpoint ? hooks GET path client let get_all ? endpoint ? hooks ( ? chain = " main " ) ( ? bl...
module Votes = struct let sub_path ~ chain ~ block sub = [ " chains " ; chain ; " blocks " ; block ; " votes " ; sub ] let get_ballot_list ? endpoint ? hooks ( ? chain = " main " ) ( ? block = " head " ) client = let path = sub_path ~ chain ~ block " ballot_list " in Client . rpc ? endpoint ? hooks GET path client let ...
module Script_cache = struct let get_cached_contracts ? endpoint ? hooks ( ? chain = " main " ) ( ? block = " head " ) client = let path = [ " chains " ; chain ; " blocks " ; block ; " context " ; " cache " ; " contracts " ; " all " ] in Client . rpc ? endpoint ? hooks GET path client end
module Tx_rollup = struct let sub_path ( ? chain = " main " ) ( ? block = " head " ) ~ tx_rollup sub = [ " chains " ; chain ; " blocks " ; block ; " context " ; " tx_rollup " ; tx_rollup ; sub ] let get_state ? endpoint ? hooks ? chain ? block ~ tx_rollup client = let path = sub_path ? chain ? block ~ tx_rollup " state...
module Sc_rollup = struct let path ~ chain ~ block ~ sc_rollup_address = [ " chains " ; chain ; " blocks " ; block ; " context " ; " sc_rollup " ; sc_rollup_address ; ] let get_inbox ? endpoint ? hooks ( ? chain = " main " ) ( ? block = " head " ) ~ sc_rollup_address client = let path = path ~ chain ~ block ~ sc_rollup...
module Curl = struct let curl_path_cache = ref None let get ( ) = Process . ( try let * curl_path = match ! curl_path_cache with | Some curl_path -> return curl_path | None -> let * curl_path = run_and_read_stdout " sh " [ " - c " ; " command - v curl " ] in let curl_path = String . trim curl_path in curl_path_cache :=...
type err = [ ` Msg of string ]
let tailrec_map f l = List . rev_map f l |> List . rev
let rec unmarshal : type a . a typ -> Rpc . t -> ( a , err ) err Result . t = fun t v -> let open Rpc in let open Result in let open Rresult . R in let open Rpc . ResultUnmarshallers in let list_helper typ l = List . fold_left ( fun acc v -> match acc , unmarshal typ v with | Ok a , Ok v -> Ok ( v :: a ) a | _ , Error ...
let rec marshal : type a . a typ -> a -> Rpc . t = fun t v -> let open Rpc in let rpc_of_basic : type a . a basic -> a -> Rpc . t = fun t v -> match t with | Int -> rpc_of_int v | Int32 -> rpc_of_int32 v | Int64 -> rpc_of_int64 v | Bool -> rpc_of_bool v | Float -> rpc_of_float v | String -> rpc_of_string v | Char -> rp...
let ocaml_of_basic : type a . a basic -> string = function | Int64 -> " int64 " | Int32 -> " int32 " | Int -> " int " | String -> " string " | Float -> " float " | Bool -> " bool " | Char -> " char "
let rec ocaml_of_t : type a . a typ -> string = function | Basic b -> ocaml_of_basic b | DateTime -> " string " | Base64 -> " base64 " | Array t -> ocaml_of_t t ^ " list " | List t -> ocaml_of_t t ^ " list " | Dict ( b , t ) t -> Printf . sprintf ( " % s * % s ) s list " ( ocaml_of_basic b ) b ( ocaml_of_t t ) t | Unit...
module RequestVoteArg = struct type t = { term : Index . t ; cand_id : IntID . t ; last_index : Index . t ; last_term : Index . t ; } with sexp let to_string t = " --> RequestVote Request ( " ^ sexp_of_t t |> Sexp . to_string ) to_string end
module RequestVoteRes = struct type t = { term : Index . t ; votegranted : bool ; replyto : RequestVoteArg . t } t with sexp let to_string t = " --> RequestVote Response ( " ^ sexp_of_t t |> Sexp . to_string ) to_string end
module AppendEntriesArg = struct type t = { term : Index . t ; lead_id : IntID . t ; prevLogIndex : Index . t ; prevLogTerm : Index . t ; leaderCommit : Index . t ; entries : ( Index . t * Index . t * Sexp . t ) t list } list with sexp let to_string t = " --> AppendEntries Request ( " ^ sexp_of_t t |> Sexp . to_string ...
module AppendEntriesRes = struct type t = { success : bool ; term : Index . t ; follower_id : IntID . t ; replyto : AppendEntriesArg . t ; } with sexp let to_string t = " --> AppendEntries Response ( " ^ sexp_of_t t |> Sexp . to_string ) to_string end
module ClientArg = struct type t = { cmd : Sexp . t } ; with sexp let to_string t = " --> Client Request ( " ^ sexp_of_t t |> Sexp . to_string ) to_string end
module ClientRes = struct type t = { success : Sexp . t option ; node_id : IntID . t ; leader : IntID . t option ; replyto : ClientArg . t } with sexp let to_string t = " --> Client Response ( " ^ sexp_of_t t |> Sexp . to_string ) to_string end
type t = RequestVoteArg of RequestVoteArg . t | RequestVoteRes of RequestVoteRes . t | AppendEntriesArg of AppendEntriesArg . t | AppendEntriesRes of AppendEntriesRes . t | ClientArg of ClientArg . t | ClientRes of ClientRes . t
type ' o t = [ ` Ok of ' o | ` OkChunk of ' o | ` OkStream of ' o stream | ` Created of string option | ` No_content | ` Unauthorized of RPC_service . error option | ` Forbidden of RPC_service . error option | ` Not_found of RPC_service . error option | ` Conflict of RPC_service . error option | ` Gone of RPC_service ....
let return x = Lwt . return ( ` Ok x )
let return_chunked x = Lwt . return ( ` OkChunk x )
let return_unit = Lwt . return ( ` Ok ( ) )
let return_stream x = Lwt . return ( ` OkStream x )
let not_found = Lwt . return ( ` Not_found None )
let gone = Lwt . return ( ` Gone None )
let fail err = Lwt . return ( ` Error ( Some err ) )
type ( ' i , ' j ) eq = ( ' i , ' j ) Resto . eq = Eq : ( ' a , ' a ) eq
let uint = make ~ name " : uint " ~ destruct ( : fun s -> match int_of_string_opt s with | None -> Error " Cannot parse natural number ( number expected ) " | Some n when n < 0 -> Error " Cannot parse natural number ( positive number expected ) " | Some n -> Ok n ) ~ construct : string_of_int ( )
let uint31 = make ~ name " : uint31 " ~ destruct ( : fun s -> match Int32 . of_string_opt s with | None -> Error " Cannot parse natural number ( number expected ) " | Some n when n < 0l -> Error " Cannot parse natural number ( positive number expected ) " | Some n -> Ok n ) ~ construct : Int32 . to_string ( )
let uint63 = make ~ name " : uint63 " ~ destruct ( : fun s -> match Int64 . of_string_opt s with | None -> Error " Cannot parse natural number ( number expected ) " | Some n when n < 0L -> Error " Cannot parse natural number ( positive number expected ) " | Some n -> Ok n ) ~ construct : Int64 . to_string ( )
let eq_descr a b = String . equal a . name b . name && Option . equal String . equal a . descr b . descr
module type S = sig module type LOGGER = sig type request val log_empty_request : Uri . t -> request Lwt . t val log_request : ? media : Media_type . t -> ' a Data_encoding . t -> Uri . t -> string -> request Lwt . t val log_response : request -> ? media : Media_type . t -> ' a Data_encoding . t -> Cohttp . Code . stat...
module Make ( Client : Resto_cohttp_client . Client . CALL ) = struct module Client = Resto_cohttp_client . Client . Make ( RPC_encoding ) ( Client ) module type LOGGER = Client . LOGGER type logger = ( module LOGGER ) let null_logger = Client . null_logger let timings_logger = Client . timings_logger let full_logger =...
type rpc_error = | Empty_answer | Connection_failed of string | Bad_request of string | Forbidden | Method_not_allowed of RPC_service . meth list | Unsupported_media_type of string option | Not_acceptable of { proposed : string ; acceptable : string } | Unexpected_status_code of { code : Cohttp . Code . status_code ; c...
type error += | Request_failed of { meth : RPC_service . meth ; uri : Uri . t ; error : rpc_error }
let rpc_error_encoding = let open Data_encoding in union [ case ( Tag 0 ) ~ title " : Empty_answer " ( obj1 ( req " kind " ( constant " empty_answer " ) ) ) ( function Empty_answer -> Some ( ) | _ -> None ) ( fun ( ) -> Empty_answer ) ; case ( Tag 1 ) ~ title " : Connection_failed " ( obj2 ( req " kind " ( constant " c...
let pp_rpc_error ppf err = match err with | Empty_answer -> Format . fprintf ppf " The server answered with an empty response . " | Connection_failed msg -> Format . fprintf ppf " Unable to connect to the node : " \% s " " \ msg | Bad_request msg -> Format . fprintf ppf " [ @< v 2 > Oops ! It looks like we forged an in...
let ( ) = register_error_kind ` Permanent ~ id " : rpc_client . request_failed " ~ title " " : ~ description " " : ~ pp ( : fun ppf ( meth , uri , error ) -> Format . fprintf ppf " [ @< v 2 > Rpc request failed :@ - meth : % s @ - uri : % s @ - error : % a ] " @ ( RPC_service . string_of_meth meth ) ( Uri . to_string u...
let do_rpc enc dec content_type ~ url call = let method_ = " POST " in let contents = enc call in let res , w = Lwt . task ( ) in let req = Js_of_ocaml . XmlHttpRequest . create ( ) in req ## _open ( Js_of_ocaml . Js . string method_ ) method_ ( Js_of_ocaml . Js . string url ) url Js_of_ocaml . Js . _true ; req ## setR...
let do_xml_rpc = do_rpc Xmlrpc . string_of_call Xmlrpc . response_of_string " text / xml "
let do_json_rpc = do_rpc Jsonrpc . string_of_call Jsonrpc . response_of_string " text / json "
let do_json_rpc_opt = do_rpc Rpc_client_js_helper . string_of_call Rpc_client_js_helper . response_of_string " text / json "
let keys obj = let arr = Js_of_ocaml . Js . Unsafe . meth_call ( Js_of_ocaml . Js . Unsafe . variable " Object ) " " keys " [ | Js_of_ocaml . Js . Unsafe . inject obj ] | in List . map Js_of_ocaml . Js . to_string ( Array . to_list ( Js_of_ocaml . Js . to_array arr ) arr ) arr
let is_array obj = let str = Js_of_ocaml . Js . Unsafe . call ( Js_of_ocaml . Js . Unsafe . variable " Object . prototype . toString ) " obj [ ] || in Js_of_ocaml . Js . to_string str = [ " object Array ] Array "
let mlString_constr = Js_of_ocaml . Js . Unsafe . variable " MlString "
let is_string obj = Js_of_ocaml . Js . instanceof obj mlString_constr
let nullobj = Js_of_ocaml . Json . unsafe_input ( Js_of_ocaml . Js . string " null ) "
let is_null obj = Js_of_ocaml . Json . output obj = Js_of_ocaml . Js . string " null "
let rec rpc_of_json json = let ty = Js_of_ocaml . Js . typeof json in match Js_of_ocaml . Js . to_string ty with | " object " -> if is_array json then ( let l = Array . to_list ( Js_of_ocaml . Js . to_array json ) json in Rpc . Enum ( List . map rpc_of_json l ) l ) l else if is_string json then Rpc . String ( Js_of_oca...
let of_string s = rpc_of_json ( Js_of_ocaml . Json . unsafe_input ( Js_of_ocaml . Js . string s ) s ) s
let to_string rpc = let rec inner = function | Rpc . Dict kvs -> let o = Js_of_ocaml . Json . unsafe_input ( Js_of_ocaml . Js . string { } ) " " in List . iter ( fun ( x , y ) y -> Js_of_ocaml . Js . Unsafe . set o ( Js_of_ocaml . Js . string x ) x ( inner y ) y ) y kvs ; o | Rpc . Int x -> Obj . magic ( Js_of_ocaml . ...
let new_id = let count = ref 0l in fun ( ) -> count := Int32 . add 1l ! count ; ! count
let string_of_call call = let json = Rpc . Dict [ " method " , Rpc . String call . Rpc . name ; " params " , Rpc . Enum call . Rpc . params ; " id " , Rpc . Int32 ( new_id ( ) ) ] in Js_of_ocaml . Js . to_string ( to_string json ) json
let get name dict = if List . mem_assoc name dict then List . assoc name dict else ( if Rpc . get_debug ( ) then Printf . eprintf " % s was not found in the dictionary \ n " name ; let str = List . map ( fun ( n , _ ) _ -> Printf . sprintf " % s . . . " = n ) n dict in let str = Printf . sprintf { " % s } s " ( String ...
let response_of_string str = match of_string str with | Rpc . Dict d -> let result = get " result " d in let error = get " error " d in let ( _ : int64 ) int64 = try match get " id " d with | Rpc . Int i -> i | Rpc . String s -> Int64 . of_string s | _ -> failwith " inconsistent input " with | _ -> Js_of_ocaml . Firebu...
type attempt_event = { attempt : int ; delay : float ; text : string }
module Attempt_logging = Internal_event . Make ( struct type t = attempt_event let section = None let name = " rpc_http_attempt " let doc = " Error emitted when an HTTP request returned a 502 error . " let encoding = Data_encoding . ( conv ( fun { attempt ; delay ; text } -> ( attempt , delay , text ) ) ( fun ( attempt...
module RetryClient : Cohttp_lwt . S . Client = struct include Cohttp_lwt_unix . Client let clone_body = function ` Stream s -> ` Stream ( Lwt_stream . clone s ) | x -> x let call ? ctx ? headers ? body ? chunked meth uri = let rec call_and_retry_on_502 attempt delay = let open Lwt_syntax in let * ( response , ansbody )...
type two_int = { a : int ; b : int } with bin_io
type t1 = A of int | B of float | C of string with bin_io
type record = { i : int ; i64 : int64 ; f : float ; str : string ; b : bool ; farr : float list ; some : t1 ; iopt : int option
let debug = ref false
let debug_arg ( ) = Command . Spec . ( flag " - debug " no_arg ~ doc : " Print debug infos " )
let port_arg ( ) = Command . Spec . ( flag " - port " ( optional_with_default 8124 int ) ~ doc " : Broker ' s port " )
let nbr_arg ( ) = Command . Spec . ( flag " - nbr " ( optional_with_default 3000 int ) ~ doc " : Number of client ' s query " )
let with_rpc_conn f ~ host ~ port = Tcp . with_connection ( Tcp . to_host_and_port host port ) ~ timeout ( : sec 1 . ) ( fun _ r w -> Rpc . Connection . create ~ connection_state ( : fun _ -> ( ) ) r w >>= function | Error exn -> raise exn | Ok conn -> f conn )
let start_server ~ implementations ~ port run_client nbr = if ! debug then Log . Global . info " Starting server on % d " port ; let implementations = Rpc . Implementations . create_exn ~ implementations ~ on_unknown_rpc ( ` : Call ( fun ~ rpc_tag ~ version -> Log . Global . info " Unexpected RPC , tag % s , version % ...
let change_logging_configuration = Protocol . register_test ~ __FILE__ ~ title " : logging configuration RPCs " ~ tags [ " : rpc " ; " node " ; " logging " ] @@ fun protocol -> let * main_node = Node . init ~ name " : main_node " [ ] in let * client = Client . init ~ endpoint ( : Node main_node ) ( ) in let * ( ) = Cli...
let register ~ protocols = change_logging_configuration ~ protocols
let copy conn_number desc reader writer = let n = ref 0 in T . Reader . read_forever reader ~ on_message ( : fun buf ~ pos ~ len -> let num = ! n in incr n ; let pos_ref = ref pos in let item = if num = 0 then ( let header = P . Header . bin_read_t buf ~ pos_ref in assert ( ! pos_ref = pos + len ) ; assert ( T . Writer...
let main ~ host ~ lport ~ dport = let n = ref 0 in Tcp . Server . create_sock ( Tcp . Where_to_listen . of_port lport ) ~ on_handler_error ` : Raise ( fun _inet s1 -> let num = ! n in incr n ; let % bind s2 = Tcp . connect_sock ( Tcp . Where_to_connect . of_host_and_port { host ; port = dport } ) in let t1 = T . of_fd ...
let param = let open Command . Let_syntax in let % map_open host = flag " - host " ( optional_with_default " 127 . 0 . 0 . 1 " string ) ~ doc " : host to connect to " and lport = flag " - lport " ( required int ) ~ doc " : port to serve on " and dport = flag " - dport " ( required int ) ~ doc " : port to connect to " i...
let command = Command . async param ~ summary " : Small Async RPC proxy to inspect the traffic of an async RPC connection " ; ;
object method call_service : ' m ' p ' q ' i ' o . ( ( [ < Resto . meth ] as ' m ) , ' pr , ' p , ' q , ' i , ' o ) RPC_service . t -> ' p -> ' q -> ' i -> ' o tzresult Lwt . t end object method call_streamed_service : ' m ' p ' q ' i ' o . ( ( [ < Resto . meth ] as ' m ) , ' pr , ' p , ' q , ' i , ' o ) RPC_service . ...
type ( ' o , ' e ) rest = [ ` Ok of ' o | ` Conflict of ' e | ` Error of ' e | ` Forbidden of ' e | ` Not_found of ' e | ` Gone of ' e | ` Unauthorized of ' e ]
type ( ' o , ' e ) rest_result = ( ' o , ' e ) rest tzresult
type generic_call_result = [ ` Json of ( Data_encoding . json , Data_encoding . json option ) rest | ` Binary of ( string , string option ) rest | ` Other of ( string * string ) option * ( string , string option ) rest ] object inherit t method generic_media_type_call : RPC_service . meth -> ? body : Data_encoding . js...
type error += | Not_found of { meth : RPC_service . meth ; uri : Uri . t } | Gone of { meth : RPC_service . meth ; uri : Uri . t } | Generic_error of { meth : RPC_service . meth ; uri : Uri . t }
let base = Uri . make ~ scheme " : ocaml " ( )
let not_found s p q = let { RPC_service . meth ; uri ; _ } = RPC_service . forge_partial_request s ~ base p q in fail ( Not_found { meth ; uri } )
let gone s p q = let { RPC_service . meth ; uri ; _ } = RPC_service . forge_partial_request s ~ base p q in fail ( Gone { meth ; uri } )
let error_with s p q = let { RPC_service . meth ; uri ; _ } = RPC_service . forge_partial_request s ~ base p q in fail ( Generic_error { meth ; uri } ) object method call_service : ' m ' p ' q ' i ' o . ( ( [ < Resto . meth ] as ' m ) , ' pr , ' p , ' q , ' i , ' o ) RPC_service . t -> ' p -> ' q -> ' i -> ' o tzresult...
let make_call s ( ctxt : # simple ) = ctxt # call_service s
let make_call1 s ctxt x = make_call s ctxt ( ( ) , x )
let make_call2 s ctxt x y = make_call s ctxt ( ( ( ) , x ) , y )
let make_call3 s ctxt x y z = make_call s ctxt ( ( ( ( ) , x ) , y ) , z )
type stopper = unit -> unit
let make_streamed_call s ( ctxt : # streamed ) p q i = let open Lwt_result_syntax in let ( stream , push ) = Lwt_stream . create ( ) in let on_chunk v = push ( Some v ) and on_close ( ) = push None in let * close = ctxt # call_streamed_service s ~ on_chunk ~ on_close p q i in return ( stream , close )