package tezos-protocol-012-Psithaca

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Source file voting_services.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
(*****************************************************************************)
(*                                                                           *)
(* Open Source License                                                       *)
(* Copyright (c) 2018 Dynamic Ledger Solutions, Inc. <contact@tezos.com>     *)
(*                                                                           *)
(* Permission is hereby granted, free of charge, to any person obtaining a   *)
(* copy of this software and associated documentation files (the "Software"),*)
(* to deal in the Software without restriction, including without limitation *)
(* the rights to use, copy, modify, merge, publish, distribute, sublicense,  *)
(* and/or sell copies of the Software, and to permit persons to whom the     *)
(* Software is furnished to do so, subject to the following conditions:      *)
(*                                                                           *)
(* The above copyright notice and this permission notice shall be included   *)
(* in all copies or substantial portions of the Software.                    *)
(*                                                                           *)
(* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR*)
(* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,  *)
(* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL   *)
(* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER*)
(* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING   *)
(* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER       *)
(* DEALINGS IN THE SOFTWARE.                                                 *)
(*                                                                           *)
(*****************************************************************************)

open Alpha_context

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 weight, in number of rolls."
      ~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.int32)
      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 number of rolls for the delegates in the voting listings."
      ~query:RPC_query.empty
      ~output:Data_encoding.int32
      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 () ()
OCaml

Innovation. Community. Security.