text
stringlengths
0
601k
let encoding = let open Data_encoding in conv ( fun { hash ; inbox_size } -> ( hash , inbox_size ) ) ( fun ( hash , inbox_size ) -> { hash ; inbox_size } ) ( obj2 ( req " hash " hash_encoding ) ( req " inbox_size " int64 ) )
let message_encoding = let open Data_encoding in obj3 ( req " parent " hash_encoding ) ( req " payload " string ) ( req " level " Raw_level_repr . encoding )
let number_of_available_messages { inbox_size ; hash = _ } = Z . of_int64 inbox_size
let empty = { hash = Inbox_hash . zero ; inbox_size = 0L }
let add_message { hash ; inbox_size } message level = let message_bytes = Data_encoding . Binary . to_bytes_exn message_encoding ( hash , message , level ) in let hash = Inbox_hash . hash_bytes [ message_bytes ] in { hash ; inbox_size = Int64 . succ inbox_size }
let add_messages messages level inbox = List . fold_left ( fun inbox message -> add_message inbox message level ) inbox messages
let consume_n_messages n { hash ; inbox_size } = if Compare . Int . ( n < 0 ) then None else if Compare . Int64 . ( Int64 . of_int n > inbox_size ) then None else Some { hash ; inbox_size = Int64 . sub inbox_size ( Int64 . of_int n ) }
module Parameters = struct type persistent_state = { data_dir : string ; rpc_host : string ; rpc_port : int ; node : Node . t ; mutable pending_ready : unit option Lwt . u list ; } type session_state = { mutable ready : bool } let base_default_name = " sc - rollup - node " let default_colors = Log . Color . [ | FG . gr...
let check_error ? exit_code ? msg sc_node = match sc_node . status with | Not_running -> Test . fail " Smart - contract rollup node % s is not running , it has no stderr " ( name sc_node ) | Running { process ; _ } -> Process . check_error ? exit_code ? msg process
let wait sc_node = match sc_node . status with | Not_running -> Test . fail " Smart - contract rollup node % s is not running , cannot wait for it to \ terminate " ( name sc_node ) | Running { process ; _ } -> Process . wait process
let name sc_node = sc_node . name
let rpc_host sc_node = sc_node . persistent_state . rpc_host
let rpc_port sc_node = sc_node . persistent_state . rpc_port
let endpoint sc_node = Printf . sprintf " http ://% s :% d " ( rpc_host sc_node ) ( rpc_port sc_node )
let data_dir sc_node = sc_node . persistent_state . data_dir
let spawn_command sc_node = Process . spawn ~ name : sc_node . name ~ color : sc_node . color sc_node . path
let spawn_config_init sc_node rollup_address = spawn_command sc_node [ " config " ; " init " ; " on " ; rollup_address ; " -- data - dir " ; data_dir sc_node ; " -- rpc - addr " ; rpc_host sc_node ; " -- rpc - port " ; string_of_int @@ rpc_port sc_node ; ]
let config_init sc_node rollup_address = let process = spawn_config_init sc_node rollup_address in let * output = Process . check_and_read_stdout process in match output =~* rex " Smart - contract rollup node configuration written in ( [ ^\ n ] ) " * with | None -> failwith " Smart - contract rollup node configuration ...
module Config_file = struct let filename sc_node = sf " % s / config . json " @@ data_dir sc_node let read sc_node = JSON . parse_file ( filename sc_node ) let write sc_node config = with_open_out ( filename sc_node ) @@ fun chan -> output_string chan ( JSON . encode config ) let update sc_node update = read sc_node |>...
let trigger_ready sc_node value = let pending = sc_node . persistent_state . pending_ready in sc_node . persistent_state . pending_ready <- [ ] ; List . iter ( fun pending -> Lwt . wakeup_later pending value ) pending
let set_ready sc_node = ( match sc_node . status with | Not_running -> ( ) | Running status -> status . session_state . ready <- true ) ; trigger_ready sc_node ( Some ( ) )
let handle_event sc_node { name ; value = _ } = match name with " sc_rollup_node_is_ready . v0 " -> set_ready sc_node | _ -> ( )
let check_event ? where sc_node name promise = let * result = promise in match result with | None -> raise ( Terminated_before_event { daemon = sc_node . name ; event = name ; where } ) | Some x -> return x
let wait_for_ready sc_node = match sc_node . status with | Running { session_state = { ready = true ; _ } ; _ } -> unit | Not_running | Running { session_state = { ready = false ; _ } ; _ } -> let ( promise , resolver ) = Lwt . task ( ) in sc_node . persistent_state . pending_ready <- resolver :: sc_node . persistent_s...
let create ( ? path = Constant . sc_rollup_node ) ? name ? color ? data_dir ? event_pipe ( ? rpc_host = " 127 . 0 . 0 . 1 " ) ? rpc_port ( node : Node . t ) = let name = match name with None -> fresh_name ( ) | Some name -> name in let data_dir = match data_dir with None -> Temp . dir name | Some dir -> dir in let rpc_...
let make_arguments node = [ " -- endpoint " ; Printf . sprintf " http ://% s :% d " ( Node . rpc_host node . persistent_state . node ) ( Node . rpc_port node . persistent_state . node ) ; ]
let do_runlike_command node arguments = if node . status <> Not_running then Test . fail " Smart contract rollup node % s is already running " node . name ; let on_terminate _status = trigger_ready node None ; unit in let arguments = make_arguments node @ arguments in run node { ready = false } arguments ~ on_terminate
let run node = do_runlike_command node [ " run " ; " -- data - dir " ; node . persistent_state . data_dir ]
let run node = let * ( ) = run node in let * ( ) = wait_for_ready node in return ( )
module PVM = struct type boot_sector = string let boot_sector_encoding = Data_encoding . string let boot_sector_of_string s = s end
module Address = struct let prefix = " scr1 " let encoded_size = 37 let decoded_prefix = " \ 001 \ 118 \ 132 \ 217 " module H = Blake2B . Make ( Base58 ) ( struct let name = " Sc_rollup_hash " let title = " A smart contract rollup address " let b58check_prefix = decoded_prefix let size = Some 20 end ) include H let ( )...
module Commitment_hash = struct let prefix = " scc1 " let encoded_size = 54 module H = Blake2B . Make ( Base58 ) ( struct let name = " commitment_hash " let title = " The hash of a commitment of a smart contract rollup " let b58check_prefix = commitment_hash_prefix let size = None end ) include H let ( ) = Base58 . che...
module State_hash = struct let prefix = " scs1 " let encoded_size = 54 module H = Blake2B . Make ( Base58 ) ( struct let name = " state_hash " let title = " The hash of the VM state of a smart contract rollup " let b58check_prefix = state_hash_prefix let size = None end ) include H let ( ) = Base58 . check_encoded_pref...
let description = " A smart contract rollup is identified by a base58 address starting with " ^ Address . prefix
type error += Invalid_sc_rollup_address of string
let error_description = Format . sprintf " A smart contract rollup address must be a valid hash starting with ' % s ' . " Address . prefix
let ( ) = let open Data_encoding in register_error_kind ` Permanent ~ id " : rollup . invalid_smart_contract_rollup_address " ~ title " : Invalid smart contract rollup address " ~ pp ( : fun ppf x -> Format . fprintf ppf " Invalid smart contract rollup address % S " x ) ~ description : error_description ( obj1 ( req " ...
let of_b58check s = match Base58 . decode s with | Some ( Address . Data hash ) -> ok hash | _ -> Error ( Format . sprintf " Invalid_sc_rollup_address % s " s )
let encoding = let open Data_encoding in def " rollup_address " ~ title " : A smart contract rollup address " ~ description ( conv_with_guard Address . to_b58check of_b58check string )
let rpc_arg = let construct = Address . to_b58check in let destruct hash = Result . map_error ( fun _ -> error_description ) ( of_b58check hash ) in RPC_arg . make ~ descr " : A smart contract rollup address . " ~ name " : sc_rollup_address " ~ construct ~ destruct ( )
module Index = struct type t = Address . t let path_length = 1 let to_path c l = let raw_key = Data_encoding . Binary . to_bytes_exn encoding c in let ( ` Hex key ) = Hex . of_bytes raw_key in key :: l let of_path = function | [ key ] -> Option . bind ( Hex . to_bytes ( ` Hex key ) ) ( Data_encoding . Binary . of_bytes...
module Commitment_hash_index = struct include Commitment_hash end
module Number_of_messages = Bounded . Int32 . Make ( struct let min_int = 1l let max_int = 4096l end )
module Number_of_ticks = Bounded . Int32 . Make ( struct let min_int = 1l let max_int = Int32 . max_int end )
module Commitment = struct type t = { compressed_state : State_hash . t ; inbox_level : Raw_level_repr . t ; predecessor : Commitment_hash . t ; number_of_messages : Number_of_messages . t ; number_of_ticks : Number_of_ticks . t ; } let encoding = let open Data_encoding in conv ( fun { compressed_state ; inbox_level ; ...
module Kind = struct type t = Example_arith let example_arith_case = Data_encoding . ( case ~ title " : Example_arith smart contract rollup kind " ( Tag 0 ) unit ( function Example_arith -> Some ( ) ) ( fun ( ) -> Example_arith ) ) let encoding = Data_encoding . union ~ tag_size ` : Uint16 [ example_arith_case ] end
let originate ctxt ~ kind ~ boot_sector = Raw_context . increment_origination_nonce ctxt >>?= fun ( ctxt , nonce ) -> Sc_rollup_repr . Address . from_nonce nonce >>?= fun address -> Storage . Sc_rollup . PVM_kind . add ctxt address kind >>= fun ctxt -> Storage . Sc_rollup . Boot_sector . add ctxt address boot_sector >>...
let kind ctxt address = Storage . Sc_rollup . PVM_kind . find ctxt address
let add_messages ctxt rollup messages = Storage . Sc_rollup . Inbox . get ctxt rollup >>=? fun ( ctxt , inbox ) -> let { Level_repr . level ; _ } = Raw_context . current_level ctxt in let inbox = Sc_rollup_inbox . add_messages messages level inbox in Storage . Sc_rollup . Inbox . update ctxt rollup inbox >>=? fun ( ctx...
let inbox ctxt rollup = Storage . Sc_rollup . Inbox . get ctxt rollup >>=? fun ( ctxt , res ) -> return ( res , ctxt )
let creds = { Creds . aws_access_key_id = Keys . k ; Creds . aws_secret_access_key = Keys . c }
let list_domains ( ) = Lwt_main . run ( SDB . list_domains creds ( ) >>= function | ` Ok l -> List . iter print_endline l ; return ( ) | ` Error ( code , msg ) -> Printf . printf " Panic : % s \ n " msg ; return ( ) )
let create_domain name = Lwt_main . run ( SDB . create_domain creds name >>= function | ` Ok -> return ( ) | ` Error ( code , msg ) -> Printf . printf " Panic : % s \ n " msg ; return ( ) )
let delete_domain name = Lwt_main . run ( SDB . delete_domain creds name >>= function | ` Ok -> return ( ) | ` Error ( code , msg ) -> Printf . printf " Panic : % s \ n " msg ; return ( ) )
let get_attributes domain item = Lwt_main . run ( SDB . get_attributes ~ encoded : false creds domain item >>= function | ` Ok l -> List . iter ( fun ( n , v ) -> Printf . printf " % s -> % s \ n " n v ) l ; return ( ) | ` Error ( code , msg ) -> Printf . printf " Panic : % s \ n " msg ; return ( ) )
let rec select token expr = SDB . select ~ encoded : false ~ token creds expr >>= function | ` Ok ( l , nxt ) -> List . iter ( fun ( name , attrs ) -> print_endline name ; List . iter ( fun ( name , value ) -> Printf . printf " % s -> % s \ n " name ( match value with Some s -> s | None -> " none " ) ) attrs ) l ; ( ma...
let _ = Lwt_main . run ( select None Sys . argv . ( 1 ) )
module Make = functor ( HC : Aws_sigs . HTTP_CLIENT ) -> struct module C = CalendarLib . Calendar module P = CalendarLib . Printer . CalendarPrinter module X = My_xml open Lwt open Creds module Util = Aws_util exception Error of string let sprint = Printf . sprintf let print = Printf . printf let signed_request ? regio...
let _ = Callback . register_exception " SDL_init_exception " ( SDL_init_exception " Any string " )
type subsystem = [ | ` TIMER | ` AUDIO | ` VIDEO | ` CDROM | ` JOYSTICK ] [ < subsystem | ` NOPARACHUTE | ` EVENTTHREAD | ` EVERYTHING ] list -> unit = " sdl_init "
type version = { major : int ; minor : int ; patch : int ; }
let string_of_version v = String . concat " . " ( List . map string_of_int [ v . major ; v . minor ; v . patch ] )
let rwops_from_mem buff = let rw = _rwops_from_mem buff in Gc . finalise _rwops_in_finalise rw ; rw
type format = | AUDIO_U8 | AUDIO_S8 | AUDIO_U16LSB | AUDIO_S16LSB | AUDIO_U16MSB | AUDIO_S16MSB | AUDIO_U16 | AUDIO_S16 | AUDIO_S32LSB | AUDIO_S32MSB | AUDIO_S32 | AUDIO_F32LSB | AUDIO_F32MSB | AUDIO_F32 | AUDIO_U16SYS | AUDIO_S16SYS | AUDIO_S32SYS | AUDIO_F32SYS unit -> string array = " caml_SDL_GetAudioDrivers " = " ...
type status = | Stopped | Playing | Paused = " caml_SDL_GetAudioStatus "
let string_of_status = function | Stopped -> " Stopped " | Playing -> " Playing " | Paused -> " Paused " = " caml_SDL_PauseAudio " = " caml_SDL_LockAudio " = " caml_SDL_UnlockAudio " = " caml_SDL_CloseAudio "
type audio_spec = " caml_SDL_alloc_audio_spec " = " caml_SDL_free_audio_spec "
type audio_buffer = " caml_SDL_LoadWAV " = " caml_SDL_FreeWAV "
type audio_device_id = " caml_SDL_OpenAudioDevice_simple " = " caml_SDL_QueueAudio " = " caml_SDL_UnpauseAudioDevice " = " caml_SDL_PauseAudioDevice " = " caml_SDL_CloseAudioDevice "
let _ = Callback . register_exception " SDLcdrom_exception " ( SDLcdrom_exception " " ) ; Callback . register_exception " SDLcdrom_nocd " Trayempty
type cdrom_drive_status = | CD_TRAYEMPTY | CD_STOPPED | CD_PLAYING | CD_PAUSED
type track_type = | TRACK_AUDIO | TRACK_DATA
type track = { id : int ; kind : track_type ; length : int ; offset : int ; }
type cdrom_info = { num_tracks : int ; curr_track : int ; curr_frame : int ; tracks : track array ; } start_track : int -> start_frame : int -> num_tracks : int -> num_frames : int -> unit = " sdlcdrom_play_tracks "
let cd_play_track cdrom { id = num } = cd_play_tracks cdrom ( num - 1 ) 0 1 0 ; ;
let msf_of_frames f = let s ' = f / 75 in let m = s ' / 60 in ( m , s ' mod 60 , f mod 75 )
let frames_of_msf ( m , s , f ) = m * 60 * 75 + s * 75 + f
let _ = Callback . register_exception " sdlevent_exn " ( Event_exn " " )
type active_state = | MOUSEFOCUS | INPUTFOCUS | APPACTIVE = " mlsdlevent_get_app_state "
type active_event = { gain : bool ; ae_state : active_state list ; }
type switch_state = | RELEASED | PRESSED
type keyboard_event = { ke_which : int ; ke_state : switch_state ; keysym : Sdlkey . t ; keymod : Sdlkey . mod_state ; keycode : char ; unicode : int ; }
type mousemotion_event = { mme_which : int ; mme_state : Sdlmouse . button list ; mme_x : int ; mme_y : int ; mme_xrel : int ; mme_yrel : int ; }
type mousebutton_event = { mbe_which : int ; mbe_button : Sdlmouse . button ; mbe_state : switch_state ; mbe_x : int ; mbe_y : int ; }
type joyaxis_event = { jae_which : int ; jae_axis : int ; jae_value : int ; }
type joyball_event = { jle_which : int ; jle_ball : int ; jle_xrel : int ; jle_yrel : int ; }
type joyhat_event = { jhe_which : int ; jhe_hat : int ; jhe_value : Sdljoystick . hat_value ; }
type joybutton_event = { jbe_which : int ; jbe_button : int ; jbe_state : switch_state ; }
type event = | ACTIVE of active_event | KEYDOWN of keyboard_event | KEYUP of keyboard_event | MOUSEMOTION of mousemotion_event | MOUSEBUTTONDOWN of mousebutton_event | MOUSEBUTTONUP of mousebutton_event | JOYAXISMOTION of joyaxis_event | JOYBALLMOTION of joyball_event | JOYHATMOTION of joyhat_event | JOYBUTTONDOWN of j...
let string_of_event = function | ACTIVE _ -> " active " | KEYDOWN _ -> " key down " | KEYUP _ -> " key up " | MOUSEMOTION _ -> " mouse motion " | MOUSEBUTTONDOWN _ -> " mouse button down " | MOUSEBUTTONUP _ -> " mouse button up " | JOYAXISMOTION _ -> " joystick axis motion " | JOYBALLMOTION _ -> " joystick ball motion ...
type event_kind = | ACTIVE_EVENT | KEYDOWN_EVENT | KEYUP_EVENT | MOUSEMOTION_EVENT | MOUSEBUTTONDOWN_EVENT | MOUSEBUTTONUP_EVENT | JOYAXISMOTION_EVENT | JOYBALL_EVENT | JOYHAT_EVENT | JOYBUTTONDOWN_EVENT | JOYBUTTONUP_EVENT | QUIT_EVENT | SYSWM_EVENT | RESIZE_EVENT | EXPOSE_EVENT | USER_EVENT
let make_mask = List . fold_left ( fun acc evt -> acc lor ( match evt with | ACTIVE_EVENT -> active_mask | KEYDOWN_EVENT -> keydown_mask | KEYUP_EVENT -> keyup_mask | MOUSEMOTION_EVENT -> mousemotion_mask | MOUSEBUTTONDOWN_EVENT -> mousebuttondown_mask | MOUSEBUTTONUP_EVENT -> mousebuttonup_mask | JOYAXISMOTION_EVENT -...
let enable_events mask = set_state_by_mask mask true
let disable_events mask = set_state_by_mask mask false
let of_mask mask = List . fold_left ( fun acc ( evt_t , m ) -> if mask land m <> 0 then evt_t :: acc else acc ) [ ] [ ( ACTIVE_EVENT , active_mask ) ;
module Old = struct type keyboard_event_func = Sdlkey . t -> switch_state -> int -> int -> unit type mouse_event_func = Sdlmouse . button -> switch_state -> int -> int -> unit type mousemotion_event_func = int -> int -> unit type idle_event_func = unit -> unit type resize_event_func = int -> int -> unit let keyboard_ev...
let log fmt = Format . printf ( fmt ^^ " . " ) @
let log_err fmt = Format . eprintf ( fmt ^^ " . " ) @
let close_joysticks joysticks = List . iter Sdl . joystick_close joysticks
let open_joysticks ( ) = match Sdl . num_joysticks ( ) with let joysticks = ref [ ] in for i = 0 to count - 1 do begin match Sdl . joystick_open i with | Error ( ` Msg e ) -> log_err " Could not open joystick % d : % s " i e | Ok j -> joysticks := j :: ! joysticks ; begin match Sdl . joystick_name j with | Error ( ` Ms...