Source file client_proto_context_commands.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
open Protocol
open Alpha_context
open Client_proto_context
open Client_proto_contracts
open Client_keys_v0
let report_michelson_errors ?(no_print_source = false) ~msg
(cctxt : #Client_context.printer) = function
| Error errs ->
cctxt#warning
"%a"
(Michelson_v1_error_reporter.report_errors
~details:(not no_print_source)
~show_source:(not no_print_source)
?parsed:None)
errs
>>= fun () ->
cctxt#error "%s" msg >>= fun () -> Lwt.return_none
| Ok data -> Lwt.return_some data
let group =
{
Tezos_clic.name = "context";
title = "Block contextual commands (see option -block)";
}
let alphanet = {Tezos_clic.name = "alphanet"; title = "Alphanet only commands"}
let binary_description =
{Tezos_clic.name = "description"; title = "Binary Description"}
let commands () =
let open Tezos_clic in
[
command
~group
~desc:"Access the timestamp of the block."
(args1
(switch ~doc:"output time in seconds" ~short:'s' ~long:"seconds" ()))
(fixed ["get"; "timestamp"])
(fun seconds (cctxt : Alpha_client_context.full) ->
Shell_services.Blocks.Header.shell_header cctxt ~block:cctxt#block ()
>>=? fun {timestamp = v; _} ->
(if seconds then cctxt#message "%Ld" (Time.Protocol.to_seconds v)
else cctxt#message "%s" (Time.Protocol.to_notation v))
>>= fun () -> return_unit);
command
~group
~desc:"Lists all non empty contracts of the block."
no_options
(fixed ["list"; "contracts"])
(fun () (cctxt : Alpha_client_context.full) ->
list_contract_labels cctxt ~chain:`Main ~block:cctxt#block
>>=? fun contracts ->
List.iter_s
(fun (alias, hash, kind) -> cctxt#message "%s%s%s" hash kind alias)
contracts
>>= fun () -> return_unit);
command
~group
~desc:"Get the balance of a contract."
no_options
(prefixes ["get"; "balance"; "for"]
@@ ContractAlias.destination_param ~name:"src" ~desc:"source contract"
@@ stop)
(fun () (_, contract) (cctxt : Alpha_client_context.full) ->
get_balance cctxt ~chain:`Main ~block:cctxt#block contract
>>=? fun amount ->
cctxt#answer "%a %s" Tez.pp amount Client_proto_args.tez_sym
>>= fun () -> return_unit);
command
~group
~desc:"Get the storage of a contract."
no_options
(prefixes ["get"; "script"; "storage"; "for"]
@@ ContractAlias.destination_param ~name:"src" ~desc:"source contract"
@@ stop)
(fun () (_, contract) (cctxt : Alpha_client_context.full) ->
get_storage cctxt ~chain:`Main ~block:cctxt#block contract >>=? function
| None -> cctxt#error "This is not a smart contract."
| Some storage ->
cctxt#answer "%a" Michelson_v1_printer.print_expr_unwrapped storage
>>= fun () -> return_unit);
command
~group
~desc:"Get the code of a contract."
no_options
(prefixes ["get"; "script"; "code"; "for"]
@@ ContractAlias.destination_param ~name:"src" ~desc:"source contract"
@@ stop)
(fun () (_, contract) (cctxt : Alpha_client_context.full) ->
get_script cctxt ~chain:`Main ~block:cctxt#block contract >>=? function
| None -> cctxt#error "This is not a smart contract."
| Some {code; storage = _} -> (
match Script_repr.force_decode code with
| Error errs ->
cctxt#error
"%a"
(Format.pp_print_list
~pp_sep:Format.pp_print_newline
Environment.Error_monad.pp)
errs
| Ok (code, _) ->
cctxt#answer "%a" Michelson_v1_printer.print_expr_unwrapped code
>>= fun () -> return_unit));
command
~group
~desc:"Get the manager of a contract."
no_options
(prefixes ["get"; "manager"; "for"]
@@ ContractAlias.destination_param ~name:"src" ~desc:"source contract"
@@ stop)
(fun () (_, contract) (cctxt : Alpha_client_context.full) ->
Client_proto_contracts.get_manager
cctxt
~chain:`Main
~block:cctxt#block
contract
>>=? fun manager ->
Public_key_hash.rev_find cctxt manager >>=? fun mn ->
Public_key_hash.to_source manager >>=? fun m ->
cctxt#message
"%s (%s)"
m
(match mn with None -> "unknown" | Some n -> "known as " ^ n)
>>= fun () -> return_unit);
command
~group
~desc:"Get the delegate of a contract."
no_options
(prefixes ["get"; "delegate"; "for"]
@@ ContractAlias.destination_param ~name:"src" ~desc:"source contract"
@@ stop)
(fun () (_, contract) (cctxt : Alpha_client_context.full) ->
Client_proto_contracts.get_delegate
cctxt
~chain:`Main
~block:cctxt#block
contract
>>=? function
| None -> cctxt#message "none" >>= fun () -> return_unit
| Some delegate ->
Public_key_hash.rev_find cctxt delegate >>=? fun mn ->
Public_key_hash.to_source delegate >>=? fun m ->
cctxt#message
"%s (%s)"
m
(match mn with None -> "unknown" | Some n -> "known as " ^ n)
>>= fun () -> return_unit);
command
~group:binary_description
~desc:"Describe unsigned block header"
no_options
(fixed ["describe"; "unsigned"; "block"; "header"])
(fun () (cctxt : Alpha_client_context.full) ->
cctxt#message
"%a"
Data_encoding.Binary_schema.pp
(Data_encoding.Binary.describe
Alpha_context.Block_header.unsigned_encoding)
>>= fun () -> return_unit);
command
~group:binary_description
~desc:"Describe unsigned operation"
no_options
(fixed ["describe"; "unsigned"; "operation"])
(fun () (cctxt : Alpha_client_context.full) ->
cctxt#message
"%a"
Data_encoding.Binary_schema.pp
(Data_encoding.Binary.describe
Alpha_context.Operation.unsigned_encoding)
>>= fun () -> return_unit);
]