text stringlengths 0 601k |
|---|
let sum_until_negative_0 a = let iter = { i = 0 ; sum = 0 } in let finished = ref false in while ! finished do let element = a . ( iter . i ) in if element < 0 then finished := true else ( iter . i <- iter . i + 1 ; iter . sum <- iter . sum + element ) done ; iter . sum |
let sum_until_negative_1 a = let iter = { i = 0 ; sum = 0 } in let finished = ref false in while ! finished do let element = a . ( iter . i ) in if element < 0 then finished := true else ( iter . i <- iter . i + 1 ; iter . sum <- iter . sum + element ) done ; iter . sum |
let sum_until_negative_2 a = let iter = { i = 0 ; sum = 0 } in let finished = ref false in while ! finished do let element = a . ( iter . i ) in if element < 0 then finished := true else ( iter . i <- iter . i + 1 ; iter . sum <- iter . sum + element ) done ; iter . sum if a < b then shift_left f g ( a + 1 ) b ( c + 1 ... |
let sum_until_negative_3 a = let iter = { i = 0 ; sum = 0 } in let exception Finish of int in try while iter . i < Array . length a do if a . ( iter . i ) < 0 then raise ( Finish iter . sum ) else ( iter . sum <- iter . sum + a . ( iter . i ) ; iter . i <- iter . i + 1 ) done ; iter . sum with Finish i -> i |
let main ( ) = sum_until_negative_3 [ | 1 ; 2 ; 3 ; 4 ; - 5 ; - 6 ; - 7 ; - 8 ] | |
type t = { id : string ; port : int ; exec : Tezos_executable . t } |
let base_dir t ~ state = Paths . root state // sprintf " Admin - client - base -% s " t . id |
let of_client ~ exec n = let id = sprintf " A -% s " n . Tezos_client . id in let port = n . Tezos_client . port in { id ; port ; exec } |
let of_node ~ exec n = let id = sprintf " C -% s " n . Tezos_node . id in let port = n . Tezos_node . rpc_port in { id ; port ; exec } |
let make_command state t args = let open Tezos_executable . Make_cli in Tezos_executable . call state t . exec ~ path ( : base_dir t ~ state // " exec - admin " ) ( optf " port " " % d " t . port @ opt " base - dir " ( base_dir ~ state t ) @ args ) |
module Command_error = struct let failf ? client ? args fmt = let attach = Option . value_map ~ default [ ] : args ~ f ( : fun l -> [ ( " arguments " , ` String_list l ) ] ) @ Option . value_map ~ default [ ] : client ~ f ( : fun c -> [ ( " client - id " , ` String_value c . id ) ] ) in Process_result . Error . wrong_b... |
let successful_command admin state args = Running_processes . run_cmdf state " sh - c % s " ( make_command state admin args |> Genspio . Compile . to_one_liner |> Caml . Filename . quote ) >>= fun res -> Console . display_errors_of_command state res >>= function | true -> return res | false -> failf ~ args " Admin - co... |
let inject_protocol admin state ~ path = successful_command admin state [ " inject " ; " protocol " ; path ] >>= fun res -> String . concat ~ sep " : " res # out |> String . split ~ on ' : ' |> List . map ~ f : String . strip |> ( function | _ :: _ :: hash :: _ when Char . equal hash . [ 0 ] ' P ' -> return hash | _ ->... |
type t = { id : string ; port : int ; exec : Tezos_executable . t } |
let no_node_client ~ exec = { id = " C - null " ; port = 0 ; exec } |
let of_node ~ exec n = let id = sprintf " C -% s " n . Tezos_node . id in let port = n . Tezos_node . rpc_port in { id ; port ; exec } |
let base_dir t ~ state = Paths . root state // sprintf " Client - base -% s " t . id |
let client_call ( ? wait = " none " ) state t args = " -- wait " :: wait :: optf " port " " % d " t . port @ opt " base - dir " ( base_dir ~ state t ) @ args |
let client_command ? wait state t args = Tezos_executable . call state t . exec ~ path ( : base_dir t ~ state // " exec - client " ) ( client_call ? wait state t args ) |
module Command_error = struct let failf ? result ? client ? args fmt = let attach = Option . value_map ~ default [ ] : args ~ f ( : fun l -> [ ( " arguments " , ` String_list l ) ] ) @ Option . value_map ~ default [ ] : client ~ f ( : fun c -> [ ( " client - id " , ` String_value c . id ) ] ) @ Option . value_map ~ def... |
let run_client_cmd ? id_prefix ? wait state client args = Running_processes . run_cmdf ? id_prefix state " sh - c % s " ( client_command ? wait state client args |> Genspio . Compile . to_one_liner |> Caml . Filename . quote ) |
let client_cmd ? id_prefix ( ? verbose = true ) ? wait state ~ client args = Running_processes . run_cmdf ? id_prefix state " sh - c % s " ( client_command ? wait state client args |> Genspio . Compile . to_one_liner |> Caml . Filename . quote ) >>= fun res -> let unix_success = Poly . equal res # status ( Lwt_unix . W... |
let successful_client_cmd ? id_prefix ( ? verbose = true ) ? wait state ~ client args = client_cmd ? id_prefix ~ verbose state ? wait ~ client args >>= fun ( success , result ) -> match success with | true -> return result | false -> failf ~ result ~ client ~ args " Client - command failure : % s " ( String . concat ~ ... |
let wait_for_node_bootstrap state client = let try_once ( ) = run_client_cmd ~ id_prefix ( : client . id ^ " - bootstrapped " ) state client [ " bootstrapped " ] >>= fun res -> return Poly . ( res # status = Unix . WEXITED 0 ) in let attempts = 20 in let rec loop nth = if nth >= attempts then failf " Bootstrapping fail... |
let import_secret_key state client ~ name ~ key = successful_client_cmd state ~ client [ " import " ; " secret " ; " key " ; name ; key ; " -- force " ] >>= fun _ -> return ( ) |
let register_as_delegate state client ~ key_name = successful_client_cmd state ~ client [ " register " ; " key " ; key_name ; " as " ; " delegate " ] >>= fun _ -> return ( ) |
let rpc state ~ client meth ~ path = let args = match meth with | ` Get -> [ " rpc " ; " get " ; path ] | ` Post s -> [ " rpc " ; " post " ; path ; " with " ; s ] in successful_client_cmd state ~ client args >>= fun res -> let output = String . concat ~ sep " :\ n " res # out in try let json = Jqo . of_string output in... |
let activate_protocol state client protocol = let timestamp = match protocol . Tezos_protocol . timestamp_delay with | None -> [ ] | Some delay -> ( let now = Ptime_clock . now ( ) in match Ptime . add_span now ( Ptime . Span . of_int_s delay ) with | None -> invalid_arg " activate_protocol_script : protocol . timestam... |
let find_applied_in_mempool state ~ client ~ f = successful_client_cmd state ~ client [ " rpc " ; " get " ; " / chains / main / mempool / pending_operations " ] >>= fun res -> try let json = Jqo . of_string ( String . concat ~ sep " :\ n " res # out ) in let found = Jqo . field ~ k " : applied " json |> Jqo . list_find... |
let mempool_has_operation state ~ client ~ kind = find_applied_in_mempool state ~ client ~ f ( : fun o -> Jqo . field o ~ k " : contents " |> Jqo . list_exists ~ f : Poly . ( fun op -> Jqo . field op ~ k " : kind " = ` String kind ) ) >>= fun found_or_not -> return Poly . ( found_or_not <> None ) |
let block_has_operation state ~ client ~ level ~ kind = successful_client_cmd state ~ client [ " rpc " ; " get " ; sprintf " / chains / main / blocks /% d / operations " level ] >>= fun res -> try let json = Jqo . of_string ( String . concat ~ sep " :\ n " res # out ) in let found = Jqo . list_exists json ~ f ( : fun o... |
let get_block_header state ~ client block = let path = sprintf " / chains / main / blocks /% s / header " ( match block with ` Head -> " head " | ` Level i -> Int . to_string i ) in rpc state ~ client ` Get ~ path |
let list_known_addresses state ~ client = successful_client_cmd state ~ client [ " list " ; " known " ; " addresses " ] >>= fun res -> let re = Re . ( compile ( seq [ group ( rep1 ( alt [ alnum ; char ' _ ' ] ) ) ; str " : " ; group ( rep1 alnum ) ; alt [ space ; eol ; eos ] ] ) ) in return ( List . filter_map res # ou... |
module Ledger = struct type hwm = { main : int ; test : int ; chain : Tezos_crypto . Chain_id . t option } let set_hwm state ~ client ~ uri ~ level = successful_client_cmd state ~ client [ " set " ; " ledger " ; " high " ; " watermark " ; " for " ; uri ; " to " ; Int . to_string level ] >>= fun _ -> return ( ) let get_... |
module Keyed = struct type t = { client : client ; key_name : string ; secret_key : string } let make client ~ key_name ~ secret_key = { client ; key_name ; secret_key } let initialize state { client ; key_name ; secret_key } = successful_client_cmd state ~ client [ " import " ; " secret " ; " key " ; key_name ; secret... |
type args = | Baker : string -> args | Endorser : string -> args | Accuser : args |
type t = { node : Tezos_node . t ; client : Tezos_client . t ; exec : Tezos_executable . t ; args : args ; name_tag : string option } |
let of_node ? name_tag node args ~ exec ~ client = { node ; exec ; client ; args ; name_tag } |
let baker_of_node ? name_tag nod ~ key = of_node nod ? name_tag ( Baker key ) |
let endorser_of_node ? name_tag nod ~ key = of_node nod ? name_tag ( Endorser key ) |
let accuser_of_node ? name_tag nod = of_node ? name_tag nod Accuser |
let arg_to_string = function | Baker k -> sprintf " baker -% s " k | Endorser k -> sprintf " endorser -% s " k | Accuser -> " accuser " |
let to_script state ( t : t ) = let base_dir = Tezos_client . base_dir ~ state t . client in let call t args = Tezos_executable . call state t . exec ~ path : ( base_dir // sprintf " exec -% s -% d % s " ( arg_to_string t . args ) t . node . Tezos_node . rpc_port ( Option . value_map t . name_tag ~ default " " : ~ f ( ... |
let process state ( t : t ) = Running_processes . Process . genspio ( sprintf " % s - for -% s % s " ( arg_to_string t . args ) t . node . Tezos_node . id ( Option . value_map t . name_tag ~ default " " : ~ f ( : sprintf " -% s " ) ) ) ( to_script state t ) |
module Make_cli = struct let flag name = [ sprintf " --% s " name ] let opt name s = [ sprintf " --% s " name ; s ] let optf name fmt = ksprintf ( opt name ) fmt end |
module Unix_files_sink = struct type t = { matches : string list option ; level_at_least : string } let all_at_least level_at_least = { matches = None ; level_at_least } let all_notices = all_at_least " notice " let all_info = all_at_least " info " end |
type kind = [ ` Node | ` Baker | ` Endorser | ` Accuser | ` Client | ` Admin ] |
type t = { kind : kind ; binary : string option ; unix_files_sink : Unix_files_sink . t option ; environment : ( string * string ) list } |
let make ? binary ? unix_files_sink ( ? environment = [ ] ) ( kind : [ < kind ] ) = { kind ; binary ; unix_files_sink ; environment } |
let kind_string ( kind : [ < kind ] ) = match kind with | ` Accuser -> " accuser - alpha " | ` Baker -> " baker - alpha " | ` Endorser -> " endorser - alpha " | ` Node -> " node " | ` Client -> " client " | ` Admin -> " admin - client " |
let default_binary t = sprintf " tezos -% s " ( kind_string t . kind ) |
let get t = Option . value t . binary ~ default ( : default_binary t ) |
let call state t ~ path args = let open Genspio . EDSL in let unix_files_sink = match t . unix_files_sink with | Some s -> Some s | None -> Environment_configuration . default_events_level state |> Option . map ~ f : Unix_files_sink . all_at_least in seq ( Option . value_map unix_files_sink ~ default [ ] : ~ f ( : func... |
let cli_term ( ? extra_doc = " " ) state kind prefix = let open Cmdliner in let open Term in let docs = Manpage_builder . section state ~ rank : 2 ~ name " : EXECUTABLE PATHS " in pure ( fun binary -> { kind ; binary ; unix_files_sink = None ; environment = [ ] } ) $ Arg . ( value & opt ( some string ) None & info ~ do... |
type custom_network = [ ` Json of Ezjsonm . value ] |
type t = { id : string ; expected_connections : int ; rpc_port : int ; p2p_port : int ; peers : int list ; exec : Tezos_executable . t ; protocol : Tezos_protocol . t ; history_mode : [ ` Archive | ` Full of int | ` Rolling of int ] option ; single_process : bool ; cors_origin : string option ; custom_network : custom_... |
let compare a b = Base . String . compare a . id b . id |
let equal a b = Base . String . equal a . id b . id |
let ef t = EF . ( desc_list ( af " Node :% S " t . id ) [ desc ( af " rpc " ) ( af " :% d " t . rpc_port ) ; desc ( af " p2p " ) ( af " :% d " t . p2p_port ) ; desc_list ( af " peers " ) ( List . map t . peers ~ f ( : af " :% d " ) ) ] ) |
let pp fmt t = Easy_format . Pretty . to_formatter fmt ( ef t ) |
let id t = t . id |
let make ? cors_origin ~ exec ( ? protocol = Tezos_protocol . default ( ) ) ? custom_network ( ? single_process = true ) ? history_mode id ~ expected_connections ~ rpc_port ~ p2p_port peers = { id ; expected_connections ; rpc_port ; p2p_port ; peers ; exec ; protocol ; history_mode ; single_process ; cors_origin ; cust... |
let make_path p ~ config t = Paths . root config // sprintf " node -% s " t . id // p |
let data_dir config t = make_path " data - dir " ~ config t |
let config_file config t = data_dir config t // " config . json " |
let identity_file config t = data_dir config t // " identity . json " |
let log_output config t = make_path " node - output . log " ~ config t |
let exec_path config t = make_path ~ config " exec " t |
module Config_file = struct open Tezos_rpc_http_server let network ( ? genesis_hash = " BLdZYwNF8Rn6zrTWkuRRNyrj6bQWPkfBog2YKhWhn5z3ApmpzBf " ) ( ) = let open Ezjsonm in [ ( " genesis " , dict [ ( " timestamp " , string " 2018 - 06 - 30T16 : 07 : 32Z " ) ; ( " block " , string genesis_hash ) ; ( " protocol " , string "... |
let node_command state t cmd options = Tezos_executable . call state t . exec ~ path ( : exec_path state t ) ( cmd @ opt " config - file " ( config_file state t ) @ opt " data - dir " ( data_dir state t ) @ options ) |
let run_command state t = let peers = List . concat_map t . peers ~ f ( : optf " peer " " 127 . 0 . 0 . 1 :% d " ) in let cors_origin = match t . cors_origin with | Some _ as s -> s | None -> Environment_configuration . default_cors_origin state in node_command state t [ " run " ] ( flag " private - mode " @ flag " no ... |
let start_script state t = let open Genspio . EDSL in let gen_id = node_command state t [ " identity " ; " generate " ; sprintf " % d " ( Tezos_protocol . expected_pow t . protocol ) ] [ ] in let tmp_config = tmp_file ( config_file state t ) in check_sequence ~ verbosity ` : Output_all [ ( " reset - config " , node_com... |
let process state t = Running_processes . Process . genspio t . id ( start_script state t ) |
let protocol t = t . protocol |
let connections node_list = let module Connection = struct type node = t type t = [ ` Duplex of node * node | ` From_to of node * node | ` Missing of node * int ] let compare a b = match ( a , b ) with | ` Duplex ( a , b ) , ` Duplex ( c , d ) when equal a d && equal b c -> 0 | ` Duplex _ , _ -> - 1 | _ , ` Duplex _ ->... |
module History_modes = struct type ' error edit = t list -> ( t list , ' error ) Asynchronous_result . t let cmdliner_term state : _ edit Cmdliner . Term . t = let open Cmdliner in let open Term in let history_mode_converter = Arg . enum [ ( " archive " , ` Archive ) ; ( " full " , ` Full 5 ) ; ( " rolling " , ` Rollin... |
module Key = struct module Of_name = struct type t = { name : string ; pkh : Tezos_crypto . Ed25519 . Public_key_hash . t ; pk : Tezos_crypto . Ed25519 . Public_key . t ; sk : Tezos_crypto . Ed25519 . Secret_key . t } let make name = let seed = Bytes . of_string ( String . concat ~ sep " " : ( List . init 42 ~ f ( : fu... |
module Account = struct type t = | Of_name of string | Key_pair of { name : string ; pubkey : string ; pubkey_hash : string ; private_key : string } let of_name s = Of_name s let of_namef fmt = ksprintf of_name fmt let name = function Of_name n -> n | Key_pair k -> k . name let key_pair name ~ pubkey ~ pubkey_hash ~ pr... |
module Voting_period = struct type t = [ ` Proposal | ` Exploration | ` Cooldown | ` Promotion | ` Adoption ] end |
module Protocol_kind = struct type t = [ ` Athens | ` Babylon | ` Carthage | ` Delphi | ` Edo | ` Florence | ` Granada | ` Hangzhou | ` Ithaca | ` Alpha ] let names = [ ( " Athens " , ` Athens ) ; ( " Babylon " , ` Babylon ) ; ( " Carthage " , ` Carthage ) ; ( " Delphi " , ` Delphi ) ; ( " Edo " , ` Edo ) ; ( " Florenc... |
type t = { id : string ; kind : Protocol_kind . t ; bootstrap_accounts : ( Account . t * Int64 . t ) list ; dictator : Account . t ; expected_pow : int ; name : string ; hash : string ; time_between_blocks : int list ; minimal_block_delay : int ; baking_reward_per_endorsement : int list ; endorsement_reward : int list ... |
let compare a b = String . compare a . id b . id |
let make_bootstrap_accounts ~ balance n = List . init n ~ f ( : fun n -> ( Account . of_namef " bootacc -% d " n , balance ) ) |
let default ( ) = let dictator = Account . of_name " dictator - default " in { id = " default - bootstrap " ; kind = Protocol_kind . default ; bootstrap_accounts = make_bootstrap_accounts ~ balance : 4_000_000_000_000L 4 ; dictator ; expected_pow = 1 ; name = " alpha " ; hash = " ProtoALphaALphaALphaALphaALphaALphaALph... |
let protocol_parameters_json t : Ezjsonm . t = let open Ezjsonm in let make_account ( account , amount ) = strings [ Account . pubkey account ; sprintf " % Ld " amount ] in let extra_post_babylon_stuff subkind = let alpha_specific_parameters = match subkind with | ` Alpha -> [ ( " tx_rollup_enable " , bool false ) ; ( ... |
let voting_period_to_string t ( p : Voting_period . t ) = match p with | ` Promotion -> if Protocol_kind . ( t . kind < ` Florence ) then " promotion_vote " else " promotion " | ` Exploration -> if Protocol_kind . ( t . kind < ` Florence ) then " testing_vote " else " exploration " | ` Proposal -> " proposal " | ` Cool... |
let sandbox { dictator ; _ } = let pk = Account . pubkey dictator in Ezjsonm . to_string ( ` O [ ( " genesis_pubkey " , ` String pk ) ] ) |
let protocol_parameters t = Ezjsonm . to_string ~ minify : false ( protocol_parameters_json t ) |
let expected_pow t = t . expected_pow |
let id t = t . id |
let kind t = t . kind |
let bootstrap_accounts t = List . map ~ f : fst t . bootstrap_accounts |
let dictator_name { dictator ; _ } = Account . name dictator |
let dictator_secret_key { dictator ; _ } = Account . private_key dictator |
let make_path config t = Paths . root config // sprintf " protocol -% s " ( id t ) |
let sandbox_path config t = make_path config t // " sandbox . json " |
let protocol_parameters_path config t = make_path config t // " protocol_parameters . json " |
let ensure_script state t = let open Genspio . EDSL in let file string p = let path = p state t in ( Caml . Filename . basename path , write_stdout ~ path ( : str path ) ( feed ~ string ( : str ( string t ) ) ( exec [ " cat " ] ) ) ) in check_sequence ~ verbosity ( ` : Announce ( sprintf " Ensure - protocol -% s " ( id... |
let ensure state t = Running_processes . run_successful_cmdf state " sh - c % s " ( Genspio . Compile . to_one_liner ( ensure_script state t ) |> Caml . Filename . quote ) >>= fun _ -> return ( ) |
let cli_term state = let open Cmdliner in let open Term in let def = default ( ) in let docs = Manpage_builder . section state ~ rank : 2 ~ name " : PROTOCOL OPTIONS " in pure ( fun bootstrap_accounts ( ` Blocks_per_voting_period blocks_per_voting_period ) ( ` Protocol_hash hash ) ( ` Time_between_blocks time_between_b... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.