Source file operation_kind.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
(** The kind of operations that can be injected by the rollup node. *)
type t =
| Publish
| Add_messages
| Cement
| Timeout
| Refute
| Recover
| Execute_outbox_message
let all =
[
Publish;
Add_messages;
Cement;
Timeout;
Refute;
Recover;
Execute_outbox_message;
]
module Map = Map.Make (struct
type nonrec t = t
let compare = Stdlib.compare
end)
let to_string = function
| Publish -> "publish"
| Add_messages -> "add_messages"
| Cement -> "cement"
| Timeout -> "timeout"
| Refute -> "refute"
| Recover -> "recover"
| Execute_outbox_message -> "execute_outbox_message"
let of_string = function
| "publish" -> Some Publish
| "add_messages" -> Some Add_messages
| "cement" -> Some Cement
| "timeout" -> Some Timeout
| "refute" -> Some Refute
| "recover" -> Some Recover
| "execute_outbox_message" -> Some Execute_outbox_message
| _ -> None
let of_string_exn s =
match of_string s with
| Some p -> p
| None -> invalid_arg ("operation_kind_of_string " ^ s)
let encoding =
Data_encoding.string_enum
@@ List.map
(fun operation_kind -> (to_string operation_kind, operation_kind))
all
let map_encoding value_encoding =
let open Data_encoding in
conv
Map.bindings
(fun l -> List.to_seq l |> Map.of_seq)
(Dictionary_encoding.dictionary_encoding
~keys:all
~string_of_key:to_string
~key_of_string:of_string_exn
~value_encoding)