package tezos-protocol-alpha

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

Source file misbehaviour_repr.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
(*****************************************************************************)
(*                                                                           *)
(* SPDX-License-Identifier: MIT                                              *)
(* Copyright (c) 2023 Nomadic Labs, <contact@nomadic-labs.com>               *)
(*                                                                           *)
(*****************************************************************************)

type kind = Double_baking | Double_attesting | Double_preattesting

let kind_encoding =
  let open Data_encoding in
  string_enum
    [
      ("preattestation", Double_preattesting);
      ("attestation", Double_attesting);
      ("block", Double_baking);
    ]

type t = {level : Raw_level_repr.t; round : Round_repr.t; kind : kind}

let compare_kind a b =
  let to_int = function
    | Double_baking -> 0
    | Double_attesting -> 1
    | Double_preattesting -> 2
  in
  Compare.Int.compare (to_int a) (to_int b)

let equal_kind a b = Compare.Int.equal 0 (compare_kind a b)

let compare a b =
  Compare.or_else (Raw_level_repr.compare a.level b.level) @@ fun () ->
  Compare.or_else (Round_repr.compare a.round b.round) @@ fun () ->
  compare_kind a.kind b.kind

let encoding =
  let open Data_encoding in
  conv
    (fun {level; round; kind} -> (level, round, kind))
    (fun (level, round, kind) -> {level; round; kind})
    (obj3
       (req "level" Raw_level_repr.encoding)
       (req "round" Round_repr.encoding)
       (req "kind" kind_encoding))
OCaml

Innovation. Community. Security.