text
stringlengths 0
601k
|
---|
let check_current_level client expected_level = let * level = get_current_level client in Check . ( ( level = expected_level ) level_type ) ~ error_msg " : expected current_period = % R , got % L " ; unit |
let get_proposals client = let * proposals = RPC . Votes . get_proposals client in JSON . as_list proposals |> List . map JSON . as_list |> List . map ( function | [ hash ; _ ] -> JSON . as_string hash | _ -> Test . fail " invalid proposal in JSON response : expected a list with 2 items " ) |> return |
let get_current_proposal client = let * proposal = RPC . Votes . get_current_proposal client in if JSON . is_null proposal then return None else return ( Some JSON . ( proposal |> as_string ) ) |
let check_current_proposal client expected_proposal_hash = let * current_proposal = get_current_proposal client in Check . ( ( current_proposal = Some expected_proposal_hash ) ( option string ) ) ~ error_msg " : expected current_proposal = % R , got % L " ; unit |
let get_protocols client = let * block = RPC . get_block_metadata client in return ( JSON . ( block |-> " protocol " |> as_string ) , JSON . ( block |-> " next_protocol " |> as_string ) ) |
let check_protocols client expected_protocols = let * protocols = get_protocols client in Check . ( ( protocols = expected_protocols ) ( tuple2 string string ) ) ~ error_msg " : expected ( protocol , next_protocol ) = % R , got % L " ; unit |
let check_listings_not_empty client = let * listings = RPC . Votes . get_listings client in match JSON . as_list listings with | [ ] -> Test . fail " Expected GET . . . / votes / listing RPC to return a non - empty list " | _ :: _ -> unit |
type target_protocol = Known of Protocol . t | Injected_test |
let target_protocol_tag = function | Known protocol -> Protocol . tag protocol | Injected_test -> " injected_test " |
let register ~ from_protocol ( ~ to_protocol : target_protocol ) ~ loser_protocols = Test . register ~ __FILE__ ~ title : ( sf " amendment : % s -> % s ( losers : % s ) " ( Protocol . tag from_protocol ) ( target_protocol_tag to_protocol ) ( String . concat " , " ( List . map Protocol . tag loser_protocols ) ) ) ~ tags : ( " amendment " :: ( " from_ " ^ Protocol . tag from_protocol ) :: ( " to_ " ^ target_protocol_tag to_protocol ) :: List . map ( fun p -> " loser_ " ^ Protocol . tag p ) loser_protocols @ [ ( match to_protocol with | Known _ -> " known " | Injected_test -> " injected " ) ; ] ) @@ fun ( ) -> let * parameter_file = Protocol . write_parameter_file ~ base ( : Right ( from_protocol , None ) ) [ ( [ " blocks_per_cycle " ] , Some " 8 " ) ; ( [ " blocks_per_voting_period " ] , Some " 4 " ) ; ] in let * node = Node . init [ Synchronisation_threshold 0 ] in let * client = Client . init ~ endpoint ( : Node node ) ( ) in let * ( ) = Client . activate_protocol ~ protocol : from_protocol ~ parameter_file client in let * ( ) = check_current_level client { level = 1 ; level_position = 0 ; cycle = 0 ; cycle_position = 0 ; expected_commitment = false ; } in let * ( ) = check_current_period client { index = 0 ; kind = " proposal " ; start_position = 0 ; position = 0 ; remaining = 3 ; } in let * ( ) = check_successor_period client { index = 0 ; kind = " proposal " ; start_position = 0 ; position = 1 ; remaining = 2 ; } in Log . info " Current period : proposal . " ; let * ( ) = Client . bake_for client in let * ( ) = Client . bake_for client in let * ( ) = check_current_level client { level = 3 ; level_position = 2 ; cycle = 0 ; cycle_position = 2 ; expected_commitment = false ; } in let * ( ) = check_current_period client { index = 0 ; kind = " proposal " ; start_position = 0 ; position = 2 ; remaining = 1 ; } in let * ( ) = Client . bake_for client in let * ( ) = check_current_period client { index = 0 ; kind = " proposal " ; start_position = 0 ; position = 3 ; remaining = 0 ; } in let * proposals = get_proposals client in Check . ( ( proposals = [ ] ) ( list string ) ) ~ error_msg " : expected proposal list to be empty , got % L " ; let * ( ) = check_listings_not_empty client in let * period = Client . show_voting_period client in Check . ( ( period = " proposal " ) string ) ~ error_msg " : expected tezos - client show voting period to return % R , got % L " ; let * to_protocol_hash = match to_protocol with | Known protocol -> return ( Protocol . hash protocol ) | Injected_test -> let protocol_path = Temp . dir " test_proto " in let * ( ) = Process . run " cp " ( List . map ( fun filename -> test_proto_dir // filename ) test_proto_files @ [ protocol_path ] ) in ( with_open_out ( protocol_path // " TEZOS_PROTOCOL " ) @@ fun ch -> output_string ch test_proto_TEZOS_PROTOCOL ) ; let * protocols_before = Client . Admin . list_protocols client in let * test_proto_hash = Client . Admin . inject_protocol client ~ protocol_path in let * protocols_after = Client . Admin . list_protocols client in if List . mem test_proto_hash protocols_before then Test . fail " Test protocol % s was already known , I can ' t test injection with \ it . " test_proto_hash ; if not ( List . mem test_proto_hash protocols_after ) then Test . fail " Test protocol % s is not known even though it was injected \ successfully . " test_proto_hash ; Log . info " Injected : % s " test_proto_hash ; return test_proto_hash in let * ( ) = Client . submit_proposals ~ proto_hashes ( : to_protocol_hash :: List . map Protocol . hash loser_protocols ) client in let * ( ) = Client . bake_for client in let * proposals = get_proposals client in let expected_proposals = to_protocol_hash :: List . map Protocol . hash loser_protocols in let sort = List . sort String . compare in Check . ( ( sort proposals = sort expected_proposals ) ( list string ) ) ~ error_msg " : expected proposals = % R , got % L " ; let * ( ) = Client . submit_proposals ~ key : Constant . bootstrap2 . alias ~ proto_hash : to_protocol_hash client in let * ( ) = Client . bake_for client in let * proposals = get_proposals client in Check . ( ( sort proposals = sort expected_proposals ) ( list string ) ) ~ error_msg " : expected proposals = % R , got % L " ; let * ( ) = Client . bake_for client in let * ( ) = Client . bake_for client in let * ( ) = check_current_level client { level = 8 ; level_position = 7 ; cycle = 0 ; cycle_position = 7 ; expected_commitment = true ; } in let * ( ) = check_current_period client { index = 1 ; kind = " proposal " ; start_position = 4 ; position = 3 ; remaining = 0 ; } in let * ( ) = check_listings_not_empty client in let * ( ) = check_current_proposal client to_protocol_hash in let * ( ) = Client . bake_for client in let * ( ) = check_current_period client { index = 2 ; kind = " exploration " ; start_position = 8 ; position = 0 ; remaining = 3 ; } in let * ( ) = check_current_proposal client to_protocol_hash in Log . info " Current period : exploration , with current proposal : % s . " ( target_protocol_tag to_protocol ) ; let vote ( account : Account . key ) ballot = Client . submit_ballot ~ key : account . alias ~ proto_hash : to_protocol_hash ballot client in let * ( ) = vote Constant . bootstrap1 Yay in let * ( ) = vote Constant . bootstrap2 Yay in let * ( ) = vote Constant . bootstrap3 Yay in let * ( ) = Client . bake_for client in let * ( ) = check_current_level client { level = 10 ; level_position = 9 ; cycle = 1 ; cycle_position = 1 ; expected_commitment = false ; } in let * ( ) = check_current_period client { index = 2 ; kind = " exploration " ; start_position = 8 ; position = 1 ; remaining = 2 ; } in let * ( ) = Client . bake_for client in let * ( ) = Client . bake_for client in let * ( ) = check_current_period client { index = 2 ; kind = " exploration " ; start_position = 8 ; position = 3 ; remaining = 0 ; } in let * ( ) = Client . bake_for client in let * ( ) = check_current_period client { index = 3 ; kind = " cooldown " ; start_position = 12 ; position = 0 ; remaining = 3 ; } in let * current_proposal = get_current_proposal client in Check . ( ( current_proposal = Some to_protocol_hash ) ( option string ) ) ~ error_msg " : expected current_proposal = % R , got % L " ; Log . info " Current period : cooldown , with current proposal : % s . " ( target_protocol_tag to_protocol ) ; let * ( ) = Client . bake_for client in let * ( ) = check_current_level client { level = 14 ; level_position = 13 ; cycle = 1 ; cycle_position = 5 ; expected_commitment = false ; } in let * ( ) = check_current_period client { index = 3 ; kind = " cooldown " ; start_position = 12 ; position = 1 ; remaining = 2 ; } in let * ( ) = Client . bake_for client in let * ( ) = Client . bake_for client in let * ( ) = check_current_period client { index = 3 ; kind = " cooldown " ; start_position = 12 ; position = 3 ; remaining = 0 ; } in let * ( ) = Client . bake_for client in let * ( ) = check_current_period client { index = 4 ; kind = " promotion " ; start_position = 16 ; position = 0 ; remaining = 3 ; } in let * current_proposal = get_current_proposal client in Check . ( ( current_proposal = Some to_protocol_hash ) ( option string ) ) ~ error_msg " : expected current_proposal = % R , got % L " ; Log . info " Current period : promotion , with current proposal : % s . " ( target_protocol_tag to_protocol ) ; let * ( ) = vote Constant . bootstrap1 Yay in let * ( ) = vote Constant . bootstrap2 Yay in let * ( ) = vote Constant . bootstrap3 Yay in let * ( ) = vote Constant . bootstrap4 Yay in let * ( ) = vote Constant . bootstrap5 Nay in let * ( ) = Client . bake_for client in let * ( ) = check_current_level client { level = 18 ; level_position = 17 ; cycle = 2 ; cycle_position = 1 ; expected_commitment = false ; } in let * ( ) = check_current_period client { index = 4 ; kind = " promotion " ; start_position = 16 ; position = 1 ; remaining = 2 ; } in let * ( ) = Client . bake_for client in let * ( ) = Client . bake_for client in let * ( ) = check_current_period client { index = 4 ; kind = " promotion " ; start_position = 16 ; position = 3 ; remaining = 0 ; } in let * ( ) = Client . bake_for client in let * ( ) = check_current_period client { index = 5 ; kind = " adoption " ; start_position = 20 ; position = 0 ; remaining = 3 ; } in let * current_proposal = get_current_proposal client in Check . ( ( current_proposal = Some to_protocol_hash ) ( option string ) ) ~ error_msg " : expected current_proposal = % R , got % L " ; Log . info " Current period : adoption , with current proposal : % s . " ( target_protocol_tag to_protocol ) ; let * ( ) = Client . bake_for client in let * ( ) = check_current_level client { level = 22 ; level_position = 21 ; cycle = 2 ; cycle_position = 5 ; expected_commitment = false ; } in let * ( ) = check_current_period client { index = 5 ; kind = " adoption " ; start_position = 20 ; position = 1 ; remaining = 2 ; } in let * ( ) = Client . bake_for client in let * ( ) = check_protocols client ( Protocol . hash from_protocol , Protocol . hash from_protocol ) in Log . info " Baking last block of adoption period . . . " ; let * ( ) = Client . bake_for client in match to_protocol with | Injected_test -> Log . info " Creating a second node . . . " ; let * node2 = Node . init [ Synchronisation_threshold 1 ] in let check_event_fetching_protocol = Node . wait_for node2 " fetching_protocol . v0 " @@ fun json -> let hash = JSON . ( json |-> " hash " |> as_string ) in if hash = Protocol . hash from_protocol then None else ( Check . ( ( hash = to_protocol_hash ) string ) ~ error_msg " : expected node2 to fetch protocol % R , got % L " ; Log . info " Node 2 is fetching the injected protocol . " ; Some ( ) ) in let check_event_new_protocol_initialisation = Node . wait_for node2 " new_protocol_initialisation . v0 " @@ fun json -> let hash = JSON . as_string json in if hash = Protocol . hash from_protocol then None else ( Check . ( ( hash = to_protocol_hash ) string ) ~ error_msg " : expected node2 to initialize protocol % R , got % L " ; Log . info " Node 2 initialized the injected protocol . " ; Some ( ) ) in let check_event_update_protocol_table = Node . wait_for node2 " update_protocol_table . v0 " @@ fun json -> let proto_hash = JSON . ( json |-> " proto_hash " |> as_string ) in if proto_hash = Protocol . hash from_protocol then None else let proto_level = JSON . ( json |-> " proto_level " |> as_int ) in Check . ( ( ( proto_hash , proto_level ) = ( to_protocol_hash , 2 ) ) ( tuple2 string int ) ) ~ error_msg : " expected node 2 to update its protocol table with % R , got % L " ; Log . info " Node 2 updated its protocol table with the injected protocol . " ; Some ( ) in let * ( ) = Client . Admin . connect_address ~ peer : node2 client in Log . info " Node 2 initialized and connected to node1 , waiting for it to sync . . . " ; let * level = Node . wait_for_level node2 ( Node . get_level node ) in Log . info " Both nodes are at level % d . " level ; let all_checks = let * ( ) = check_event_fetching_protocol and * ( ) = check_event_new_protocol_initialisation and * ( ) = check_event_update_protocol_table in unit in let timeout = let * ( ) = Lwt_unix . sleep 60 . in Test . fail " timeout while waiting for fetching_protocol , \ new_protocol_initialisation , or update_protocol_table " in let * ( ) = Lwt . pick [ all_checks ; timeout ] in unit | Known _ -> let * ( ) = check_current_period client { index = 5 ; kind = " adoption " ; start_position = 20 ; position = 3 ; remaining = 0 ; } in let * ( ) = check_protocols client ( Protocol . hash from_protocol , to_protocol_hash ) in Log . info " Current period : adoption , with next protocol : % s . " ( target_protocol_tag to_protocol ) ; Log . info " Baking transition block . . . " ; let everybody = List . map ( fun x -> x . Account . public_key_hash ) Constant . bootstrap_keys in let * ( ) = Client . bake_for ~ keys : everybody client in let * ( ) = check_current_period client { index = 6 ; kind = " proposal " ; start_position = 24 ; position = 0 ; remaining = 3 ; } in let * ( ) = check_protocols client ( to_protocol_hash , to_protocol_hash ) in Log . info " Current period : proposal , with protocol : % s . " ( target_protocol_tag to_protocol ) ; let * ( ) = Client . bake_for ~ keys : everybody client in let * ( ) = check_current_period client { index = 6 ; kind = " proposal " ; start_position = 24 ; position = 1 ; remaining = 2 ; } in check_protocols client ( to_protocol_hash , to_protocol_hash ) |
type kind = Proposal | Exploration | Cooldown | Promotion | Adoption |
let string_of_kind = function | Proposal -> " proposal " | Exploration -> " exploration " | Cooldown -> " cooldown " | Promotion -> " promotion " | Adoption -> " adoption " |
let pp_kind ppf kind = Format . fprintf ppf " % s " @@ string_of_kind kind |
let kind_encoding = let open Data_encoding in union ~ tag_size ` : Uint8 [ case ( Tag 0 ) ~ title " : Proposal " ( constant " proposal " ) ( function Proposal -> Some ( ) | _ -> None ) ( fun ( ) -> Proposal ) ; case ( Tag 1 ) ~ title " : exploration " ( constant " exploration " ) ( function Exploration -> Some ( ) | _ -> None ) ( fun ( ) -> Exploration ) ; case ( Tag 2 ) ~ title " : Cooldown " ( constant " cooldown " ) ( function Cooldown -> Some ( ) | _ -> None ) ( fun ( ) -> Cooldown ) ; case ( Tag 3 ) ~ title " : Promotion " ( constant " promotion " ) ( function Promotion -> Some ( ) | _ -> None ) ( fun ( ) -> Promotion ) ; case ( Tag 4 ) ~ title " : Adoption " ( constant " adoption " ) ( function Adoption -> Some ( ) | _ -> None ) ( fun ( ) -> Adoption ) ; ] |
let succ_kind = function | Proposal -> Exploration | Exploration -> Cooldown | Cooldown -> Promotion | Promotion -> Adoption | Adoption -> Proposal |
type voting_period = { index : int32 ; kind : kind ; start_position : int32 } |
type info = { voting_period : t ; position : int32 ; remaining : int32 } |
let root ~ start_position = { index = 0l ; kind = Proposal ; start_position } |
let pp ppf { index ; kind ; start_position } = Format . fprintf ppf " [ @< hv 2 > index : % ld , @ kind :% a , @ start_position : % ld ] " @ index pp_kind kind start_position |
let pp_info ppf { voting_period ; position ; remaining } = Format . fprintf ppf " [ @< hv 2 > voting_period : % a , @ position :% ld , @ remaining : % ld ] " @ pp voting_period position remaining |
let encoding = let open Data_encoding in conv ( fun { index ; kind ; start_position } -> ( index , kind , start_position ) ) ( fun ( index , kind , start_position ) -> { index ; kind ; start_position } ) ( obj3 ( req " index " ~ description : " The voting period ' s index . Starts at 0 with the first block of \ the Alpha family of protocols . " int32 ) ( req ~ description : " One of the several kinds of periods in the voting procedure . " " kind " kind_encoding ) ( req ~ description : " The relative position of the first level of the period with \ respect to the first level of the Alpha family of protocols . " " start_position " int32 ) ) |
let info_encoding = let open Data_encoding in conv ( fun { voting_period ; position ; remaining } -> ( voting_period , position , remaining ) ) ( fun ( voting_period , position , remaining ) -> { voting_period ; position ; remaining } ) ( obj3 ( req ~ description " : The voting period to which the block belongs . " " voting_period " encoding ) ( req ~ description " : The position of the block within the voting period . " " position " int32 ) ( req ~ description : " The number of blocks remaining till the end of the voting period . " " remaining " int32 ) ) type nonrec t = t let compare p p ' = Compare . Int32 . compare p . index p ' . index end ) |
let raw_reset period ~ start_position = let index = Int32 . succ period . index in let kind = Proposal in { index ; kind ; start_position } |
let raw_succ period ~ start_position = let index = Int32 . succ period . index in let kind = succ_kind period . kind in { index ; kind ; start_position } |
let position_since ( level : Level_repr . t ) ( voting_period : t ) = Int32 . ( sub level . level_position voting_period . start_position ) |
let remaining_blocks ( level : Level_repr . t ) ( voting_period : t ) ~ blocks_per_voting_period = let position = position_since level voting_period in Int32 . ( sub blocks_per_voting_period ( succ position ) ) |
let init_first_period ctxt ~ start_position = init ctxt @@ Voting_period_repr . root ~ start_position >>=? fun ctxt -> Storage . Vote . Pred_period_kind . init ctxt Voting_period_repr . Proposal |
let common ctxt = get_current ctxt >>=? fun current_period -> Storage . Vote . Pred_period_kind . update ctxt current_period . kind >|=? fun ctxt -> let start_position = Int32 . succ ( Level_storage . current ctxt ) . level_position in ( ctxt , current_period , start_position ) |
let reset ctxt = common ctxt >>=? fun ( ctxt , current_period , start_position ) -> Voting_period_repr . raw_reset current_period ~ start_position |> set_current ctxt |
let succ ctxt = common ctxt >>=? fun ( ctxt , current_period , start_position ) -> Voting_period_repr . raw_succ current_period ~ start_position |> set_current ctxt |
let get_current_kind ctxt = get_current ctxt >|=? fun { kind ; _ } -> kind |
let get_current_info ctxt = get_current ctxt >|=? fun voting_period -> let blocks_per_voting_period = Constants_storage . blocks_per_voting_period ctxt in let level = Level_storage . current ctxt in let position = Voting_period_repr . position_since level voting_period in let remaining = Voting_period_repr . remaining_blocks level voting_period ~ blocks_per_voting_period in Voting_period_repr . { voting_period ; position ; remaining } |
let get_current_remaining ctxt = get_current ctxt >|=? fun voting_period -> let blocks_per_voting_period = Constants_storage . blocks_per_voting_period ctxt in Voting_period_repr . remaining_blocks ( Level_storage . current ctxt ) voting_period ~ blocks_per_voting_period |
let is_last_block ctxt = get_current_remaining ctxt >|=? fun remaining -> Compare . Int32 . ( remaining = 0l ) |
let get_rpc_current_info ctxt = get_current_info ctxt >>=? fun ( { voting_period ; position ; _ } as voting_period_info ) -> if Compare . Int32 . ( position = Int32 . minus_one ) then let level = Level_storage . current ctxt in let blocks_per_voting_period = Constants_storage . blocks_per_voting_period ctxt in Storage . Vote . Pred_period_kind . get ctxt >|=? fun pred_kind -> let voting_period : Voting_period_repr . t = { index = Int32 . pred voting_period . index ; kind = pred_kind ; start_position = Int32 . ( sub voting_period . start_position blocks_per_voting_period ) ; } in let position = Voting_period_repr . position_since level voting_period in let remaining = Voting_period_repr . remaining_blocks level voting_period ~ blocks_per_voting_period in ( { voting_period ; remaining ; position } : Voting_period_repr . info ) else return voting_period_info |
let get_rpc_succ_info ctxt = Level_storage . from_raw_with_offset ctxt ~ offset : 1l ( Level_storage . current ctxt ) . level >>?= fun level -> get_current ctxt >|=? fun voting_period -> let blocks_per_voting_period = Constants_storage . blocks_per_voting_period ctxt in let position = Voting_period_repr . position_since level voting_period in let remaining = Voting_period_repr . remaining_blocks level voting_period ~ blocks_per_voting_period in Voting_period_repr . { voting_period ; position ; remaining } |
module S = struct let path = RPC_path . ( open_root / " votes " ) let ballots = RPC_service . get_service ~ description " : Sum of ballots casted so far during a voting period . " ~ query : RPC_query . empty ~ output : Vote . ballots_encoding RPC_path . ( path / " ballots " ) let ballot_list = RPC_service . get_service ~ description " : Ballots casted so far during a voting period . " ~ query : RPC_query . empty ~ output : Data_encoding . ( list ( obj2 ( req " pkh " Signature . Public_key_hash . encoding ) ( req " ballot " Vote . ballot_encoding ) ) ) RPC_path . ( path / " ballot_list " ) let current_period = RPC_service . get_service ~ description : " Returns the voting period ( index , kind , starting position ) and \ related information ( position , remaining ) of the interrogated block . " ~ query : RPC_query . empty ~ output : Voting_period . info_encoding RPC_path . ( path / " current_period " ) let successor_period = RPC_service . get_service ~ description : " Returns the voting period ( index , kind , starting position ) and \ related information ( position , remaining ) of the next block . Useful to \ craft operations that will be valid in the next block . " ~ query : RPC_query . empty ~ output : Voting_period . info_encoding RPC_path . ( path / " successor_period " ) let current_quorum = RPC_service . get_service ~ description " : Current expected quorum . " ~ query : RPC_query . empty ~ output : Data_encoding . int32 RPC_path . ( path / " current_quorum " ) let listings = RPC_service . get_service ~ description " : List of delegates with their voting power . " ~ query : RPC_query . empty ~ output : Vote . listings_encoding RPC_path . ( path / " listings " ) let proposals = RPC_service . get_service ~ description " : List of proposals with number of supporters . " ~ query : RPC_query . empty ~ output ( : Protocol_hash . Map . encoding Data_encoding . int64 ) RPC_path . ( path / " proposals " ) let current_proposal = RPC_service . get_service ~ description " : Current proposal under evaluation . " ~ query : RPC_query . empty ~ output ( : Data_encoding . option Protocol_hash . encoding ) RPC_path . ( path / " current_proposal " ) let total_voting_power = RPC_service . get_service ~ description " : Total voting power in the voting listings . " ~ query : RPC_query . empty ~ output : Data_encoding . int64 RPC_path . ( path / " total_voting_power " ) end |
let register ( ) = let open Services_registration in register0 ~ chunked : false S . ballots ( fun ctxt ( ) ( ) -> Vote . get_ballots ctxt ) ; register0 ~ chunked : true S . ballot_list ( fun ctxt ( ) ( ) -> Vote . get_ballot_list ctxt >|= ok ) ; register0 ~ chunked : false S . current_period ( fun ctxt ( ) ( ) -> Voting_period . get_rpc_current_info ctxt ) ; register0 ~ chunked : false S . successor_period ( fun ctxt ( ) ( ) -> Voting_period . get_rpc_succ_info ctxt ) ; register0 ~ chunked : false S . current_quorum ( fun ctxt ( ) ( ) -> Vote . get_current_quorum ctxt ) ; register0 ~ chunked : true S . proposals ( fun ctxt ( ) ( ) -> Vote . get_proposals ctxt ) ; register0 ~ chunked : true S . listings ( fun ctxt ( ) ( ) -> Vote . get_listings ctxt >|= ok ) ; register0 ~ chunked : false S . current_proposal ( fun ctxt ( ) ( ) -> Vote . find_current_proposal ctxt ) ; register0 ~ chunked : false S . total_voting_power ( fun ctxt ( ) ( ) -> Vote . get_total_voting_power_free ctxt ) [ @@ coq_axiom_with_reason " disabled because we would need to re - create the error e in order to have \ different polymorphic variables " ] |
let ballots ctxt block = RPC_context . make_call0 S . ballots ctxt block ( ) ( ) |
let ballot_list ctxt block = RPC_context . make_call0 S . ballot_list ctxt block ( ) ( ) |
let current_period ctxt block = RPC_context . make_call0 S . current_period ctxt block ( ) ( ) |
let successor_period ctxt block = RPC_context . make_call0 S . successor_period ctxt block ( ) ( ) |
let current_quorum ctxt block = RPC_context . make_call0 S . current_quorum ctxt block ( ) ( ) |
let listings ctxt block = RPC_context . make_call0 S . listings ctxt block ( ) ( ) |
let proposals ctxt block = RPC_context . make_call0 S . proposals ctxt block ( ) ( ) |
let current_proposal ctxt block = RPC_context . make_call0 S . current_proposal ctxt block ( ) ( ) |
let total_voting_power ctxt block = RPC_context . make_call0 S . total_voting_power ctxt block ( ) ( ) |
module Block_producer_keys = struct [ %% versioned module Stable = struct [ @@@ no_toplevel_latest_type ] no_toplevel_latest_type module V1 = struct type t = ( Keypair . Stable . V1 . t * Public_key . Compressed . Stable . V1 . t ) t list [ @@ deriving sexp ] sexp let to_latest = Fn . id end end ] end type t = Stable . Latest . t [ @@ deriving sexp ] sexp end |
module Evaluator_status = struct [ %% versioned module Stable = struct [ @@@ no_toplevel_latest_type ] no_toplevel_latest_type module V1 = struct type t = At of Global_slot . Stable . V1 . t | Completed let to_latest = Fn . id end end ] end type t = Stable . Latest . t = At of Global_slot . t | Completed [ @@ deriving sexp ] sexp end |
module Vrf_evaluation_result = struct [ %% versioned module Stable = struct [ @@@ no_toplevel_latest_type ] no_toplevel_latest_type module V1 = struct type t = { slots_won : Consensus . Data . Slot_won . Stable . V1 . t list ; evaluator_status : Evaluator_status . Stable . V1 . t } let to_latest = Fn . id end end ] end type t = Stable . Latest . t = { slots_won : Consensus . Data . Slot_won . t list ; evaluator_status : Evaluator_status . t } end |
module Worker_state = struct type init_arg = { constraint_constants : Genesis_constants . Constraint_constants . t ; consensus_constants : Consensus . Constants . Stable . Latest . t ; conf_dir : string ; logger : Logger . Stable . Latest . t } [ @@ deriving bin_io_unversioned ] bin_io_unversioned type t = { config : init_arg ; mutable last_checked_slot_and_epoch : ( Epoch . t * Slot . t ) t Public_key . Compressed . Table . t ; slots_won : Consensus . Data . Slot_won . t Queue . t ; mutable current_slot : Global_slot . t option ; mutable epoch_data : unit Ivar . t * Consensus . Data . Epoch_data_for_vrf . t option ; mutable block_producer_keys : Block_producer_keys . t } let make_last_checked_slot_and_epoch_table old_table new_keys ~ default = let module Set = Public_key . Compressed . Set in let module Table = Public_key . Compressed . Table in let last_checked_slot_and_epoch = Table . create ( ) in List . iter new_keys ~ f ( : fun ( _ , pk ) pk -> let data = Option . value ( Table . find old_table pk ) pk ~ default in Table . add_exn last_checked_slot_and_epoch ~ key : pk ~ data ) ; last_checked_slot_and_epoch let seen_slot last_checked_slot_and_epoch epoch slot = let module Table = Public_key . Compressed . Table in let unseens = Table . to_alist last_checked_slot_and_epoch |> List . filter_map ~ f ( : fun ( pk , last_checked_epoch_and_slot ) last_checked_epoch_and_slot -> let i = Tuple2 . compare ~ cmp1 : Epoch . compare ~ cmp2 : Slot . compare last_checked_epoch_and_slot ( epoch , slot ) slot in if i > 0 then None else if i = 0 then Some pk else ( Table . set last_checked_slot_and_epoch ~ key : pk ~ data ( : epoch , slot ) slot ; Some pk ) ) in match unseens with | [ ] -> ` All_seen | nel -> ` Unseen ( Public_key . Compressed . Set . of_list nel ) nel let evaluate ( { config ; slots_won ; block_producer_keys ; epoch_data = interrupt_ivar , epoch_data ; _ } as t ) : ( unit , unit ) unit Interruptible . t = match epoch_data with | None -> Interruptible . return ( ) | Some epoch_data -> let open Interruptible . Let_syntax in let % bind ( ) = Interruptible . lift Deferred . unit ( Ivar . read interrupt_ivar ) interrupt_ivar in let module Slot = Mina_numbers . Global_slot in let logger = config . logger in let epoch = epoch_data . epoch in [ % log info ] info " Starting VRF evaluation for epoch : $ epoch " ~ metadata [ : ( " epoch " , Epoch . to_yojson epoch ) epoch ] ; let keypairs = block_producer_keys in let logger = config . logger in let start_global_slot = epoch_data . global_slot in let start_global_slot_since_genesis = epoch_data . global_slot_since_genesis in let constants = config . consensus_constants in let delegatee_table = epoch_data . delegatee_table in let start_consensus_time = Consensus . Data . Consensus_time ( . of_global_slot ~ constants start_global_slot ) start_global_slot in let total_stake = epoch_data . epoch_ledger . total_currency in let evaluate_vrf ~ consensus_time = let slot = Consensus_time . slot consensus_time in let global_slot = Consensus_time . to_global_slot consensus_time in [ % log info ] info " Checking VRF evaluations for epoch : $ epoch , slot : $ slot " ~ metadata : [ ( " epoch " , ` Int ( Epoch . to_int epoch ) epoch ) epoch ; ( " slot " , ` Int ( Slot . to_int slot ) slot ) slot ] ; let rec go = function | [ ] -> Interruptible . return None | ( ( keypair : Keypair . t ) t , public_key_compressed ) public_key_compressed :: keypairs -> ( let global_slot_since_genesis = let slot_diff = match Global_slot . sub global_slot start_global_slot with | None -> failwith " Checking slot - winner for a slot which is older than \ the slot in the latest consensus state . System time \ might be out - of - sync " | Some diff -> diff in Global_slot . add start_global_slot_since_genesis slot_diff in [ % log info ] info " Checking VRF evaluations at epoch : $ epoch , slot : $ slot " ~ metadata : [ ( " epoch " , ` Int ( Epoch . to_int epoch ) epoch ) epoch ; ( " slot " , ` Int ( Slot . to_int slot ) slot ) slot ] ; match % bind Consensus . Data . Vrf . check ~ constraint_constants : config . constraint_constants ~ global_slot ~ seed : epoch_data . epoch_seed ~ get_delegators : ( Public_key . Compressed . Table . find delegatee_table ) delegatee_table ~ producer_private_key : keypair . private_key ~ producer_public_key : public_key_compressed ~ total_stake ~ logger with | None -> go keypairs | Some ( ` Vrf_eval _vrf_string , ` Vrf_output vrf_result , ` Delegator delegator ) -> [ % log info ] info " Won slot % d in epoch % d " ( Slot . to_int slot ) slot ( Epoch . to_int epoch ) epoch ; let slot_won = Consensus . Data . Slot_won . { delegator ; producer = keypair ; global_slot ; global_slot_since_genesis ; vrf_result } in Interruptible . return ( Some slot_won ) slot_won ) in go keypairs in let rec find_winning_slot ( consensus_time : Consensus_time . t ) t = let slot = Consensus_time . slot consensus_time in let global_slot = Consensus_time . to_global_slot consensus_time in t . current_slot <- Some global_slot ; let epoch ' = Consensus_time . epoch consensus_time in if Epoch ( . epoch ' > epoch ) epoch then ( t . current_slot <- None ; Interruptible . return ( ) ) else let start = Time . now ( ) in match % bind evaluate_vrf ~ consensus_time with | None -> [ % log info ] info " Did not win slot $ slot , took $ time ms " ~ metadata : [ ( " time " , ` Float Time ( . Span . to_ms ( diff ( now ( ) ) start ) start ) start ) start ; ( " slot " , Slot . to_yojson slot ) slot ] ; find_winning_slot ( Consensus_time . succ consensus_time ) consensus_time | Some slot_won -> [ % log info ] info " Won a slot $ slot , took $ time ms " ~ metadata : [ ( " time " , ` Float Time ( . Span . to_ms ( diff ( now ( ) ) start ) start ) start ) start ; ( " slot " , Slot . to_yojson slot ) slot ] ; Queue . enqueue slots_won slot_won ; find_winning_slot ( Consensus_time . succ consensus_time ) consensus_time in find_winning_slot start_consensus_time let create config = { config ; last_checked_slot_and_epoch = Public_key . Compressed . Table . create ( ) ; slots_won = Queue . create ~ capacity : ( Global_slot . to_int config . consensus_constants . slots_per_epoch ) slots_per_epoch ( ) ; current_slot = None ; epoch_data = ( Ivar . create ( ) , None ) None ; block_producer_keys = [ ] } end |
module Functions = struct type ( ' i , ' o ) ' o t = ' i Bin_prot . Type_class . t * ' o Bin_prot . Type_class . t * ( Worker_state . t -> ' i -> ' o Deferred . t ) t let create input output f : ( ' i , ' o ) ' o t = ( input , output , f ) f let set_new_epoch_state = create Consensus . Data . Epoch_data_for_vrf . Stable . Latest . bin_t Unit . bin_t ( fun w e -> let logger = w . config . logger in let update ( ) = [ % log info ] info " Updating epoch data for the VRF evaluation for epoch $ epoch " ~ metadata [ : ( " epoch " , Epoch . to_yojson e . epoch ) epoch ] ; let interrupt_ivar , _ = w . epoch_data in Ivar . fill_if_empty interrupt_ivar ( ) ; Queue . clear w . slots_won ; w . current_slot <- None ; w . epoch_data <- ( Ivar . create ( ) , Some e ) e ; Interruptible . don ' t_wait_for ( Worker_state . evaluate w ) w ; Deferred . unit in match w . epoch_data with | _ , None -> update ( ) | _ , Some current -> if Epoch ( . succ e . epoch > current . epoch ) epoch then update ( ) else ( [ % log info ] info " Received epoch data for current epoch $ epoch . Skipping " ~ metadata [ : ( " epoch " , Epoch . to_yojson e . epoch ) epoch ] ; Deferred . unit ) ) let slots_won_so_far = create Unit . bin_t Vrf_evaluation_result . Stable . Latest . bin_t ( fun w ( ) -> let slots_won = Queue . to_list w . slots_won in [ % log ' info w . config . logger ] logger " ! Slots won evaluator : { % sexp : Consensus . Data . Slot_won . t list } list " slots_won ; Queue . clear w . slots_won ; let evaluator_status = match w . current_slot with | Some slot -> Evaluator_status . At slot | None -> Completed in return Vrf_evaluation_result { . slots_won ; evaluator_status } ) let update_block_producer_keys = create Block_producer_keys . Stable . Latest . bin_t Unit . bin_t ( fun w e -> let logger = w . config . logger in [ % log info ] info " Updating block producer keys " ; w . block_producer_keys <- e ; Deferred . unit ) end |
module Worker = struct module T = struct type ' worker functions = { set_new_epoch_state : ( ' worker , Consensus . Data . Epoch_data_for_vrf . t , unit ) Rpc_parallel . Function . t ; slots_won_so_far : ( ' worker , unit , Vrf_evaluation_result . t ) t Rpc_parallel . Function . t ; update_block_producer_keys : ( ' worker , Block_producer_keys . t , unit ) unit Rpc_parallel . Function . t } module Worker_state = Worker_state module Connection_state = struct type init_arg = unit [ @@ deriving bin_io_unversioned ] bin_io_unversioned type t = unit end module Functions ( C : Rpc_parallel . Creator with type worker_state := Worker_state . t and type connection_state := Connection_state . t ) t = struct let functions = let f ( i , o , f ) f = C . create_rpc ~ f ( : fun ~ worker_state ~ conn_state : _ i -> f worker_state i ) i ~ bin_input : i ~ bin_output : o ( ) in let open Functions in { set_new_epoch_state = f set_new_epoch_state ; slots_won_so_far = f slots_won_so_far ; update_block_producer_keys = f update_block_producer_keys } let init_worker_state ( init_arg : Worker_state . init_arg ) init_arg = let logger = init_arg . logger in let max_size = 200 * 1024 * 1024 in let num_rotate = 1 in Logger . Consumer_registry . register ~ id " : default " ~ processor ( : Logger . Processor . raw ( ) ) ~ transport : ( Logger_file_system . dumb_logrotate ~ directory : init_arg . conf_dir ~ log_filename " : mina - vrf - evaluator . log " ~ max_size ~ num_rotate ) ; [ % log info ] info " Vrf_evaluator started " ; return ( Worker_state . create init_arg ) init_arg let init_connection_state ~ connection : _ ~ worker_state : _ = return end end include Rpc_parallel . Make ( T ) T end |
type t = { connection : Worker . Connection . t ; process : Process . t } |
let update_block_producer_keys { connection ; process = _ } ~ keypairs = Worker . Connection . run connection ~ f : Worker . functions . update_block_producer_keys ~ arg ( : Keypair . And_compressed_pk . Set . to_list keypairs ) keypairs |
let create ~ constraint_constants ~ pids ~ consensus_constants ~ conf_dir ~ logger ~ keypairs = let on_failure err = [ % log error ] error " VRF evaluator process failed with error $ err " ~ metadata [ : ( " err " , Error_json . error_to_yojson err ) err ] ; Error . raise err in [ % log info ] info " Starting a new vrf - evaluator process " ; let % bind connection , process = Worker . spawn_in_foreground_exn ~ connection_timeout ( : Time . Span . of_min 1 ) . ~ on_failure ~ shutdown_on : Connection_closed ~ connection_state_init_arg ( ) : { constraint_constants ; consensus_constants ; conf_dir ; logger } in [ % log info ] info " Daemon started process of kind $ process_kind with pid $ vrf_evaluator_pid " ~ metadata : [ ( " vrf_evaluator_pid " , ` Int ( Process . pid process |> Pid . to_int ) to_int ) to_int ; ( " process_kind " , ` String Child_processes . Termination ( . show_process_kind Vrf_evaluator ) Vrf_evaluator ) ] ; Child_processes . Termination . register_process pids process Child_processes . Termination . Vrf_evaluator ; don ' t_wait_for @@ Pipe . iter ( Process . stdout process |> Reader . pipe ) pipe ~ f ( : fun stdout -> return @@ [ % log debug ] debug " Vrf_evaluator stdout : $ stdout " ~ metadata [ : ( " stdout " , ` String stdout ) stdout ] ) ; don ' t_wait_for @@ Pipe . iter ( Process . stderr process |> Reader . pipe ) pipe ~ f ( : fun stderr -> return @@ [ % log error ] error " Vrf_evaluator stderr : $ stderr " ~ metadata [ : ( " stderr " , ` String stderr ) stderr ] ) ; let t = { connection ; process } in let % map _ = update_block_producer_keys ~ keypairs t in t |
let set_new_epoch_state { connection ; process = _ } ~ epoch_data_for_vrf = Worker . Connection . run connection ~ f : Worker . functions . set_new_epoch_state ~ arg : epoch_data_for_vrf |
let slots_won_so_far { connection ; process = _ } = Worker . Connection . run connection ~ f : Worker . functions . slots_won_so_far ~ arg ( ) : |
module Disposable = struct include Class . Make ( ) include [ % js : val from : ( t list [ @ js . variadic ] ) -> t [ @@ js . global " vscode . Disposable . from " ] val make : dispose ( : unit -> unit ) -> t [ @@ js . new " vscode . Disposable " ] val dispose : t -> unit [ @@ js . call ] ] end |
module Command = struct include Interface . Make ( ) include [ % js : val title : t -> string [ @@ js . get ] val command : t -> string [ @@ js . get ] val tooltip : t -> string or_undefined [ @@ js . get ] val arguments : t -> Js . Any . t maybe_list [ @@ js . get ] val create : title : string -> command : string -> ? tooltip : string -> ? arguments : Js . Any . t list -> unit -> t [ @@ js . builder ] ] end |
module Position = struct include Class . Make ( ) include [ % js : val line : t -> int [ @@ js . get ] val character : t -> int [ @@ js . get ] val make : line : int -> character : int -> t [ @@ js . new " vscode . Position " ] val isBefore : t -> other : t -> bool [ @@ js . call ] val isBeforeOrEqual : t -> other : t -> bool [ @@ js . call ] val isAfter : t -> other : t -> bool [ @@ js . call ] val isAfterOrEqual : t -> other : t -> bool [ @@ js . call ] val isEqual : t -> other : t -> bool [ @@ js . call ] val compareTo : t -> other : t -> int [ @@ js . call ] val translate : t -> ? lineDelta : int -> ? characterDelta : int -> unit -> t [ @@ js . call ] val with_ : t -> ? line : int -> ? character : int -> unit -> t [ @@ js . call ] ] end |
module Range = struct include Class . Make ( ) include [ % js : val start : t -> Position . t [ @@ js . get ] val end_ : t -> Position . t [ @@ js . get ] val makePositions : start : Position . t -> end_ : Position . t -> t [ @@ js . new " vscode . Range " ] val makeCoordinates : startLine : int -> startCharacter : int -> endLine : int -> endCharacter : int -> t [ @@ js . new " vscode . Range " ] val isEmpty : t -> bool [ @@ js . get ] val isSingleLine : t -> bool [ @@ js . get ] val contains : t -> positionOrRange ( [ : ` Position of Position . t | ` Range of t ] [ @ js . union ] ) -> bool [ @@ js . call ] val isEqual : t -> other : t -> bool [ @@ js . call ] val intersection : t -> range : t -> t or_undefined [ @@ js . call ] val union : t -> other : t -> t [ @@ js . call ] val with_ : t -> ? start : Position . t -> ? end_ : Position . t -> unit -> t [ @@ js . call ] ] end |
module TextLine = struct include Interface . Make ( ) include [ % js : val lineNumber : t -> int [ @@ js . get ] val text : t -> string [ @@ js . get ] val range : t -> Range . t [ @@ js . get ] val rangeIncludingLineBreak : t -> Range . t [ @@ js . get ] val firstNonWhitespaceCharacterIndex : t -> int [ @@ js . get ] val isEmptyOrWhitespace : t -> bool [ @@ js . get ] val create : lineNumber : int -> text : string -> range : Range . t -> rangeIncludingLineBreak : Range . t -> firstNonWhitespaceCharacterIndex : int -> isEmptyOrWhitespace : bool -> t [ @@ js . builder ] ] end |
module EndOfLine = struct type t = | CRLF [ @ js 2 ] | LF [ @ js 1 ] [ @@ js . enum ] [ @@ js ] end |
module TextEdit = struct include Class . Make ( ) include [ % js : val replace : range : Range . t -> newText : string -> t [ @@ js . global " vscode . TextEdit . replace " ] val insert : position : Position . t -> newText : string -> t [ @@ js . global " vscode . TextEdit . insert " ] val delete : Range . t -> t [ @@ js . global " vscode . TextEdit . delete " ] val setEndOfLine : EndOfLine . t -> t [ @@ js . global " vscode . TextEdit . setEndOfLine " ] val range : t -> Range . t [ @@ js . get ] val newText : t -> string [ @@ js . get ] val newEol : t -> EndOfLine . t or_undefined [ @@ js . get ] val make : range : Range . t -> newText : string -> t [ @@ js . new " vscode . TextEdit " ] ] end |
module Uri = struct include Class . Make ( ) module Scheme = struct type t = [ ` File | ` Untitled ] let to_string = function | ` File -> " file " | ` Untitled -> " untitled " end include [ % js : val parse : string -> ? strict : bool -> unit -> t [ @@ js . global " vscode . Uri . parse " ] val file : string -> t [ @@ js . global " vscode . Uri . file " ] val joinPath : t -> pathSegments ( : string list [ @ js . variadic ] ) -> t [ @@ js . global " vscode . Uri . joinPath " ] val scheme : t -> string [ @@ js . get ] val authority : t -> string [ @@ js . get ] val path : t -> string [ @@ js . get ] val query : t -> string [ @@ js . get ] val fragment : t -> string [ @@ js . get ] val fsPath : t -> string [ @@ js . get ] val with_ : t -> Ojs . t -> t [ @@ js . call ] val toString : t -> ? skipEncoding : bool -> unit -> string [ @@ js . call ] val toJson : t -> Jsonoo . t [ @@ js . call ] ] let with_ this ? scheme ? authority ? path ? query ? fragment ( ) = let change = Ojs . obj [ ] || in iter_set change " scheme " [ % js . of : string ] ( Option . map Scheme . to_string scheme ) ; iter_set change " authority " [ % js . of : string ] authority ; iter_set change " path " [ % js . of : string ] path ; iter_set change " query " [ % js . of : string ] query ; iter_set change " fragment " [ % js . of : string ] fragment ; with_ this change let equal a b = String . equal ( toString a ( ) ) ( toString b ( ) ) end |
module TextDocument = struct include Interface . Make ( ) include [ % js : val uri : t -> Uri . t [ @@ js . get ] val fileName : t -> string [ @@ js . get ] val isUntitled : t -> bool [ @@ js . get ] val languageId : t -> string [ @@ js . get ] val version : t -> int [ @@ js . get ] val isDirty : t -> bool [ @@ js . get ] val isClosed : t -> bool [ @@ js . get ] val save : t -> bool Promise . t [ @@ js . call ] val eol : t -> EndOfLine . t [ @@ js . get ] val lineCount : t -> int [ @@ js . get ] val lineAt : t -> line : int -> TextLine . t [ @@ js . call ] val lineAtPosition : t -> position : Position . t -> TextLine . t [ @@ js . call " lineAt " ] val offsetAt : t -> position : Position . t -> int [ @@ js . call ] val positionAt : t -> offset : int -> Position . t [ @@ js . call ] val getText : t -> ? range : Range . t -> unit -> string [ @@ js . call ] val getWordRangeAtPosition : t -> position : Position . t -> ? regex : Regexp . t -> unit -> Range . t or_undefined [ @@ js . call ] val validateRange : t -> range : Range . t -> Range . t [ @@ js . call ] val validatePosition : t -> position : Position . t -> Position . t [ @@ js . call ] ] end |
module WorkspaceFolder = struct include Interface . Make ( ) include [ % js : val uri : t -> Uri . t [ @@ js . get ] val name : t -> string [ @@ js . get ] val index : t -> int [ @@ js . get ] val create : uri : Uri . t -> name : string -> index : int -> t [ @@ js . builder ] ] end |
module ViewColumn = struct type t = | Active [ @ js - 1 ] | Beside [ @ js - 2 ] | One [ @ js 1 ] | Two [ @ js 2 ] | Three [ @ js 3 ] | Four [ @ js 4 ] | Five [ @ js 5 ] | Six [ @ js 6 ] | Seven [ @ js 7 ] | Eight [ @ js 8 ] | Nine [ @ js 9 ] [ @@ js . enum ] [ @@ js ] end |
module Selection = struct include Class . Extend ( Range ) ( ) include Range include [ % js : val anchor : t -> Position . t [ @@ js . get ] val active : t -> Position . t [ @@ js . get ] val makePositions : anchor : Position . t -> active : Position . t -> t [ @@ js . new " vscode . Selection " ] val makeCoordinates : anchorLine : int -> anchorCharacter : int -> activeLine : int -> activeCharacter : int -> t [ @@ js . new " vscode . Selection " ] val isReversed : t -> bool [ @@ js . get ] ] end |
module TextEditorEdit = struct include Interface . Make ( ) type replaceLocation = ( [ ` Position of Position . t | ` Range of Range . t | ` Selection of Selection . t ] [ @ js . union ] ) [ @@ js ] let replaceLocation_of_js js_val = if Ojs . has_property js_val " anchor " then ` Position ( [ % js . to : Position . t ] js_val ) else if Ojs . has_property js_val " start " then ` Range ( [ % js . to : Range . t ] js_val ) else ` Selection ( [ % js . to : Selection . t ] js_val ) type deleteLocation = ( [ ` Range of Range . t | ` Selection of Selection . t ] [ @ js . union ] ) [ @@ js ] let deleteLocation_of_js js_val = if Ojs . has_property js_val " anchor " then ` Selection ( [ % js . to : Selection . t ] js_val ) else ` Range ( [ % js . to : Range . t ] js_val ) include [ % js : val replace : t -> location : replaceLocation -> value : string -> unit [ @@ js . call ] val insert : t -> location : Position . t -> value : string -> unit [ @@ js . call ] val delete : t -> location : deleteLocation -> unit [ @@ js . call ] val setEndOfLine : t -> endOfLine : EndOfLine . t -> t [ @@ js . call ] val create : replace ( : location : replaceLocation -> value : string -> unit ) -> insert ( : location : Position . t -> value : string -> unit ) -> delete ( : location : deleteLocation -> unit ) -> setEndOfLine ( : endOfLine : EndOfLine . t -> t ) -> t [ @@ js . builder ] ] end |
module TextEditorCursorStyle = struct type t = | Line [ @ js 1 ] | Block [ @ js 2 ] | Underline [ @ js 3 ] | LineThin [ @ js 4 ] | BlockOutline [ @ js 5 ] | UnderlineThin [ @ js 6 ] [ @@ js . enum ] [ @@ js ] end |
module TextEditorLineNumbersStyle = struct type t = | Off [ @ js 0 ] | On [ @ js 1 ] | Relative [ @ js 2 ] [ @@ js . enum ] [ @@ js ] end |
module TextEditorRevealType = struct type t = | Default [ @ js 0 ] | InCenter [ @ js 1 ] | InCenterIfOutsideViewport [ @ js 2 ] | AtTop [ @ js 3 ] [ @@ js . enum ] [ @@ js ] end |
module TextEditorOptions = struct include Interface . Make ( ) type tabSize = ( [ ` Int of int | ` String of string ] [ @ js . union ] ) [ @@ js ] let tabSize_of_js js_val = match Ojs . type_of js_val with | " number " -> ` Int ( [ % js . to : int ] js_val ) | " string " -> ` String ( [ % js . to : string ] js_val ) | _ -> assert false type insertSpaces = ( [ ` Bool of bool | ` String of string ] [ @ js . union ] ) [ @@ js ] let insertSpaces_of_js js_val = match Ojs . type_of js_val with | " boolean " -> ` Bool ( [ % js . to : bool ] js_val ) | " string " -> ` String ( [ % js . to : string ] js_val ) | _ -> assert false include [ % js : val tabSize : t -> tabSize or_undefined [ @@ js . get ] val insertSpaces : t -> insertSpaces or_undefined [ @@ js . get ] val cursorStyle : t -> TextEditorCursorStyle . t or_undefined [ @@ js . get ] val lineNumbers : t -> TextEditorLineNumbersStyle . t or_undefined [ @@ js . get ] val create : ? tabSize : tabSize -> ? insertSpaces : insertSpaces -> ? cursorStyle : TextEditorCursorStyle . t -> ? lineNumbers : TextEditorLineNumbersStyle . t -> unit -> t [ @@ js . builder ] ] end |
module TextEditorDecorationType = struct include Interface . Make ( ) include [ % js : val key : t -> string [ @@ js . get ] val dispose : t -> unit [ @@ js . call ] val create : key : string -> dispose ( : unit -> unit ) -> t [ @@ js . builder ] ] let disposable this = Disposable . make ~ dispose ( : fun ( ) -> dispose this ) end |
module MarkdownString = struct include Class . Make ( ) include [ % js : val value : t -> string [ @@ js . get ] val isTrusted : t -> bool or_undefined [ @@ js . get ] val supportThemeIcons : t -> bool or_undefined [ @@ js . get ] val make : ? value : string -> ? supportThemeIcons : bool -> unit -> t [ @@ js . new " vscode . MarkdownString " ] val appendText : t -> value : string -> t [ @@ js . call ] val appendMarkdown : t -> value : string -> t [ @@ js . call ] val appendCodeblock : t -> value : string -> ? language : string -> unit -> t [ @@ js . call ] ] end |
module ThemeColor = struct include Class . Make ( ) include [ % js : val make : id : string -> t [ @@ js . new " vscode . ThemeColor " ] ] end |
module ThemableDecorationAttachmentRenderOptions = struct include Interface . Make ( ) type contentIconPath = ( [ ` String of string | ` Uri of Uri . t ] [ @ js . union ] ) [ @@ js ] let contentIconPath_of_js js_val = match Ojs . type_of js_val with | " string " -> ` String ( [ % js . to : string ] js_val ) | _ -> ` Uri ( [ % js . to : Uri . t ] js_val ) type color = ( [ ` String of string | ` ThemeColor of ThemeColor . t ] [ @ js . union ] ) [ @@ js ] let color_of_js js_val = match Ojs . type_of js_val with | " string " -> ` String ( [ % js . to : string ] js_val ) | _ -> ` ThemeColor ( [ % js . to : ThemeColor . t ] js_val ) include [ % js : val contentText : t -> string or_undefined [ @@ js . get ] val contentIconPath : t -> contentIconPath or_undefined [ @@ js . get ] val border : t -> string or_undefined [ @@ js . get ] val borderColor : t -> color or_undefined [ @@ js . get ] val fontStyle : t -> string or_undefined [ @@ js . get ] val fontWeight : t -> string or_undefined [ @@ js . get ] val textDecoration : t -> string or_undefined [ @@ js . get ] val color : t -> color or_undefined [ @@ js . get ] val backgroundColor : t -> color or_undefined [ @@ js . get ] val margin : t -> string or_undefined [ @@ js . get ] val width : t -> string or_undefined [ @@ js . get ] val height : t -> string or_undefined [ @@ js . get ] val create : ? contentText : string -> ? contentIconPath : contentIconPath -> ? border : string -> ? borderColor : color -> ? fontStyle : string -> ? fontWeight : string -> ? textDecoration : string -> ? color : color -> ? backgroundColor : color -> ? margin : string -> ? width : string -> ? height : string -> unit -> t [ @@ js . builder ] ] end |
module ThemableDecorationInstanceRenderOptions = struct include Interface . Make ( ) include [ % js : val before : t -> ThemableDecorationAttachmentRenderOptions . t or_undefined [ @@ js . get ] val after : t -> ThemableDecorationAttachmentRenderOptions . t or_undefined [ @@ js . get ] val create : ? before : ThemableDecorationAttachmentRenderOptions . t -> ? after : ThemableDecorationAttachmentRenderOptions . t -> unit -> t [ @@ js . builder ] ] end |
module DecorationInstanceRenderOptions = struct include Interface . Make ( ) include [ % js : val light : t -> ThemableDecorationInstanceRenderOptions . t or_undefined [ @@ js . get ] val dark : t -> ThemableDecorationInstanceRenderOptions . t or_undefined [ @@ js . get ] val create : ? light : ThemableDecorationInstanceRenderOptions . t -> ? dark : ThemableDecorationInstanceRenderOptions . t -> unit -> t [ @@ js . builder ] ] end |
module DecorationOptions = struct include Interface . Make ( ) type hoverMessage = ( [ ` MarkdownString of MarkdownString . t | ` MarkdownStrings of MarkdownString . t list ] [ @ js . union ] ) [ @@ js ] let hoverMessage_of_js js_val = if Ojs . has_property js_val " value " then ` MarkdownString ( [ % js . to : MarkdownString . t ] js_val ) else ` MarkdownStrings ( [ % js . to : MarkdownString . t list ] js_val ) include [ % js : val range : t -> Range . t [ @@ js . get ] val hoverMessage : t -> hoverMessage or_undefined [ @@ js . get ] val renderOptions : t -> DecorationInstanceRenderOptions . t or_undefined [ @@ js . get ] val create : range : Range . t -> ? hoverMessage : hoverMessage -> ? renderOptions : DecorationInstanceRenderOptions . t or_undefined -> unit -> t [ @@ js . builder ] ] end |
module SnippetString = struct include Class . Make ( ) include [ % js : val value : t -> string [ @@ js . get ] val make : ? value : string -> unit -> t [ @@ js . new " vscode . SnippetString " ] val appendText : t -> string : string -> t [ @@ js . call ] val appendTabStop : t -> number : int -> t [ @@ js . call ] val appendPlaceHolder : t -> value ( [ : ` String of string | ` Function of t -> unit ] [ @ js . union ] ) -> ? number : int -> unit -> t [ @@ js . call ] val appendChoice : t -> values : string list -> ? number : int -> unit -> t [ @@ js . call ] val appendVariable : t -> name : string -> defaultValue : ( [ ` String of string | ` Function of t -> unit ] [ @ js . union ] ) -> t [ @@ js . call ] ] end |
module TextEditor = struct include Interface . Make ( ) type insertSnippetLocation = ( [ ` Position of Position . t | ` Range of Range . t | ` Positions of Position . t list | ` Ranges of Range . t list ] [ @ js . union ] ) [ @@ js ] include [ % js : val document : t -> TextDocument . t [ @@ js . get ] val selection : t -> Selection . t [ @@ js . get ] val set_selection : t -> Selection . t -> unit [ @@ js . set " selection " ] val selections : t -> Selection . t list [ @@ js . get ] val visibleRanges : t -> Range . t list [ @@ js . get ] val options : t -> TextEditorOptions . t [ @@ js . get ] val viewColumn : t -> ViewColumn . t or_undefined [ @@ js . get ] val edit : t -> callback ( : editBuilder : TextEditorEdit . t -> unit ) -> Ojs . t -> unit -> bool Promise . t [ @@ js . call ] val insertSnippet : t -> snippet : SnippetString . t -> ? location : insertSnippetLocation -> Ojs . t -> bool Promise . t [ @@ js . call ] val setDecorations : t -> decorationType : TextEditorDecorationType . t -> rangesOrOptions : ( [ ` Ranges of Range . t list | ` Options of DecorationOptions . t list ] [ @ js . union ] ) -> unit [ @@ js . call ] val revealRange : t -> range : Range . t -> ? revealType : TextEditorRevealType . t -> unit -> unit [ @@ js . call ] ] let edit this ~ callback ? undoStopBefore ? undoStopAfter ( ) = let options = Ojs . obj [ ] || in iter_set options " undoStopBefore " [ % js . of : bool ] undoStopBefore ; iter_set options " undoStopAfter " [ % js . of : bool ] undoStopAfter ; edit this ~ callback options ( ) let insertSnippet this ~ snippet ? location ? undoStopBefore ? undoStopAfter ( ) = let options = Ojs . obj [ ] || in iter_set options " undoStopBefore " [ % js . of : bool ] undoStopBefore ; iter_set options " undoStopAfter " [ % js . of : bool ] undoStopAfter ; insertSnippet this ~ snippet ? location options end |
module ConfigurationTarget = struct type t = | Global [ @ js 1 ] | Workspace [ @ js 2 ] | WorkspaceFolder [ @ js 3 ] [ @@ js . enum ] [ @@ js ] end |
module WorkspaceConfiguration = struct include Interface . Make ( ) type ' a inspectResult = { key : string ; defaultValue : ' a or_undefined ; globalValue : ' a or_undefined ; workspaceValue : ' a or_undefined ; workspaceFolderValue : ' a or_undefined ; defaultLanguageValue : ' a or_undefined ; globalLanguageValue : ' a or_undefined ; workspaceLanguageValue : ' a or_undefined ; workspaceFolderLanguageValue : ' a or_undefined ; languageIds : string list or_undefined } let inspectResult_of_js ( type t ) t_of_js js_val : t inspectResult = let field = Ojs . get_prop_ascii js_val in { key = [ % js . to : string ] ( field " key " ) ; defaultValue = [ % js . to : t or_undefined ] ( field " defaultValue " ) ; globalValue = [ % js . to : t or_undefined ] ( field " globalValue " ) ; workspaceValue = [ % js . to : t or_undefined ] ( field " workspaceValue " ) ; workspaceFolderValue = [ % js . to : t or_undefined ] ( field " workspaceFolderValue " ) ; defaultLanguageValue = [ % js . to : t or_undefined ] ( field " defaultLanguageValue " ) ; globalLanguageValue = [ % js . to : t or_undefined ] ( field " globalLanguageValue " ) ; workspaceLanguageValue = [ % js . to : t or_undefined ] ( field " workspaceLanguageValue " ) ; workspaceFolderLanguageValue = [ % js . to : t or_undefined ] ( field " workspaceFolderLanguageValue " ) ; languageIds = [ % js . to : string list or_undefined ] ( field " languageIds " ) } include [ % js : val get : t -> section : string -> Js . Any . t or_undefined [ @@ js . call ] val get_default : t -> section : string -> defaultValue : Ojs . t -> Ojs . t [ @@ js . call ] val has : t -> section : string -> bool [ @@ js . call ] val inspect : t -> section : string -> Ojs . t [ @@ js . call ] val update : t -> section : string -> value : Js . Any . t -> ? configurationTarget : ( [ ` ConfigurationTarget of ConfigurationTarget . t | ` Bool of bool ] [ @ js . union ] ) -> ? overrideInLanguage : bool -> unit -> Promise . void [ @@ js . call ] ] let inspect ( type a ) ( module T : Js . T with type t = a ) this ~ section : a inspectResult or_undefined = [ % js . to : T . t inspectResult or_undefined ] ( inspect this ~ section ) let get_default ( type a ) ( module T : Js . T with type t = a ) this ~ section ( ~ defaultValue : a ) : a = let defaultValue = [ % js . of : T . t ] defaultValue in [ % js . to : T . t ] ( get_default this ~ section ~ defaultValue ) end |
module WorkspaceEdit = struct include Class . Make ( ) include [ % js : val size : t -> int [ @@ js . get ] val replace : t -> uri : Uri . t -> range : Range . t -> newText : string -> unit [ @@ js . call ] val make : unit -> t [ @@ js . new " vscode . WorkspaceEdit " ] ] end |
module StatusBarAlignment = struct type t = | Left [ @ js 1 ] | Right [ @ js 2 ] [ @@ js . enum ] [ @@ js ] end |
module AccessibilityInformation = struct include Interface . Make ( ) include [ % js : val label : t -> string [ @@ js . get ] val role : t -> string or_undefined [ @@ js . get ] val create : label : string -> ? role : string -> unit -> t [ @@ js . builder ] ] end |
module StatusBarItem = struct include Interface . Make ( ) type color = ( [ ` String of string | ` ThemeColor of ThemeColor . t ] [ @ js . union ] ) [ @@ js ] let color_of_js js_val = match Ojs . type_of js_val with | " string " -> ` String ( [ % js . to : string ] js_val ) | _ -> ` ThemeColor ( [ % js . to : ThemeColor . t ] js_val ) type command = ( [ ` String of string | ` Command of Command . t ] [ @ js . union ] ) [ @@ js ] let command_of_js js_val = match Ojs . type_of js_val with | " string " -> ` String ( [ % js . to : string ] js_val ) | _ -> ` Command ( [ % js . to : Command . t ] js_val ) include [ % js : val alignment : t -> StatusBarAlignment . t [ @@ js . get ] val priority : t -> int or_undefined [ @@ js . get ] val text : t -> string [ @@ js . get ] val tooltip : t -> string or_undefined [ @@ js . get ] val color : t -> color or_undefined [ @@ js . get ] val backgroundColor : t -> ThemeColor . t or_undefined [ @@ js . get ] val command : t -> command or_undefined [ @@ js . get ] val accessibilityInformation : t -> AccessibilityInformation . t or_undefined [ @@ js . get ] val set_alignment : t -> StatusBarAlignment . t -> unit [ @@ js . set " alignment " ] val set_priority : t -> int -> unit [ @@ js . set ] val set_text : t -> string -> unit [ @@ js . set ] val set_tooltip : t -> string -> unit [ @@ js . set ] val set_color : t -> color -> unit [ @@ js . set ] val set_backgroundColor : t -> ThemeColor . t -> unit [ @@ js . set ] val set_command : t -> command -> unit [ @@ js . set ] val set_accessibilityInformation : t -> AccessibilityInformation . t -> unit [ @@ js . set ] val show : t -> unit [ @@ js . call ] val hide : t -> unit [ @@ js . call ] val dispose : t -> unit [ @@ js . call ] ] let disposable this = Disposable . make ~ dispose ( : fun ( ) -> dispose this ) end |
module WorkspaceFoldersChangeEvent = struct include Interface . Make ( ) include [ % js : val added : t -> WorkspaceFolder . t list [ @@ js . get ] val removed : t -> WorkspaceFolder . t list [ @@ js . get ] val create : added : WorkspaceFolder . t list -> removed : WorkspaceFolder . t list -> t [ @@ js . builder ] ] end |
module FormattingOptions = struct include Interface . Make ( ) include [ % js : val tabSize : t -> int [ @@ js . get ] val insertSpaces : t -> bool [ @@ js . get ] val create : tabSize : int -> insertSpaces : bool -> t [ @@ js . builder ] ] end |
module Event = struct type ' a t = listener ( ' : a -> unit ) -> ? thisArgs : Js . Any . t -> ? disposables : Disposable . t list -> unit -> Disposable . t module Make ( T : Js . T ) = struct type t = listener ( : T . t -> unit ) -> ? thisArgs : Js . Any . t -> ? disposables : Disposable . t list -> unit -> Disposable . t [ @@ js ] end end |
module EventEmitter = struct include Class . Generic ( Ojs ) ( ) module Make ( T : Js . T ) = struct type t = T . t generic [ @@ js ] module Event = Event . Make ( T ) include [ % js : val make : unit -> t [ @@ js . new " vscode . EventEmitter " ] val event : t -> Event . t [ @@ js . get ] val fire : t -> T . t -> unit [ @@ js . call ] val dispose : t -> unit -> unit [ @@ js . call ] ] end end |
module CancellationToken = struct include Interface . Make ( ) module OnCancellationRequested = Event . Make ( Js . Any ) include [ % js : val isCancellationRequested : t -> bool [ @@ js . get ] val onCancellationRequested : t -> OnCancellationRequested . t [ @@ js . get ] val create : isCancellationRequested : bool -> onCancellationRequested : OnCancellationRequested . t -> t [ @@ js . builder ] ] end |
module QuickPickItem = struct include Interface . Make ( ) include [ % js : val label : t -> string [ @@ js . get ] val description : t -> string or_undefined [ @@ js . get ] val detail : t -> string or_undefined [ @@ js . get ] val picked : t -> bool or_undefined [ @@ js . get ] val alwaysShow : t -> bool or_undefined [ @@ js . get ] val create : label : string -> ? description : string -> ? detail : string -> ? picked : bool -> ? alwaysShow : bool -> unit -> t [ @@ js . builder ] ] end |
module QuickPickOptions = struct include Interface . Make ( ) type onDidSelectItemArgs = ( [ ` QuickPickItem of QuickPickItem . t | ` String of string ] [ @ js . union ] ) [ @@ js ] let onDidSelectItemArgs_of_js js_val = match Ojs . type_of js_val with | " string " -> ` String ( [ % js . to : string ] js_val ) | _ -> ` QuickPickItem ( [ % js . to : QuickPickItem . t ] js_val ) include [ % js : val title : t -> string or_undefined [ @@ js . get ] val matchOnDescription : t -> bool or_undefined [ @@ js . get ] val matchOnDetail : t -> bool or_undefined [ @@ js . get ] val placeHolder : t -> string or_undefined [ @@ js . get ] val ignoreFocusOut : t -> bool or_undefined [ @@ js . get ] val canPickMany : t -> bool or_undefined [ @@ js . get ] val onDidSelectItem : t -> ( onDidSelectItemArgs -> unit ) or_undefined [ @@ js . get ] val create : ? title : string -> ? matchOnDescription : bool -> ? matchOnDetail : bool -> ? placeHolder : string -> ? ignoreFocusOut : bool -> ? canPickMany : bool -> ? onDidSelectItem ( : item : onDidSelectItemArgs -> unit ) -> unit -> t [ @@ js . builder ] ] end |
module ProviderResult = struct type ' a t = [ ` Value of ' a or_undefined | ` Promise of ' a or_undefined Promise . t ] let t_to_js ml_to_js = function | ` Value v -> or_undefined_to_js ml_to_js v | ` Promise p -> Promise . t_to_js ( or_undefined_to_js ml_to_js ) p let t_of_js ml_of_js js_val = if Ojs . has_property js_val " then " then ` Promise ( Promise . t_of_js ( or_undefined_of_js ml_of_js ) js_val ) else ` Value ( or_undefined_of_js ml_of_js js_val ) end |
module InputBoxOptions = struct include Interface . Make ( ) include [ % js : val title : t -> string or_undefined [ @@ js . get ] val value : t -> string or_undefined [ @@ js . get ] val valueSelection : t -> ( int * int ) or_undefined [ @@ js . get ] val prompt : t -> string or_undefined [ @@ js . get ] val placeHolder : t -> string or_undefined [ @@ js . get ] val password : t -> bool or_undefined [ @@ js . get ] val ignoreFocusOut : t -> bool or_undefined [ @@ js . get ] val validateInput : t -> ( string -> string ProviderResult . t ) or_undefined [ @@ js . get ] val create : ? title : string -> ? value : string -> ? valueSelection : int * int -> ? prompt : string -> ? placeHolder : string -> ? password : bool -> ? ignoreFocusOut : bool -> ? validateInput ( : value : string -> string option Promise . t ) -> unit -> t [ @@ js . builder ] ] end |
module MessageItem = struct include Interface . Make ( ) include [ % js : val title : t -> string [ @@ js . get ] val isCloseAffordance : t -> bool or_undefined [ @@ js . get ] val create : title : string -> ? isCloseAffordance : bool -> unit -> t [ @@ js . builder ] ] end |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.