Source file pending_denunciations_storage.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
let find ctxt delegate =
let open Lwt_result_syntax in
let* denunciations_opt = Storage.Pending_denunciations.find ctxt delegate in
return @@ Option.value denunciations_opt ~default:[]
let add_denunciation ctxt ~misbehaving_delegate operation_hash
~rewarded_delegate misbehaviour =
let open Lwt_result_syntax in
let* denunciations = find ctxt misbehaving_delegate in
let denunciations =
Denunciations_repr.add
operation_hash
rewarded_delegate
misbehaviour
denunciations
in
let*! ctxt =
Storage.Pending_denunciations.add ctxt misbehaving_delegate denunciations
in
return ctxt
let set_denunciations ctxt delegate denunciations =
match denunciations with
| [] -> Storage.Pending_denunciations.remove ctxt delegate
| _ -> Storage.Pending_denunciations.add ctxt delegate denunciations
let has_pending_denunciations ctxt delegate =
Storage.Pending_denunciations.mem ctxt delegate
let fold = Storage.Pending_denunciations.fold
let clear ctxt = Storage.Pending_denunciations.clear ctxt
module For_RPC = struct
let pending_denunciations_list ctxt =
let open Lwt_syntax in
let+ r = Storage.Pending_denunciations.bindings ctxt in
List.map (fun (x, l) -> List.map (fun y -> (x, y)) l) r |> List.flatten
end