package octez-shell-libs

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

Source file proxy_delegate_maker.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
(*****************************************************************************)
(*                                                                           *)
(* Open Source License                                                       *)
(* Copyright (c) 2022 Nomadic Labs, <contact@nomadic-labs.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.                                                 *)
(*                                                                           *)
(*****************************************************************************)

let of_memory_tree (t : Tezos_context_memory.Context.tree) :
    Tezos_protocol_environment.Proxy_delegate.t =
  (module struct
    let proxy_dir_mem key =
      let open Lwt_syntax in
      let* v = Tezos_context_memory.Context.Tree.mem_tree t key in
      return_ok v

    let proxy_get key =
      let open Lwt_syntax in
      let* v = Tezos_context_memory.Context.Tree.find_tree t key in
      return_ok v

    let proxy_mem key =
      let open Lwt_syntax in
      let* v = Tezos_context_memory.Context.Tree.mem t key in
      return_ok v
  end : Tezos_protocol_environment.Proxy_delegate.T)

let of_memory_context (m : Tezos_context_memory.Context.t) :
    Tezos_protocol_environment.Proxy_delegate.t =
  (module struct
    let proxy_dir_mem key =
      let open Lwt_syntax in
      let* v = Tezos_context_memory.Context.mem_tree m key in
      return_ok v

    let proxy_get key =
      let open Lwt_syntax in
      let* v = Tezos_context_memory.Context.find_tree m key in
      return_ok v

    let proxy_mem key =
      let open Lwt_syntax in
      let* v = Tezos_context_memory.Context.mem m key in
      return_ok v
  end : Tezos_protocol_environment.Proxy_delegate.T)

let make_index ~(context_path : string) : Tezos_context.Context.index Lwt.t =
  Tezos_context.Context.init ~readonly:true context_path

let of_index ~(index : Tezos_context.Context.index)
    (hash : Tezos_crypto.Hashed.Context_hash.t) :
    Tezos_protocol_environment.Proxy_delegate.t tzresult Lwt.t =
  let open Lwt_syntax in
  let* ctxt = Tezos_context.Context.checkout index hash in
  match ctxt with
  | None ->
      failwith
        "Couldn't check out the hash %s"
        (Tezos_crypto.Hashed.Context_hash.to_string hash)
  | Some ctxt ->
      let proxy_data_dir : Tezos_protocol_environment.Proxy_delegate.t =
        (module struct
          let proxy_dir_mem (key : Tezos_context.Context.key) :
              bool tzresult Lwt.t =
            let* (res : bool) = Tezos_context.Context.mem_tree ctxt key in
            return_ok res

          let proxy_get (key : Tezos_context.Context.key) :
              Tezos_context_memory.Context.tree option tzresult Lwt.t =
            let* res = Tezos_context.Context.to_memory_tree ctxt key in
            return_ok res

          let proxy_mem (key : Tezos_context.Context.key) : bool tzresult Lwt.t
              =
            let* res = Tezos_context.Context.mem ctxt key in
            return_ok res
        end)
      in
      return_ok proxy_data_dir
OCaml

Innovation. Community. Security.