Source file michelson_v1_entrypoints.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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
open Protocol
open Protocol_client_context
open Alpha_context
type error += Contract_without_code of Contract.t
let () =
register_error_kind
`Permanent
~id:"contractWithoutCode"
~title:"The given contract has no code"
~description:
"Attempt to get the code of a contract failed because it has nocode. No \
scriptless contract should remain."
~pp:(fun ppf contract ->
Format.fprintf ppf "Contract has no code %a." Contract.pp contract)
Data_encoding.(obj1 (req "contract" Contract.encoding))
(function Contract_without_code c -> Some c | _ -> None)
(fun c -> Contract_without_code c)
let print_errors (cctxt : #Client_context.printer) errs =
cctxt#error "%a" Error_monad.pp_print_trace errs >>= fun () -> return_unit
let script_entrypoint_type cctxt ~(chain : Chain_services.chain) ~block
(program : Script.expr) ~entrypoint =
Alpha_services.Helpers.Scripts.entrypoint_type
cctxt
(chain, block)
(program, entrypoint)
>>= function
| Ok ty -> return_some ty
| Error
(Environment.Ecoproto_error (Script_tc_errors.No_such_entrypoint _) :: _)
->
return None
| Error _ as err -> Lwt.return err
let contract_entrypoint_type cctxt ~(chain : Chain_services.chain) ~block
~contract ~entrypoint =
Alpha_services.Contract.entrypoint_type
cctxt
(chain, block)
contract
entrypoint
>>= function
| Ok ty -> return_some ty
| Error (Tezos_rpc.Context.Not_found _ :: _) -> return None
| Error _ as err -> Lwt.return err
let print_entrypoint_type (cctxt : #Client_context.printer)
?(on_errors = print_errors cctxt) ~emacs ?contract ?script_name ~entrypoint
= function
| Ok (Some ty) ->
(if emacs then
cctxt#message
"@[<v 2>((entrypoint . %s) (type . %a))@]@."
entrypoint
Michelson_v1_emacs.print_expr
ty
else
cctxt#message
"@[<v 2>Entrypoint %s: %a@]@."
entrypoint
Michelson_v1_printer.print_expr
ty)
>>= fun () -> return_unit
| Ok None ->
cctxt#message
"@[<v 2>No entrypoint named %s%a%a@]@."
entrypoint
(Format.pp_print_option (fun ppf ->
Format.fprintf ppf " for contract %a" Contract.pp))
contract
(Format.pp_print_option (fun ppf -> Format.fprintf ppf " for script %s"))
script_name
>>= fun () -> return_unit
| Error errs -> on_errors errs
let list_contract_unreachables_and_entrypoints cctxt ~chain ~block ~contract =
Alpha_services.Contract.list_entrypoints cctxt (chain, block) contract
let list_contract_unreachables cctxt ~chain ~block ~contract =
list_contract_unreachables_and_entrypoints cctxt ~chain ~block ~contract
>>=? fun (unreachables, _) -> return unreachables
let list_contract_entrypoints cctxt ~chain ~block ~contract =
list_contract_unreachables_and_entrypoints cctxt ~chain ~block ~contract
>>=? fun (_, entrypoints) ->
if not @@ List.mem_assoc ~equal:String.equal "default" entrypoints then
contract_entrypoint_type cctxt ~chain ~block ~contract ~entrypoint:"default"
>>= function
| Ok (Some ty) -> return (("default", ty) :: entrypoints)
| Ok None -> return entrypoints
| Error _ as err -> Lwt.return err
else return entrypoints
let list_unreachables cctxt ~chain ~block (program : Script.expr) =
Alpha_services.Helpers.Scripts.list_entrypoints cctxt (chain, block) program
>>=? fun (unreachables, _) -> return unreachables
let list_entrypoints cctxt ~chain ~block (program : Script.expr) =
Alpha_services.Helpers.Scripts.list_entrypoints cctxt (chain, block) program
>>=? fun (_, entrypoints) ->
if not @@ List.mem_assoc ~equal:String.equal "default" entrypoints then
script_entrypoint_type cctxt ~chain ~block program ~entrypoint:"default"
>>= function
| Ok (Some ty) -> return (("default", ty) :: entrypoints)
| Ok None -> return entrypoints
| Error _ as err -> Lwt.return err
else return entrypoints
let print_entrypoints_list (cctxt : #Client_context.printer)
?(on_errors = print_errors cctxt) ~emacs ?contract ?script_name = function
| Ok entrypoint_list ->
(if emacs then
cctxt#message
"@[<v 2>(@[%a@])@."
(Format.pp_print_list
~pp_sep:Format.pp_print_cut
(fun ppf (entrypoint, ty) ->
Format.fprintf
ppf
"@[<v 2>( ( entrypoint . %s ) ( type . @[%a@]))@]"
entrypoint
Michelson_v1_emacs.print_expr
ty))
entrypoint_list
else
cctxt#message
"@[<v 2>Entrypoints%a%a: @,%a@]@."
(Format.pp_print_option (fun ppf ->
Format.fprintf ppf " for contract %a" Contract.pp))
contract
(Format.pp_print_option (fun ppf ->
Format.fprintf ppf " for script %s"))
script_name
(Format.pp_print_list
~pp_sep:Format.pp_print_cut
(fun ppf (entrypoint, ty) ->
Format.fprintf
ppf
"@[<v 2>%s: @[%a@]@]"
entrypoint
Michelson_v1_printer.print_expr
ty))
entrypoint_list)
>>= fun () -> return_unit
| Error errs -> on_errors errs
let print_unreachables (cctxt : #Client_context.printer)
?(on_errors = print_errors cctxt) ~emacs ?contract ?script_name = function
| Ok unreachable ->
(if emacs then
cctxt#message
"@[<v 2>(@[%a@])@."
(Format.pp_print_list ~pp_sep:Format.pp_print_cut (fun ppf path ->
Format.fprintf
ppf
"@[<h>( unreachable-path . %a )@]"
(Format.pp_print_list
~pp_sep:Format.pp_print_space
(fun ppf prim ->
Format.pp_print_string ppf
@@ Michelson_v1_primitives.string_of_prim prim))
path))
unreachable
else
match unreachable with
| [] -> cctxt#message "@[<v 2>None.@]@."
| _ ->
cctxt#message
"@[<v 2>Unreachable paths in the argument%a%a: @[%a@]@."
(Format.pp_print_option (fun ppf ->
Format.fprintf ppf " of contract %a" Contract.pp))
contract
(Format.pp_print_option (fun ppf ->
Format.fprintf ppf " of script %s"))
script_name
(Format.pp_print_list ~pp_sep:Format.pp_print_cut (fun ppf ->
Format.fprintf
ppf
"@[<h> %a @]"
(Format.pp_print_list
~pp_sep:(fun ppf _ -> Format.pp_print_string ppf "/")
(fun ppf prim ->
Format.pp_print_string ppf
@@ Michelson_v1_primitives.string_of_prim prim))))
unreachable)
>>= fun () -> return_unit
| Error errs -> on_errors errs