text stringlengths 0 601k |
|---|
type t = opcode list * int ; ; |
let empty = ( [ ] , 0 ) ; ; |
let opcode_to_hex oc = let rec data_to_bytearray d = match String . length d with | 0 -> [ ] | n -> ( Char . code @@ String . get d 0 ) :: data_to_bytearray ( String . sub d 1 ( n - 1 ) ) in match oc with | OP_COINBASE ( d ) -> data_to_bytearray d | OP_0 -> [ 0x00 ] | OP_FALSE -> [ 0x00 ] | OP_DATA ( s , data ) -> s ::... |
let opcode_of_hex s = let consume_next s = match String . length s with | 0 -> failwith " Not enough data " | 1 -> ( String . get s 0 |> Char . code , " " ) | n -> let c = String . get s 0 |> Char . code in let s ' = String . sub s 1 @@ n - 1 in ( c , s ' ) in let consume_string s sizea = let sizea = List . fold_left (... |
let join s1 s2 = ( ( fst s1 ) @ ( fst s2 ) , ( snd s1 ) + ( snd s2 ) ) ; ; |
let length scr = snd scr ; ; |
let serialize scr = let rec serialize ' scr acc = match scr with | [ ] -> acc | op :: scr ' -> let r = List . fold_right ( fun x acc ' -> ( String . make 1 ( Char . chr x ) ) ^ acc ' ) ( opcode_to_hex op ) " " in serialize ' scr ' ( acc ^ r ) in let s = serialize ' ( fst scr ) " " in match ( snd scr , String . length s... |
let parse s = let rec chunkize s acc = match String . length s with | 0 -> acc | n when n <= 8192 -> acc @ [ OP_COINBASE ( s ) ] | n -> let chunk = String . sub s 0 8192 in chunkize ( String . sub s 8192 @@ n - 8192 ) ( acc @ [ OP_COINBASE ( chunk ) ] ) in let rec parse ' s acc = match String . length s with | 0 -> acc... |
let parse_coinbase s = ( [ OP_COINBASE ( s ) ] , String . length s ) ; ; |
let of_opcodes ops = ( ops , List . length ops ) ; ; |
type output_format = Rows of { separator : string ; escape : [ ` No | ` OCaml ] } |
let rows separator escape = Rows { separator ; escape } |
let tsv = rows " \ t " ` No |
let csv = rows " , " ` OCaml |
let clic_arg ( ) = let open Clic in arg ~ doc " : Make the output script - friendly . Possible values are ' TSV ' and ' CSV ' . " ~ long " : for - script " ~ placeholder " : FORMAT " ( parameter ( fun _ spec -> match String . lowercase_ascii spec with | " tsv " -> return tsv | " csv " -> return csv | other -> failwith ... |
let fprintf_lwt chan fmt = let open Lwt_syntax in Format . kasprintf ( fun s -> protect ( fun ( ) -> let * ( ) = Lwt_io . write chan s in return_ok_unit ) ) fmt |
let output ( ? channel = Lwt_io . stdout ) how_option ~ for_human ~ for_script = let open Lwt_result_syntax in match how_option with | None -> for_human ( ) | Some ( Rows { separator ; escape } ) -> let open Format in let * ( ) = List . iter_es ( fun row -> fprintf_lwt channel " % a . " @ ( pp_print_list ~ pp_sep ( : f... |
let output_for_human how_option for_human = output how_option ~ for_human ~ for_script ( : fun ( ) -> [ ] ) |
let output_row ? channel how_option ~ for_human ~ for_script = output ? channel how_option ~ for_human ~ for_script ( : fun ( ) -> [ for_script ( ) ] ) |
let is_win32 = Sys . os_type = " Win32 " |
let path_concat str = if Sys . win32 then List . fold_left Filename . concat " " ( Str . split ( Str . regexp " " ) / str ) else str ; ; |
let run cmd = printf " % s \ n " %! cmd ; let exit_code = Sys . command cmd in if exit_code <> 0 then ( raise ( Script_error ( cmd , exit_code ) ) ) |
let sys_command cmd = let cmd = String . concat " " cmd in printf " % s \ n " %! cmd ; let exit_code = Sys . command cmd in if exit_code <> 0 then ( raise ( Script_error ( cmd , exit_code ) ) ) |
let mkdir d = printf " mkdir % s \ n " %! d ; Unix . mkdir d 0o755 |
let rec mkdir_p d = if not ( Sys . file_exists d ) then begin mkdir_p ( Filename . dirname d ) ; mkdir d end ; ; |
let copy_file ic oc = let buff = Bytes . create 0x1000 in let rec copy ( ) = let n = input ic buff 0 0x1000 in if n = 0 then ( ) else ( output oc buff 0 n ; copy ( ) ) in copy ( ) |
let cp ( ? echo = false ) src dst = if echo then ( printf " % s -> % s \ n " %! src dst ) ; let ic = open_in_bin src in let oc = open_out_bin dst in let finally ( ) = close_out oc ; close_in ic in try copy_file ic oc ; finally ( ) with ex -> ( finally ( ) ; raise ex ) |
let remove_file ( ? verbose = false ) filename = if Sys . file_exists filename && not ( Sys . is_directory filename ) then ( if verbose then ( print_endline filename ) ; Sys . remove filename ) |
let rm = if is_win32 then " DEL / F / Q " else " rm - f " |
let rmr = if is_win32 then " RMDIR / Q / S " else " rm - fr " |
let substitute ~ filename ( ? regexp = false ) repl = let perm = ( Unix . stat filename ) . Unix . st_perm in let ichan = open_in_bin filename in let tmp , ochan = Filename . open_temp_file ( Filename . basename filename ) " " in Stdlib . set_binary_mode_out ochan true ; let finally ( ) = close_in_noerr ichan ; close_o... |
let get_command_output command = let ch = Unix . open_process_in command in set_binary_mode_in ch false ; let output = ref [ ] in try while true do output := ( input_line ch ) :: ! output done ; assert false with End_of_file -> begin ignore ( Unix . close_process_in ch ) ; List . rev ! output end | e -> begin ignore ( ... |
let main ? dir ( ? targets [ ] ) = ? default_target ~ options ( ) = try let mktarget f x = fun ( ) -> ( match dir with Some dir -> pushd dir | _ -> ( ) ) ; let finally ( ) = match dir with Some _ -> popd ( ) | _ -> ( ) in ( try f x with ex -> ( finally ( ) ; raise ex ) ) ; finally ( ) ; in let target_func = ref None in... |
let initial_env ( ) = let env = Compmisc . initial_env ( ) in if ! Jclflags . java_extensions && ( not ! Clflags . nopervasives ) nopervasives then try Env . open_pers_signature " JavaPervasives " env with Not_found -> prerr_endline " Warning : JavaPervasives is not opened . " ; env else env |
type res = Ok of Obj . t | Err of string |
let _ = Ok ( Obj . repr 0 ) 0 , Err " " |
type evaluation_outcome = Result of Obj . t | Exception of exn = " caml_natdynlink_run_toplevel " |
let _need_symbol sym = try ignore ( ndl_loadsym sym ) sym ; false with _ -> true |
let dll_run dll entry = match ( try Result ( Obj . magic ( ndl_run_toplevel dll entry ) entry ) entry with exn -> Exception exn ) exn with | Exception _ as r -> r | Result r -> match Obj . magic r with | Ok x -> Result x | Err s -> fatal_error ( " Scriptloop . dll_run " ^ s ) s |
let phrase_seqid = ref 0 |
let phrase_name = ref " SCRIPT " |
let load_lambda ( size , lam ) lam = let slam = Simplif . simplify_lambda lam in let dll = if ! Clflags . keep_asm_file then ! phrase_name ^ Jconfig . ext_obj else Filename . temp_file ( " caml " ^ ! phrase_name ) phrase_name Jconfig . ext_obj in let fn = Filename . chop_extension dll in Javagen . compile_implementatio... |
let toplevel_env = ref Env . empty |
let execute_phrase : Parsetree . toplevel_phrase -> ' a = function | Ptop_def sstr -> let oldenv = ! toplevel_env in incr phrase_seqid ; phrase_name := Printf . sprintf " TOP % i " ! phrase_seqid ; Jcompilenv . reset ? packname : None ! phrase_name ; Typecore . reset_delayed_checks ( ) ; let ( str , _sg , newenv ) newe... |
let got_eof = ref false |
let read_input_default buffer len = let i = ref 0 in try while true do if ! i >= len then raise Exit ; let c = input_char Pervasives . stdin in buffer [ . ! i ] i <- c ; incr i ; if c = ' \ n ' then raise Exit ; done ; ( ! i , false ) false with | End_of_file -> ( ! i , true ) true | Exit -> ( ! i , false ) false |
let refill_lexbuf buffer len = if ! got_eof then ( got_eof := false ; 0 ) 0 else begin let ( len , eof ) eof = read_input_default buffer len in if eof then begin Location . echo_eof ( ) ; if len > 0 then got_eof := true ; len end else len end |
let _ = Sys . interactive := true ; Dynlink . init ( ) ; Compmisc . init_path true ; Clflags . dlcode := true ; ( ) |
let set_paths ( ) = load_path := ! load_path @ [ Filename . concat Config . standard_library " camlp4 ] " ; load_path := " " :: ( List . rev ! Clflags . include_dirs @ ! load_path ) load_path ; ( ) |
let initialize_toplevel_env ( ) = toplevel_env := initial_env ( initial_env ) initial_env |
let eval : string -> ' a = fun s -> let lb = Lexing . from_string s in Location . input_name := " " ; Location . input_lexbuf := Some lb ; let snap = Btype . snapshot ( ) in try let phrases = Parse . use_file lb in List . fold_left ( fun _ phrase -> execute_phrase phrase ) phrase ( Obj . magic ( ) ) phrases with | e ->... |
let directory : string -> unit = fun s -> let d = expand_directory Config . standard_library s in Config . load_path := d :: ! Config . load_path |
let rec load_file ppf name = let filename = try Some ( find_in_path ! Config . load_path name ) name with Not_found -> None in match filename with | None -> fprintf ppf " Cannot find file % s . . " @ name ; false | Some name -> really_load_file ppf name let fn , tmp = if Filename . check_suffix filename " . cmj " || Fi... |
let load : string -> unit = fun s -> ignore ( load_file Format . err_formatter s ) s |
let init ( ) = initialize_toplevel_env ( ) ; let lb = Lexing . from_function refill_lexbuf in Location . input_name := " // script " ; // Location . input_lexbuf := Some lb ; Callback . register " ocamljava javax . script . eval " eval ; Callback . register " ocamljava javax . script . directory " directory ; Callback ... |
let get_operations client = let * operations = RPC . get_operations client in return JSON . ( operations |> geti 3 |> geti 0 |> get " contents " ) |
let read_consumed_gas operation = JSON . ( operation |> get " metadata " |> get " operation_result " |> get " consumed_gas " |> as_int ) |
let get_consumed_gas client = JSON . ( let * operations = get_operations client in return @@ read_consumed_gas ( operations |> geti 0 ) ) |
let get_consumed_gas_for_block client = JSON . ( let * operations = get_operations client in let gas = List . fold_left ( fun gas op -> gas + read_consumed_gas op ) 0 ( operations |> as_list ) in return gas ) |
let current_head = [ " chains " ; " main " ; " blocks " ; " head " ] |
let get_counter client = let * counter = RPC . Contracts . get_counter ~ contract_id : Constant . bootstrap1 . public_key_hash client in return @@ JSON . as_int counter |
let get_size client = let * size = Client . ( rpc GET ( current_head @ [ " context " ; " cache " ; " contracts " ; " size " ] ) client ) in return ( JSON . as_int size ) |
let get_storage ~ contract_id client = let * storage = RPC . Contracts . get_storage ~ contract_id client in return @@ JSON . ( List . assoc " args " ( as_object storage ) |> geti 0 |> fun x -> List . assoc " string " ( as_object x ) |> as_string ) |
let init1 ~ protocol = let * node = Node . init [ Synchronisation_threshold 0 ; Connections 0 ] in let * client = Client . init ~ endpoint ( : Node node ) ( ) in let * ( ) = Client . activate_protocol ~ protocol client in let * _ = Node . wait_for_level node 1 in Log . info " Activated protocol . " ; return ( node , cl... |
let originate_contract prefix contract = let id = ref 0 in let fresh ( ) = incr id ; prefix ^ string_of_int ! id in fun client storage -> let * contract_id = Client . originate_contract ~ alias ( : fresh ( ) ) ~ amount : Tez . zero ~ src " : bootstrap1 " ~ prg : contract ~ init : storage ~ burn_cap : Tez . ( of_int 999... |
let originate_str_id_contract = let filename = " file . :/ tezt / tests / contracts / proto_alpha / large_str_id . tz " in let originate = originate_contract " str " filename in fun client str -> originate client ( Printf . sprintf " Pair " \% s " \ " \% s " " \ str str ) |
let originate_str_id_contracts client n = fold n [ ] @@ fun k contracts -> let s = String . make k ' x ' in let * contract_id = originate_str_id_contract client s in return ( contract_id :: contracts ) |
let originate_very_small_contract = let filename = " file . :/ tezt / tests / contracts / proto_alpha / very_small . tz " in let originate = originate_contract " very_small " filename in fun client -> originate client " Unit " |
let originate_very_small_contracts client n = fold n [ ] @@ fun _ contracts -> let * contract_id = originate_very_small_contract client in return ( contract_id :: contracts ) |
let call_contract contract_id k client = let * ( ) = Client . transfer ~ amount : Tez . ( of_int 100 ) ~ burn_cap : Tez . ( of_int 999999999 ) ~ storage_limit : 100000 ~ giver " : bootstrap1 " ~ receiver : contract_id ~ arg : k client in let * ( ) = Client . bake_for client in let * gas = get_consumed_gas client in Lwt... |
let call_contracts calls client = let * ( ) = Client . multiple_transfers ~ fee_cap : Tez . ( of_int 9999999 ) ~ burn_cap : Tez . ( of_int 9999999 ) ~ giver " : bootstrap1 " ~ json_batch : calls client in let * ( ) = Client . bake_for client in let * gas = get_consumed_gas_for_block client in Lwt . return gas |
let make_calls f contracts = " [ " ^ String . concat " , " ( List . map f contracts ) ^ " ] " |
let str_id_calls = make_calls ( fun contract -> Printf . sprintf { | { " destination " : " % s " , " amount " : " 0 " , " arg " : " Left 4 " , " gas - limit " : " 20000 " } } | contract ) |
let large_types_calls = make_calls ( fun contract -> Printf . sprintf { | { " destination " : " % s " , " amount " : " 0 " , " arg " : " Unit " , " gas - limit " : " 1040000 " } } | contract ) |
let very_small_calls = make_calls ( fun contract -> Printf . sprintf { | { " destination " : " % s " , " amount " : " 0 " , " arg " : " Unit " , " gas - limit " : " 1040000 " } } | contract ) |
let get_cached_contracts client = let * contracts = RPC . Script_cache . get_cached_contracts client in let all = JSON . ( as_list contracts |> List . map @@ fun t -> as_list t |> function [ s ; _ ] -> as_string s | _ -> assert false ) in let all = List . filter ( fun c -> c <> liquidity_baking_address ) all in return ... |
let check ( ? tags = [ ] ) label test ~ protocol ~ executors = Long_test . register ~ __FILE__ ~ title ( : sf " ( % s ) Cache : % s " ( Protocol . name protocol ) label ) ~ tags ( [ " : cache " ] @ tags ) ~ timeout ( : Minutes 2000 ) ~ executors @@ test |
let check_contract_cache_lowers_gas_consumption ~ protocol = check " contract cache lowers gas consumption " ~ protocol @@ fun ( ) -> let * ( _ , client ) = init1 ~ protocol in let * contract_id = originate_str_id_contract client " " in let * gas1 = call_contract contract_id " Left 1 " client in let * gas2 = call_contr... |
let check_full_cache ~ protocol = check " contract cache does not go beyond its size limit " ~ protocol @@ fun ( ) -> let * ( _ , client ) = init1 ~ protocol in let s = String . make 1024 ' x ' in let * counter = get_counter client in let rec aux contracts previous_size nremoved k counter = if k = 0 then Lwt . return_u... |
let check_block_impact_on_cache ~ protocol = check " one cannot violate the cache size limit " ~ protocol ~ tags [ " : memory " ] @@ fun ( ) -> let * ( node , client ) = init1 ~ protocol in let * ( Node . Observe memory_consumption ) = Node . memory_consumption node in let ncontracts = 260 in let * green_contracts = or... |
let check_cache_backtracking_during_chain_reorganization ~ protocol = check " the cache handles chain reorganizations " ~ protocol @@ fun ( ) -> let * nodeA = Node . init [ Synchronisation_threshold 0 ] in let * clientA = Client . init ~ endpoint ( : Node nodeA ) ( ) in let * nodeB = Node . init [ Synchronisation_thres... |
let check_reloading_efficiency ~ protocol body = let * ( nodeA , clientA ) = init1 ~ protocol in let * _ = body clientA in let * ( ) = Client . bake_for clientA in Log . info " Contracts are in the cache " ; let * size = get_size clientA in Log . info " Cache size after baking : % d \ n " size ; let * cached_contracts ... |
let check_cache_reloading_is_not_too_slow ~ protocol = let tags = [ " reload " ; " performance " ] in check " a node reloads a full cache sufficiently fast " ~ protocol ~ tags @@ fun ( ) -> check_reloading_efficiency ~ protocol @@ fun client -> repeat 1000 @@ fun ( ) -> let ncontracts = 5 in let * contracts = originate... |
let check_simulation_takes_cache_into_account ~ protocol = check " operation simulation takes cache into account " ~ protocol @@ fun ( ) -> let * ( _ , client ) = init1 ~ protocol in let * contract_id = originate_very_small_contract client in let * chain_id = RPC . get_chain_id client in let data block counter = Ezjson... |
let register ~ executors ( ) = let protocol = Protocol . Alpha in check_contract_cache_lowers_gas_consumption ~ protocol ~ executors ; check_full_cache ~ protocol ~ executors ; check_block_impact_on_cache ~ protocol ~ executors ; check_cache_backtracking_during_chain_reorganization ~ protocol ~ executors ; check_cache_... |
let compare_address { destination = destination1 ; entrypoint = entrypoint1 } { destination = destination2 ; entrypoint = entrypoint2 } = let lres = Destination . compare destination1 destination2 in if Compare . Int . ( lres = 0 ) then Entrypoint . compare entrypoint1 entrypoint2 else lres |
type compare_comparable_cont = | Compare_comparable : ' a comparable_ty * ' a * ' a * compare_comparable_cont -> compare_comparable_cont | Compare_comparable_return : compare_comparable_cont |
let compare_comparable : type a . a comparable_ty -> a -> a -> int = let rec compare_comparable : type a . a comparable_ty -> compare_comparable_cont -> a -> a -> int = fun kind k x y -> match ( kind , x , y ) with | ( Unit_key , ( ) , ( ) ) -> ( apply [ @ tailcall ] ) 0 k | ( Never_key , _ , _ ) -> . | ( Signature_key... |
type step_constants = Script_typed_ir . step_constants = { source : Contract . t ; payer : Contract . t ; self : Contract . t ; amount : Tez . t ; balance : Tez . t ; chain_id : Chain_id . t ; now : Script_timestamp . t ; level : Script_int . n Script_int . num ; } |
type error += Reject of Script . location * Script . expr * execution_trace option |
type error += Overflow of Script . location * execution_trace option |
type error += Runtime_contract_error of Contract . t |
type error += Bad_contract_parameter of Contract . t |
let ( ) = let open Data_encoding in let trace_encoding = list @@ obj3 ( req " location " Script . location_encoding ) ( req " gas " Gas . encoding ) ( req " stack " ( list Script . expr_encoding ) ) in register_error_kind ` Temporary ~ id " : michelson_v1 . script_rejected " ~ title " : Script failed " ~ description " ... |
let rec kmap_exit : type a b c d e f g h m n o . ( a , b , c , d , e , f , g , h , m , n , o ) kmap_exit_type = fun mk g gas ( body , xs , ys , yk ) ks accu stack -> let ys = Script_map . update yk ( Some accu ) ys in let ks = mk ( KMap_enter_body ( body , xs , ys , ks ) ) in let ( accu , stack ) = stack in ( next [ @ ... |
let step_descr ~ log_now logger ( ctxt , sc ) descr accu stack = let ( gas , outdated_ctxt ) = local_gas_counter_and_outdated_context ctxt in ( match logger with | None -> step ( outdated_ctxt , sc ) gas descr . kinstr KNil accu stack | Some logger -> ( if log_now then let kinfo = kinfo_of_kinstr descr . kinstr in logg... |
let interp logger g ( Lam ( code , _ ) ) arg = step_descr ~ log_now : true logger g code arg ( EmptyCell , EmptyCell ) >|=? fun ( ret , ( EmptyCell , EmptyCell ) , ctxt ) -> ( ret , ctxt ) |
let kstep logger ctxt step_constants kinstr accu stack = let kinstr = match logger with | None -> kinstr | Some logger -> ILog ( kinfo_of_kinstr kinstr , LogEntry , logger , kinstr ) in let ( gas , outdated_ctxt ) = local_gas_counter_and_outdated_context ctxt in step ( outdated_ctxt , step_constants ) gas kinstr KNil a... |
let internal_step ctxt step_constants gas kinstr accu stack = step ( ctxt , step_constants ) gas kinstr KNil accu stack |
let step logger ctxt step_constants descr stack = step_descr ~ log_now : false logger ( ctxt , step_constants ) descr stack |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.