text
stringlengths
0
601k
let main sandbox = let url = if sandbox then sandbox_url else url in let secret = Base64 . decode_exn secret in let logon_ts = Ptime_clock . now ( ) in let logon_fields = logon_fields ~ cancel_on_disconnect ` : Session ~ key ~ secret ~ passphrase ~ logon_ts in Fix_async . with_connection ~ logon_ts ~ heartbeat ( : Time...
let command = Command . async_or_error ~ summary " : Coinbase shell " begin let open Command . Let_syntax in [ % map_open let sandbox = flag " sandbox " no_arg ~ doc " : Use sandbox " and ( ) = Logs_async_reporter . set_level_via_param [ ] in fun ( ) -> Logs . set_reporter ( Logs_async_reporter . reporter ( ) ) ; main ...
let ( ) = Command . run command
type file_dump = File_dump of { text : string ; path : string ; }
type symbolic_file_dump = Symbolic_file_dump of { contents : Execution_env . insert Template . t ; }
type t = Command of { text : Execution_env . insert Command . t ; env : Execution_env . t ; container : [ ` Docker_container of Workflow . Docker_image . t | ` Singularity_container of Workflow . container_image ] option ; }
let container_env ( Command { container ; env ; text = _ } ) = match container with | None -> env | Some ( ` Docker_container _ ) -> Execution_env . dockerize env | Some ( ` Singularity_container _ ) -> Execution_env . singularize env
let rec file_dumps_of_tokens toks = List . map toks ~ f : file_dumps_of_token |> List . concat |> List . dedup_and_sort ~ compare : Caml . compare let open Template in function | NP | DEST | TMP | S _ | D _ | MEM -> [ ] | F contents -> Symbolic_file_dump { contents = contents ; } :: file_dumps_of_tokens contents |> Lis...
let rec file_dumps_of_command = let open Command in function | Simple_command toks -> file_dumps_of_tokens toks | And_list xs | Or_list xs | Pipe_list xs -> List . map xs ~ f : file_dumps_of_command |> List . concat |> List . dedup_and_sort ~ compare : Caml . compare
let string_of_token ( env : Execution_env . t ) = let open Template in function | S s -> s | D ( Execution_env . Path p ) -> env . dep p | D ( Execution_env . Path_list { elts ; quote ; sep } ) -> let quote = Option . value_map quote ~ default : Fn . id ~ f ( : fun c p -> sprintf " % c % s % c " c p c ) in List . map e...
let string_of_tokens env xs = List . map ~ f ( : string_of_token env ) xs |> String . concat
let compile_file_dump ( env : Execution_env . t ) ( container_env : Execution_env . t ) ( Symbolic_file_dump { contents } ) = let path = env . file_dump contents in let text = string_of_tokens container_env contents in File_dump { path ; text }
let file_dumps ( Command cmd as c ) = file_dumps_of_command cmd . text |> List . map ~ f ( : compile_file_dump cmd . env ( container_env c ) )
let par x = " ( " ^ x ^ " ) "
let command_path_deps cmd = Command . deps cmd ~ compare : Execution_env . compare_insert |> List . filter_map ~ f ( : function | Execution_env . Path p -> Some [ p ] | Path_list l -> Some l . elts | String _ -> None ) |> List . concat
module Mounts = struct type t = { host_paths : string list ; container_paths : string list ; } let of_pair ( host_paths , container_paths ) = { host_paths ; container_paths ; } let deps ~ env ( Command cmd ) = let open Execution_env in command_path_deps cmd . text |> List . map ~ f ( : Execution_env . container_mount e...
let singularity_mounts ( env : Execution_env . t ) ( container_env : Execution_env . t ) cmd script_fn = let binding ( m : Mounts . t ) = List . map2_exn m . host_paths m . container_paths ~ f ( : fun hp cp -> sprintf " % s :% s " hp cp ) in Mounts . [ deps ~ env cmd ; dest env container_env ; script script_fn ; file_d...
let rec string_of_command env = let open Command in function | Simple_command tokens -> string_of_tokens env tokens | And_list xs -> par ( string_of_command_aux env " && " xs ) | Or_list xs -> par ( string_of_command_aux env " || " xs ) | Pipe_list xs -> par ( string_of_command_aux env " | " xs ) List . map xs ~ f ( : ...
let text ( Command cmd as c ) = string_of_command ( container_env c ) cmd . text
let make env img cmd = let container = Execution_env . choose_container env . Execution_env . allowed_containers img in Command { text = cmd ; env ; container ; }
let write_file_dumps xs = let f ( File_dump { text ; path } ) = Lwt_io . ( with_file ~ mode : output path ( fun oc -> write oc text ) ) in Lwt_list . iter_p f xs
let uses_docker ( Command cmd ) = match cmd . container with | None | Some ( ` Singularity_container _ ) -> false | Some ( ` Docker_container _ ) -> true
let invocation ( Command cmd as c ) script = match cmd . container with | None -> sprintf " / bin / bash % s " script | Some ( ` Docker_container image ) -> let container_env = container_env c in sprintf " docker run -- log - driver = none -- rm % s % s % s % s % s - i % s / bin / bash % s " ( Mounts . deps ~ env : cmd...
let run ( Command cmd as c ) = let open Lwt in let script_file = Filename . concat cmd . env . tmp_dir " script . sh " in let invocation = invocation c script_file in Misc . remove_if_exists cmd . env . tmp_dir >>= fun ( ) -> Unix . mkdir_p cmd . env . tmp ; Out_channel . write_all ( Filename . concat cmd . env . tmp_d...
let container ( Command cmd ) = cmd . container
module C = struct include Tezos_context . Context let set_protocol = add_protocol end
let checkout index context_hash = Tezos_context . Context . checkout index context_hash >|= Option . map @@ fun ctxt -> Context . make ~ ops ~ ctxt ~ kind : Context ~ equality_witness ~ impl_name
let checkout_exn index context_hash = Tezos_context . Context . checkout_exn index context_hash >|= fun ctxt -> Context . make ~ ops ~ ctxt ~ kind : Context ~ equality_witness ~ impl_name
let wrap_disk_context ctxt = Context . make ~ ops ~ ctxt ~ kind : Context ~ equality_witness ~ impl_name
let unwrap_disk_context : t -> Tezos_context . Context . t = function | Context . Context { ctxt ; kind = Context ; _ } -> ctxt | Context . Context t -> Environment_context . err_implementation_mismatch ~ expected : impl_name ~ got : t . impl_name
let src = Logs . Src . create " fix . deribit . shell "
let hb msg = Fix . create ~ fields [ : Field . TestReqID . create msg ] MsgType . Heartbeat
let on_server_msg _w msg = match msg . Fix . typ with | SecurityList -> begin match msg . groups with | None -> assert false | Some ( _ , groups ) -> let symbols = List . fold_left groups ~ init [ ] : ~ f : begin fun a groups -> List . fold_left groups ~ init : a ~ f : begin fun a symbol -> match Field . find Field . S...
let on_client_cmd username w words = let words = String . split ~ on ' : ' @@ String . chop_suffix_exn words ~ suffix " :\ n " in match words with | " testreq " :: _ -> let fields = [ Field . TestReqID . create " a " ] in Pipe . write w ( Fix . create ~ fields MsgType . TestRequest ) | " seclist " :: _ -> let fields = ...
let get_key_secret sandbox = let key = if sandbox then " TOKEN_DERIBIT_TEST " else " TOKEN_DERIBIT " in match String . split ~ on ' ' :: ( Sys . getenv_exn key ) with | [ key ; secret ] -> key , secret | _ -> assert false
let main sandbox = let key , secret = get_key_secret sandbox in let ts = Ptime_clock . now ( ) in let logon_fields = logon_fields ~ cancel_on_disconnect : true ~ username : key ~ secret ~ ts in Fix_async . connect ~ sid ~ tid ~ version : Version . v44 ~ logon_fields ( if sandbox then test_url else url ) >>= fun { r ; w...
let command = Command . async ~ summary " : Deribit testnet shell " begin let open Command . Let_syntax in [ % map_open let sandbox = flag " sandbox " no_arg ~ doc " : Use sandbox " and ( ) = Logs_async_reporter . set_level_via_param [ ] in fun ( ) -> Logs . set_reporter ( Logs_async_reporter . reporter ( ) ) ; main sa...
let ( ) = Command . run command
let src = Logs . Src . create " fix . ftx . shell "
let hb msg = Fix . create ~ fields [ : Field . TestReqID . create msg ] MsgType . Heartbeat
let on_server_msg _w msg = match msg . Fix . typ with | _ -> Deferred . unit
let on_client_cmd w words = let words = String . split ~ on ' : ' @@ String . chop_suffix_exn words ~ suffix " :\ n " in match words with | " testreq " :: _ -> Pipe . write w ( testreq ~ testreqid " : a " ) | " orders " :: _ -> Pipe . write w ( order_status_request ( ) ) | " order " :: orderID :: _ -> Pipe . write w ( ...
let key , secret = match String . split ~ on ' ' :: ( Sys . getenv_exn " TOKEN_FTX " ) with | [ key ; secret ] -> key , secret | _ -> assert false
let main ( ) = let logon_ts = Ptime_clock . now ( ) in let logon_fields = logon_fields ~ cancel_on_disconnect ` : Session ~ key ~ secret ~ logon_ts in Fix_async . with_connection ~ logon_ts ~ heartbeat ( : Time_ns . Span . of_int_sec 30 ) ~ sid : key ~ tid ~ version : Version . v42 ~ logon_fields url ~ f : begin fun r ...
let command = Command . async_or_error ~ summary " : FTX shell " begin let open Command . Let_syntax in [ % map_open let ( ) = Logs_async_reporter . set_level_via_param [ ] in fun ( ) -> Logs . set_reporter ( Logs_async_reporter . reporter ( ) ) ; main ( ) ] end
let ( ) = Command . run command
let raw_context_gen = let open Tezos_shell_services . Block_services in let module MapGen = MakeMapGen ( TzString . Map ) in let open QCheck2 in let open Gen in let max_depth_factor = 10 in fix ( fun self current_depth_factor -> frequency [ ( max_depth_factor , map ( fun b -> Key b ) bytes_gen ) ; ( max_depth_factor , ...
let print_raw_context = Format . asprintf " % a " Tezos_shell_services . Block_services . pp_raw_context
let irmin_hashes = [ " CoVbip7pyXZDp1umo3cGUbCWJUA8wDkPbWR56wKqS434DiDSwGWC " ; " CoVuTbwGSJyu9xD7vYYxxcqCFwCPf55UBqu8iqRcHYrs3Gu31v8y " ; " CoUiEnajKeukmYFUgWTJF2z3v24MycpTaomF8a9hRzVy7as9hvgy " ; " CoVngnGTJfudgcayQqtz2ZyWTUFB6zHmhvV1itjncRzYS4wndhH8 " ; " CoVe9oDs8t8WgH9JHB3DqbvxCZw1Q5ky7qBsZfMiLeKe6RiSMHn1 " ; " Co...
let irmin_hash_gen = QCheck2 . Gen . oneofl irmin_hashes
let merkle_node_gen = let open Tezos_shell_services . Block_services in let module MapGen = MakeMapGen ( TzString . Map ) in let open QCheck2 . Gen in let max_depth_factor = 4 in fix ( fun self current_depth_factor -> frequency [ ( max_depth_factor , map ( fun ( kind , hash ) -> Hash ( kind , hash ) ) ( pair ( oneofl [...
let print_merkle_node = Format . asprintf " % a " Tezos_shell_services . Block_services . pp_merkle_node
let merkle_tree_gen = let open MakeMapGen ( TzString . Map ) in gen_of_size QCheck2 . Gen . ( 0 -- 5 ) ( QCheck2 . Gen . small_string ? gen : None ) merkle_node_gen
let print_merkle_tree = Format . asprintf " % a " Tezos_shell_services . Block_services . pp_merkle_tree
let create = Fix . make_create ~ sendercompid " : CLIENT1 " ~ targetcompid " : EXECUTOR " ( )
let logon ( ? heartbeat = 30 ) ( ) = let fields = Fix . Tag . [ S EncryptMethod , " 0 " ; S HeartBtInt , string_of_int heartbeat ; ] in create Logon fields
let logout ( ? response = false ) ( ) = create Logout ( if response then [ C 8500 , " 0 " ] else [ ] )
let heartbeat ? testreqid ( ) = let fields = ( match testreqid with | None -> [ ] | Some value -> Fix . Tag . [ S TestReqID , value ] ) in create Heartbeat fields
let testreq reqid = create TestRequest Fix . Tag . [ S TestReqID , reqid ]
let history = ref Int . Map . empty
let send_msg w mk_msg = let seqnum , msg = mk_msg ( ) in history := Int . Map . add ! history ~ key : seqnum ~ data : msg ; Pipe . write w msg
let on_incoming_msg w msg = match msg . Fix . typ with | Logout -> send_msg w logout >>= fun ( ) -> Shutdown . exit 0 | TestRequest -> begin match Fix . Tag . Map . find ( Fix . Tag . S TestReqID ) msg . fields with | exception Not_found -> Deferred . unit | testreqid -> send_msg w ( heartbeat ~ testreqid ) end | Resen...
let rec heartbeat_loop w period = after @@ Time . Span . of_string ( string_of_int period ^ " s " ) >>= fun ( ) -> send_msg w heartbeat >>= fun ( ) -> heartbeat_loop w period
let on_user_cmd w msg = match List . hd_exn @@ String . split msg ~ on ' : ' with | " LOGON " -> send_msg w logon | " LOGOUT " -> send_msg w logout | " TESTREQ " -> send_msg w ( fun ( ) -> testreq @@ Uuid . ( create ( ) |> to_string ) ) | command -> info " Unsupported command : % s " command ; Deferred . unit
let main host port = Fix_async . with_connection ~ tls ` : Noconf ~ host ~ port ( ) >>= fun ( r , w ) -> info " Connected to % s % d " host port ; Signal . ( handle terminating ~ f ( : fun _ -> don ' t_wait_for @@ send_msg w logout ) ) ; Deferred . any [ Pipe . iter Reader . ( stdin |> Lazy . force |> pipe ) ~ f ( : on...
let main ( host , port ) ( ) = don ' t_wait_for @@ main host port ; never_returns @@ Scheduler . go ( )
let command = let spec = let open Command . Spec in empty +> anon ( t2 ( " host " %: string ) ( " port " %: int ) ) in Command . basic ~ summary " : FIX test shell " spec main
let ( ) = Command . run command
let genesis_block_hash = Block_hash . of_b58check_exn " BLockGenesisGenesisGenesisGenesisGenesisGeneskvg68z "
let genesis_protocol_hash = Protocol_hash . of_b58check_exn " ProtoDemoNoopsDemoNoopsDemoNoopsDemoNoopsDemo6XBoYp "
let genesis_time = Time . Protocol . of_seconds 0L
let genesis_protocol = match Registered_protocol . get genesis_protocol_hash with | None -> assert false | Some genesis_protocol -> genesis_protocol
module Genesis_proto = ( val genesis_protocol )
let state_genesis_block = { Genesis . time = genesis_time ; block = genesis_block_hash ; protocol = genesis_protocol_hash ; }
let genesis : Genesis . t = { time = genesis_time ; block = genesis_block_hash ; protocol = genesis_protocol_hash ; }
let chain_id = Chain_id . of_block_hash genesis_block_hash
let patch_context ctxt = Context . add ctxt [ " version " ] ( Bytes . of_string " demo_noops " ) >>= return
let init_chain ( ? history_mode = History_mode . Archive ) base_dir = let store_dir = base_dir // " store " in let context_dir = base_dir // " context " in Store . init ~ store_dir ~ context_dir ~ history_mode ~ allow_testchains : true ~ patch_context state_genesis_block >>= function | Error err -> Format . kasprintf L...
let init_mock_p2p chain_name = let open Connection_metadata in let peer_metadata_cfg : _ P2p_params . peer_meta_config = { peer_meta_encoding = Peer_metadata . encoding ; peer_meta_initial = Peer_metadata . empty ; score = Peer_metadata . score ; } in let message_cfg = Distributed_db_message . cfg chain_name in let c_m...
module Unix = UnixLabels val mutable history = ( [ ] : ' a list ) val mutable count = 0 method empty = history = [ ] method add s = count <- 0 ; history <- s :: history method next = let s = List . nth history count in count <- ( count + 1 ) mod List . length history ; s method previous = let l = List . length history ...
let protect f x = try f x with _ -> ( ) ; ;
let count = ref 0 let view = GText . view ~ cursor_visible : false ~ editable : false ? packing ? show ( ) in let buf = view # buffer in let process = Spawn . create_process ~ env prog ( Array . of_list args ) in let inchan = process . Spawn . inchan in let outchan = process . Spawn . outchan in let errchan = process ....
module type Field_intf = sig type t val size_in_bits : int val negate : t -> t val ( - ) : t -> t -> t val ( + ) : t -> t -> t val ( * ) : t -> t -> t val ( / ) : t -> t -> t val inv : t -> t val one : t val of_int : int -> t end
let two_to_the ( type f ) f ( module F : Field_intf with type t = f ) f = let rec two_to_the n = if n = 0 then F . one else let r = two_to_the ( n - 1 ) 1 in F ( . r + r ) r in two_to_the
module type S = sig [ %% versioned : module Stable : sig module V1 : sig type ' f t [ @@ deriving sexp , compare , equal , yojson , hash ] hash end end ] end val typ : ( ' a , ' b , ' f ) ' f Snarky_backendless . Typ . t -> ( ' a t , ' b t , ' f ) ' f Snarky_backendless . Typ . t val map : ' a t -> f ( : ' a -> ' b ) '...
module Type1 = struct [ %% versioned module Stable = struct module V1 = struct type ' f t = Shifted_value of ' f [ @@ deriving sexp , compare , equal , yojson , hash ] hash end end ] end let typ f = let there ( Shifted_value x ) x = x in let back x = Shifted_value x in Snarky_backendless . Typ ( . transport_var ( trans...
module Type2 = struct [ %% versioned module Stable = struct module V1 = struct type ' f t = Shifted_value of ' f [ @@ deriving sexp , compare , equal , yojson , hash ] hash end end ] end let typ f = let there ( Shifted_value x ) x = x in let back x = Shifted_value x in Snarky_backendless . Typ ( . transport_var ( trans...
type reg = { p_v : int ; p_s : int ; p_a : int ; pulse : bool ; invert : bool ; }
let genReg ? pulse ( : pulse = false ) ? invert ( : invert = false ) pin_value pin_shift pin_apply = { p_v = pin_value ; p_s = pin_shift ; p_a = pin_apply ; pulse ; invert }
let write pin value = digitalWrite pin ( if value then 1 else 0 )
let initReg ? nb_reg ( : nb_reg = 1 ) reg = pinMode reg . p_v 1 ; pinMode reg . p_s 1 ; pinMode reg . p_a 1 ; write reg . p_v false ; write reg . p_s false ; write reg . p_a false ; Array . make ( 8 * nb_reg ) false
let shift reg value = write reg . p_s false ; write reg . p_v ( value <> reg . invert ) ; write reg . p_s true
let validate reg = write reg . p_a true ; write reg . p_a false
let applyRegAll reg leds = write reg . p_a false ; for i = ( Array . length leds ) - 1 downto 0 do shift reg leds . ( i ) done ; validate reg
let applyRegPulse reg leds ? d_t ( : d_t = 3000 ) time = let t = Unix . gettimeofday ( ) in let first_time = ref true in write reg . p_a false ; for i = ( Array . length leds ) - 1 downto 0 do shift reg false done ; shift reg true ; while ! first_time || Unix . gettimeofday ( ) . - t < time do for i = 0 to ( Array . le...
let applyReg reg leds time = if reg . pulse then applyRegPulse reg leds time else begin applyRegAll reg leds ; delay ( int_of_float ( time . * 1000 . ) ) end
let clearLeds leds = Array . iteri ( fun i x -> ( leds . ( i ) <- false ) ) leds
let lightLeds leds = Array . iteri ( fun i x -> ( leds . ( i ) <- true ) ) leds
let printBoolArray t = for k = 0 to Array . length t - 1 do Printf . printf " % b ; " t . ( k ) done ; Printf . printf " \ n " %!
let findLedNumber reg ? time_answer ( : time_answer = 3 ) leds0 = let makeIntervalArray leds a b = Printf . printf " % d ; % d " a b ; Array . iteri ( fun i x -> leds . ( i ) <- ( ( a <= i ) && ( i < b ) ) ) leds in let n = Array . length leds0 in let leds = Array . make n false in let i = ref 0 in let j = ref n in whi...