text stringlengths 0 601k |
|---|
module Pretty_print = struct open More_fmt let verbatim_protection f ppf json_blob = try f ppf json_blob with e -> json ppf json_blob ; cut ppf ( ) ; exn ppf e let fail_expecting s = failwith " PP : Expecting % s " s let mempool_pending_operations_rpc ppf mempool_json = let pp_op_list_short ppf l = let kinds = List . m... |
module type CONTEXT = sig type t type key = string list type value = MBytes . t val mem : t -> key -> bool Lwt . t val dir_mem : t -> key -> bool Lwt . t val get : t -> key -> value option Lwt . t val set : t -> key -> value -> t Lwt . t val copy : t -> from : key -> to_ : key -> t option Lwt . t val del : t -> key -> ... |
module Context = struct type key = string list type value = MBytes . t type ' ctxt ops = ( module CONTEXT with type t = ' ctxt ) type _ kind = . . type t = Context : { kind : ' a kind ; ctxt : ' a ; ops : ' a ops } -> t let mem ( Context { ops = ( module Ops ) ; ctxt ; _ } ) key = Ops . mem ctxt key let set ( Context {... |
type validation_result = { context : Context . t ; fitness : Fitness . t ; message : string option ; max_operations_ttl : int ; last_allowed_fork_level : Int32 . t ; } |
type quota = { max_size : int ; max_op : int option } |
type rpc_context = { block_hash : Block_hash . t ; block_header : Block_header . shell_header ; context : Context . t ; } |
module type T = sig type context type quota type validation_result type rpc_context type ' a tzresult val max_block_length : int val max_operation_data_length : int val validation_passes : quota list type block_header_data val block_header_data_encoding : block_header_data Data_encoding . t type block_header = { shell ... |
module type PROTOCOL = T with type context := Context . t and type quota := quota and type validation_result := validation_result and type rpc_context := rpc_context and type ' a tzresult := ' a Error_monad . tzresult |
module MakeV1 ( Param : sig val name : string end ) struct include Pervasives module Pervasives = Pervasives module Compare = Compare module Array = Array module List = List module Bytes = struct include Bytes include EndianBytes . BigEndian module LE = EndianBytes . LittleEndian end module String = struct include Stri... |
let hooks = let replace_variables string = let replacements = [ ( " tz [ 123 ] \\ w { 33 } " , " [ PUBLIC_KEY_HASH ] " ) ; ( " edpk \\ w { 50 } " , " [ PUBLIC_KEY ] " ) ; ( " KT1 \\ w { 33 } " , " [ CONTRACT_HASH ] " ) ; ( " \\ bo \\ w { 50 } \\ b " , " [ OPERATION_HASH ] " ) ; ( " \\ d { 4 } -\\ d { 2 } -\\ d { 2 } T ... |
type t = Tez_tag of repr [ @@ ocaml . unboxed ] |
type error += | Addition_overflow of t * t | Subtraction_underflow of t * t | Multiplication_overflow of t * int64 | Negative_multiplicator of t * int64 | Invalid_divisor of t * int64 |
let zero = Tez_tag 0L |
let one_mutez = Tez_tag 1L |
let max_mutez = Tez_tag Int64 . max_int |
let mul_int ( Tez_tag tez ) i = Tez_tag ( Int64 . mul tez i ) |
let one_cent = mul_int one_mutez 10_000L |
let fifty_cents = mul_int one_cent 50L |
let one = mul_int one_cent 100L |
let of_string s = let triplets = function | hd :: tl -> let len = String . length hd in Compare . Int . ( len <= 3 && len > 0 && List . for_all ( fun s -> String . length s = 3 ) tl ) | [ ] -> false in let integers s = triplets ( String . split_on_char ' , ' s ) in let decimals s = let l = String . split_on_char ' , ' ... |
let pp ppf ( Tez_tag amount ) = let mult_int = 1_000_000L in let [ @ coq_struct " amount " ] rec left ppf amount = let ( d , r ) = ( Int64 . ( div amount 1000L ) , Int64 . ( rem amount 1000L ) ) in if d > 0L then Format . fprintf ppf " % a % 03Ld " left d r else Format . fprintf ppf " % Ld " r in let right ppf amount =... |
let to_string t = Format . asprintf " % a " pp t |
let ( -? ) tez1 tez2 = let ( Tez_tag t1 ) = tez1 in let ( Tez_tag t2 ) = tez2 in if t2 <= t1 then ok ( Tez_tag ( Int64 . sub t1 t2 ) ) else error ( Subtraction_underflow ( tez1 , tez2 ) ) |
let sub_opt ( Tez_tag t1 ) ( Tez_tag t2 ) = if t2 <= t1 then Some ( Tez_tag ( Int64 . sub t1 t2 ) ) else None |
let ( +? ) tez1 tez2 = let ( Tez_tag t1 ) = tez1 in let ( Tez_tag t2 ) = tez2 in let t = Int64 . add t1 t2 in if t < t1 then error ( Addition_overflow ( tez1 , tez2 ) ) else ok ( Tez_tag t ) |
let ( *? ) tez m = let ( Tez_tag t ) = tez in if m < 0L then error ( Negative_multiplicator ( tez , m ) ) else if m = 0L then ok ( Tez_tag 0L ) else if t > Int64 . ( div max_int m ) then error ( Multiplication_overflow ( tez , m ) ) else ok ( Tez_tag ( Int64 . mul t m ) ) |
let ( /? ) tez d = let ( Tez_tag t ) = tez in if d <= 0L then error ( Invalid_divisor ( tez , d ) ) else ok ( Tez_tag ( Int64 . div t d ) ) |
let mul_exn t m = match t *? Int64 . ( of_int m ) with | Ok v -> v | Error _ -> invalid_arg " mul_exn " |
let div_exn t d = match t /? Int64 . ( of_int d ) with | Ok v -> v | Error _ -> invalid_arg " div_exn " |
let of_mutez t = if t < 0L then None else Some ( Tez_tag t ) |
let of_mutez_exn x = match of_mutez x with None -> invalid_arg " Tez . of_mutez " | Some v -> v |
let to_mutez ( Tez_tag t ) = t |
let encoding = let open Data_encoding in let decode ( Tez_tag t ) = Z . of_int64 t in let encode = Json . wrap_error ( fun i -> Tez_tag ( Z . to_int64 i ) ) in Data_encoding . def name ( check_size 10 ( conv decode encode n ) ) |
let ( ) = let open Data_encoding in register_error_kind ` Temporary ~ id ( : id ^ " . addition_overflow " ) ~ title ( " : Overflowing " ^ id ^ " addition " ) ~ pp ( : fun ppf ( opa , opb ) -> Format . fprintf ppf " Overflowing addition of % a % s and % a % s " pp opa id pp opb id ) ~ description ( " : An addition of tw... |
let compare ( Tez_tag x ) ( Tez_tag y ) = compare x y |
let ( = ) ( Tez_tag x ) ( Tez_tag y ) = x = y |
let ( <> ) ( Tez_tag x ) ( Tez_tag y ) = x <> y |
let ( < ) ( Tez_tag x ) ( Tez_tag y ) = x < y |
let ( > ) ( Tez_tag x ) ( Tez_tag y ) = x > y |
let ( <= ) ( Tez_tag x ) ( Tez_tag y ) = x <= y |
let ( >= ) ( Tez_tag x ) ( Tez_tag y ) = x >= y |
let equal ( Tez_tag x ) ( Tez_tag y ) = equal x y |
let max ( Tez_tag x ) ( Tez_tag y ) = Tez_tag ( max x y ) |
let min ( Tez_tag x ) ( Tez_tag y ) = Tez_tag ( min x y ) |
let try_float_of_string str = try print_float ( float_of_string str ) ; print_newline ( ) with exn -> print_endline ( Printexc . to_string exn ) ; ; |
let ( ) = try_float_of_string " 0x1A " ; try_float_of_string " 0x1Ap3 " ; try_float_of_string " 0x " ; try_float_of_string " 0x . " ; try_float_of_string " 0xp0 " ; try_float_of_string " 0x . p0 " ; try_float_of_string " 0x1 . 0p - 2147483648 " ; try_float_of_string " 0x123456789ABCDEF0p2147483647 " ; try_float_of_stri... |
let ( ) = let _ = 0x1A in let _ = 0x1Ap3 in let _ = 0x1 . 0p - 2147483648 in let _ = 0x123456789ABCDEF0p2147483647 in let _ = 0x1p2147483648 in let _ = 0x1_ . _1p1_1 in let _ = 0x1_ . _1p1_ in let _ = 0x1_ . _1p - 1_1 in let _ = 0x1_ . _1p - 1_ in let _ = 0x1_ . _1p + 1_1 in let _ = 0x1_ . _1p + 1_ in ( ) |
let say s = Printf . printf s ; ; try say " d / i positive \ n " ; %! test ( sprintf " % d /% i " 42 43 = " 42 / 43 " ) ; test ( sprintf " %- 4d /%- 5i " 42 43 = " 42 / 43 " ) ; test ( sprintf " % 04d /% 05i " 42 43 = " 0042 / 00043 " ) ; test ( sprintf " %+ d /%+ i " 42 43 = " + 42 /+ 43 " ) ; test ( sprintf " % d /% ... |
let c_0xff_32 = Int32 . of_string " 0xff " |
let encode_frame_size x = let s = Bytes . create 4 in let n3 = Int32 . to_int ( Int32 . shift_right_logical x 24 ) land 0xff in let n2 = Int32 . to_int ( Int32 . shift_right_logical x 16 ) land 0xff in let n1 = Int32 . to_int ( Int32 . shift_right_logical x 8 ) land 0xff in let n0 = Int32 . to_int ( Int32 . logand x c_... |
let decode_frame_size s = let n3 = Int32 . of_int ( Char . code @@ Bytes . get s 0 ) in let n2 = Int32 . of_int ( Char . code @@ Bytes . get s 1 ) in let n1 = Int32 . of_int ( Char . code @@ Bytes . get s 2 ) in let n0 = Int32 . of_int ( Char . code @@ Bytes . get s 3 ) in Int32 . logor ( Int32 . shift_left n3 24 ) ( I... |
module Hashtbl = struct include Hashtbl let get t ? default k = try Some ( Hashtbl . find t k ) with | Not_found -> ( match default with None -> ( ) | Some v -> Hashtbl . replace t k v ) ; default end |
module Tid = struct type t = Ipaddr . V4 . t * int * int with sexp let to_string t = t |> sexp_of_t |> Sexplib . Sexp . to_string_hum end |
module S = struct type t = { port : int ; conns : ( Tid . t , string * int64 * int64 ) Hashtbl . t ; tids : ( Ipaddr . V4 . t * int , int ) Hashtbl . t ; files : ( string , int64 * Cstruct . t ) Hashtbl . t ; } with sexp let to_string t = t |> sexp_of_t |> Sexplib . Sexp . to_string_hum let make config = let port = Tft... |
type mode = | Octet | Netascii | Mail | Unknown of string |
let mode_of_string = function | " octet " -> Octet | " netascii " -> Netascii | " mail " -> Mail | mode -> Unknown mode |
let mode_to_string = function | Octet -> " octet " | Netascii -> " netascii " | Mail -> " mail " | Unknown mode -> mode |
module Success = struct type t = | Packet of Cstruct . t | Retx of int64 * Cstruct . t | Ack_of_error | Ack_of_eof | Error of Tftp_wire . errorcode * string | Request of string * mode with sexp let to_string t = t |> sexp_of_t |> Sexplib . Sexp . to_string_hum end |
module Failure = struct type t = | Unknown_tid | File_not_found of string | Invalid_packet | Unsupported_mode of mode | Rrq_refused | Unsupported_op of Tftp_wire . opcode with sexp let to_string t = t |> sexp_of_t |> Sexplib . Sexp . to_string_hum end |
type ret = | Ok of S . t * Tid . t * Success . t | Fail of S . t * Tid . t * Cstruct . t * Failure . t |
let obuf len = Cstruct . set_len ( Io_page . get_buf ~ n : 1 ( ) ) len |
let errorp ? msg error = let msg = match msg with | None -> Wire . errorcode_to_string error | Some m -> m in let msglen = String . length msg in let obuf = obuf ( Wire . sizeof_herr + msglen + 1 ) in Wire . ( set_herr_opcode obuf ( opcode_to_int ERROR ) ) ; Wire . ( set_herr_errorcode obuf ( errorcode_to_int error ) )... |
let datap server tid filename blockno f = Hashtbl . get server . S . files filename |> function | None -> let errp = errorp ~ msg : filename Wire . FILE_NOT_FOUND in Fail ( server , tid , errp , Failure . File_not_found filename ) | Some ( filesize , data ) -> let srcoff = Int64 . ( mul blockno 512L ) in let datlen = I... |
let handle_ack server tid inp = Hashtbl . get server . S . conns tid |> function | None -> let errp = errorp ~ msg ( : Tid . to_string tid ) Wire . UNKNOWN_TID in Fail ( server , tid , errp , Failure . Unknown_tid ) | Some ( filename , filesize , blockno ) -> let ackno = Wire . get_hdat_blockno inp |> Int64 . of_int in... |
let handle_error server tid inp = let error = Wire . ( inp |> get_herr_errorcode |> Wire . int_to_errorcode |> function | None -> UNDEFINED | Some c -> c ) in let ( msg , _ ) = Cstruct . shift inp Wire . sizeof_herr |> Wire . string0 in Ok ( server , tid , Success . Error ( error , msg ) ) |
let handle_rrq server tid inp = let ( filename , inp ) = Cstruct . shift inp Wire . sizeof_hreq |> Wire . string0 in let ( mode , _inp ) = Wire . string0 inp in match mode_of_string mode with | Unknown m as mode -> let errp = errorp ~ msg " : unknown mode " Wire . ILLEGAL_OP in Fail ( server , tid , errp , Failure . Un... |
let handle server sip spt dpt inp = let tid = Tid . ( sip , spt , dpt ) in Wire . ( inp |> get_hreq_opcode |> int_to_opcode |> function | None -> Fail ( server , tid , inp , Failure . Invalid_packet ) | Some o -> match o with | ACK -> handle_ack server tid inp | ERROR -> handle_error server tid inp | RRQ -> handle_rrq ... |
let src = Logs . Src . create " tftp " ~ doc " : tftp - mirage " |
module Log = ( val Logs . src_log src : Logs . LOG ) |
module S = struct module Make ( FS : V1_LWT . KV_RO ) ( STACK : V1_LWT . STACKV4 ) = struct module U = STACK . UDPV4 type t = { server : Tftp . S . t ; fs : FS . t ; s : STACK . t ; } let handle_failure { server ; fs ; s } ( sip , spt , dpt ) = Tftp . Failure . ( function | Unknown_tid -> Lwt . return_unit | File_not_f... |
module Hashtbl = struct include Hashtbl let get t ? default k = try Some ( Hashtbl . find t k ) with | Not_found -> ( match default with None -> ( ) | Some v -> Hashtbl . replace t k v ) ; default end |
module Make ( FS : V1_LWT . KV_RO ) ( S : V1_LWT . STACKV4 ) = struct module U = S . UDPV4 type tid = U . ipaddr * int * int let tid_to_string ( rip , rpt , lpt ) = sp " ( % s , % d , % d ) " ( Ipaddr . V4 . to_string rip ) rpt lpt type t = { c : C . t ; fs : FS . t ; s : S . t ; conns : ( tid , string * int64 * int64 ... |
UNDEFINED = 0 ; FILE_NOT_FOUND ; ACCESS_VIOLATION ; DISK_FULL ; ILLEGAL_OP ; UNKNOWN_TID ; FILE_EXISTS ; UNKNOWN_USER } as uint8_t ( sexp ) RRQ = 1 ; WRQ ; DATA ; ACK ; ERROR } as uint16_t ( sexp ) uint16_t opcode } as big_endian uint16_t opcode ; uint16_t blockno } as big_endian uint16_t opcode ; uint16_t errorcode } ... |
let string0 buf = let rec aux s i buf = let c = Cstruct . get_char buf i in if c = ' \ x00 ' then let string = s |> List . rev |> String . concat " " in ( string , Cstruct . shift buf ( i + 1 ) ) else aux ( Char . escaped c :: s ) ( i + 1 ) buf in aux [ ] 0 buf |
type ( ' input , ' output ) ' output t = { name : string option ; next : unit -> [ ` output of ' output | ` end_of_stream | ` not_ready ] ; feed : ' input -> unit ; stop : unit -> unit ; } |
let make_general ? name ~ next ~ feed ~ stop ( ) = { name ; next ; feed ; stop } |
let feed t i = t . feed i |
let next t = t . next ( ) |
let stop t = t . stop ( ) |
let name t = t . name |
let make ? name ~ feed ~ next ( ) = let stopped = ref false in make_general ? name ( ) ~ feed ( : fun x -> if not ! stopped then feed x else raise ( Feeding_stopped_transform Option ( . value ~ default " " : name ) name ) name ) name ~ next ( : fun ( ) -> next ! stopped ) stopped ~ stop ( : fun ( ) -> stopped := true )... |
let make_result ? name ~ feed ~ next ( ) = let stopped = ref false in let one_error_has_occured = ref false in make_general ? name ( ) ~ feed ( : fun x -> if not ! stopped then feed x else raise ( Feeding_stopped_transform Option ( . value ~ default " " : name ) name ) name ) name ~ next ( : fun ( ) -> if ! one_error_h... |
let of_function ? name f = let q = Queue . create ( ) in make ? name ~ feed ( : Queue . enqueue q ) q ( ) ~ next ( : fun stopped -> match Queue . dequeue q with | Some o -> ` output ( f o ) o | None -> if stopped then ` end_of_stream else ` not_ready ) not_ready |
let identity ? name ( ) = of_function ? name Fun . id |
let to_stream_fun tr en = let rec loop_until_ready tr en = match next tr with | ` output o -> Some o | ` end_of_stream -> None | ` not_ready -> begin match Stream . next en with | None -> stop tr ; loop_until_ready tr en | Some s -> feed tr s ; loop_until_ready tr en end in Stream . from ( fun _ -> loop_until_ready tr ... |
let in_channel_strings_to_stream ( ? buffer_size = 65536 ) 65536 ic tr = to_stream_fun tr ( Stream . strings_of_channel ~ buffer_size ic ) ic |
let stream_to_out_channel xs tr oc = Stream . iter ( to_stream_fun tr xs ) xs ~ f ( : Out_channel . output_string oc ) oc |
let on_input t ~ f = { t with feed = fun x -> t . feed ( f x ) x } |
let on_output t ~ f = { t with next = fun ( ) -> match t . next ( ) with | ` output o -> ` output ( f o ) o | ` not_ready -> ` not_ready | ` end_of_stream -> ` end_of_stream } |
let compose ta tb = let name = sprintf ( " compose <% s > <% s ) " > Option ( . value ~ default " " : ( name ta ) ta ) ta Option ( . value ~ default " " : ( name tb ) tb ) tb in make_general ~ name ( ) ~ feed ( : fun i -> feed ta i ) i ~ stop ( : fun ( ) -> stop ta ) ta ~ next ( : fun ( ) -> let call_tb_next ( ) = begi... |
let mix ta tb = let a_buffer = ref None in let name = sprintf ( " mix <% s > <% s ) " > Option ( . value ~ default " " : ( name ta ) ta ) ta Option ( . value ~ default " " : ( name tb ) tb ) tb in make_general ~ name ( ) ~ feed ( : fun ( a , b ) b -> feed ta a ; feed tb b ) b ~ stop ( : fun ( ) -> stop ta ; stop tb ) t... |
let filter_compose left right ~ destruct ~ reconstruct = let name = sprintf ( " part - compose <% s > <% s ) " > Option ( . value ~ default " " : ( name left ) left ) left Option ( . value ~ default " " : ( name right ) right ) right in make_general ~ name ( ) ~ feed ( : fun i -> feed left i ) i ~ stop ( : fun ( ) -> s... |
let split_and_merge ta tb ~ split ~ merge = let name = sprintf ( " merge <% s > <% s ) " > Option ( . value ~ default " " : ( name ta ) ta ) ta Option ( . value ~ default " " : ( name tb ) tb ) tb in make_general ~ name ( ) ~ feed ( : fun z -> match split z with | ` left a -> feed ta a | ` right b -> feed tb b ) b ~ st... |
let on_ok tr ~ f = on_output tr ~ f ( : function | Ok o -> Ok ( f o ) o | Error e -> Error e ) e |
let on_error tr ~ f = on_output tr ~ f ( : function | Ok o -> Ok o | Error e -> Error ( f e ) e ) e |
let compose_results ~ on_error ta tb = let name = sprintf ( " compose_results <% s > <% s ) " > Option ( . value ~ default " " : ( name ta ) ta ) ta Option ( . value ~ default " " : ( name tb ) tb ) tb in make_general ~ name ( ) ~ feed ( : fun i -> feed ta i ) i ~ stop ( : fun ( ) -> stop ta ) ta ~ next ( : fun ( ) -> ... |
let compose_results_merge_error ta tb = compose_results ta tb ~ on_error ( : function ` left e -> ` left e | ` right e -> ` right e ) e |
let compose_result_left ta tb = let name = sprintf ( " compose_result_left <% s > <% s ) " > Option ( . value ~ default " " : ( name ta ) ta ) ta Option ( . value ~ default " " : ( name tb ) tb ) tb in make_general ~ name ( ) ~ feed ( : fun i -> feed ta i ) i ~ stop ( : fun ( ) -> stop ta ) ta ~ next ( : fun ( ) -> let... |
let to_object tr = object method next = next tr method feed s = feed tr s method stop = stop tr end |
let of_object o = make_general ~ name ( : sprintf " of_object_ % d " ( Oo . id o ) o ) o ~ next ( : fun ( ) -> o # next ) next ~ feed ( : fun s -> o # feed s ) s ~ stop ( : fun ( ) -> o # stop ) stop ( ) |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.