Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file client_proto_programs_commands.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454(*****************************************************************************)(* *)(* Open Source License *)(* Copyright (c) 2018 Dynamic Ledger Solutions, Inc. <contact@tezos.com> *)(* Copyright (c) 2019 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. *)(* *)(*****************************************************************************)openProtocolletgroup={Tezos_clic.name="scripts";title="Commands for managing the library of known scripts";}openTezos_michelineopenClient_proto_programsopenClient_proto_argsletsafe_decode_json(cctxt:Protocol_client_context.full)encodingjson=matchData_encoding.Json.destructencodingjsonwith|exceptionData_encoding.Json.Cannot_destruct(_,exc)->cctxt#error"could not decode json (%a)"(Data_encoding.Json.print_error~print_unknown:(funfmtexc->Format.fprintffmt"%s"(Printexc.to_stringexc)))exc|exception((Stack_overflow|Out_of_memory)asexc)->raiseexc|exceptionexc->cctxt#error"could not decode json (%s)"(Printexc.to_stringexc)|expr->returnexprletcommands()=letopenTezos_clicinletemacs_mode_switch=switch~long:"emacs"?short:None~doc:"output in `michelson-mode.el` compatible format"()inletzero_loc_switch=switch~short:'z'~long:"zero-loc"~doc:"replace location with \"0\""()inletparse_exprexpr=Lwt.return@@Micheline_parser.no_parsing_error@@Michelson_v1_parser.parse_expressionexprinletdata_parameter=parameter(fun_data->parse_exprdata)inletdata_type_arg=arg~doc:"the given data will be type-checked against this type"~short:'t'~long:"type"~placeholder:"unit"data_parameterinletbytes_parameter~name~desc=param~name~descClient_proto_args.bytes_parameterinletsignature_parameter=parameter(fun_cctxts->matchTezos_crypto.Signature.V0.of_b58check_optswith|Somes->returns|None->failwith"Not given a valid signature")inletconvert_input_format_param=param~name:"input_format"~desc:"format of the input for conversion"(parameter~autocomplete:(fun_->return["michelson";"json";"binary"])(fun_s->matchString.lowercase_asciiswith|"michelson"->return`Michelson|"json"->return`JSON|"binary"->return`Binary|_->failwith"invalid input format, expecting one of \"michelson\", \
\"json\" or \"binary\"."))inletconvert_output_format_param=param~name:"output_format"~desc:"format of the conversion output"(parameter~autocomplete:(fun_->return["michelson";"json";"binary";"ocaml"])(fun_s->matchString.lowercase_asciiswith|"michelson"->return`Michelson|"json"->return`JSON|"binary"->return`Binary|"ocaml"->return`OCaml|_->failwith"invalid output format, expecting one of \"michelson\", \
\"json\", \"binary\" or \"ocaml\"."))inletfile_or_literal_param=param~name:"source"~desc:"literal or a path to a file"(parameter(funcctxts->cctxt#read_files>>=function|Okv->returnv|Error_->returns))in[command~group~desc:"Lists all scripts in the library."no_options(fixed["list";"known";"scripts"])(fun()(cctxt:Protocol_client_context.full)->Program.loadcctxt>>=?funlist->List.iter_s(fun(n,_)->cctxt#message"%s"n)list>>=fun()->return_unit);command~group~desc:"Add a script to the library."(args1(Program.force_switch()))(prefixes["remember";"script"]@@Program.fresh_alias_param@@Program.source_param@@stop)(funforcenamehashcctxt->Program.of_freshcctxtforcename>>=?funname->Program.add~forcecctxtnamehash);command~group~desc:"Remove a script from the library."no_options(prefixes["forget";"script"]@@Program.alias_param@@stop)(fun()(name,_)cctxt->Program.delcctxtname);command~group~desc:"Display a script from the library."no_options(prefixes["show";"known";"script"]@@Program.alias_param@@stop)(fun()(_,program)(cctxt:Protocol_client_context.full)->Program.to_sourceprogram>>=?funsource->cctxt#message"%s\n"source>>=fun()->return_unit);command~group~desc:"Parse a byte sequence (in hexadecimal notation) as a data expression, \
as per Michelson instruction `UNPACK`."no_options(prefixes["unpack";"michelson";"data"]@@bytes_parameter~name:"bytes"~desc:"the packed data to parse"@@stop)(fun()bytescctxt->(ifBytes.getbytes0!='\005'thenfailwith"Not a piece of packed Michelson data (must start with `0x05`)"elsereturn_unit)>>=?fun()->(* Remove first byte *)letbytes=Bytes.subbytes1(Bytes.lengthbytes-1)inmatchData_encoding.Binary.of_bytes_optAlpha_context.Script.expr_encodingbyteswith|None->failwith"Could not decode bytes"|Someexpr->cctxt#message"%a"Michelson_v1_printer.print_expr_unwrappedexpr>>=fun()->return_unit);command~group~desc:"Check the signature of a byte sequence as per Michelson instruction \
`CHECK_SIGNATURE`."(args1(switch~doc:"Use only exit codes"~short:'q'~long:"quiet"()))(prefixes["check";"that"]@@bytes_parameter~name:"bytes"~desc:"the signed data"@@prefixes["was";"signed";"by"]@@Client_keys_v0.Public_key.alias_param~name:"key"@@prefixes["to";"produce"]@@param~name:"signature"~desc:"the signature to check"signature_parameter@@stop)(funquietbytes(_,(key_locator,_))signature(cctxt:#Protocol_client_context.full)->Client_keys_v0.checkkey_locatorsignaturebytes>>=?function|false->cctxt#error"invalid signature"|true->ifquietthenreturn_unitelsecctxt#message"Signature check successful.">>=fun()->return_unit);command~group~desc:"Ask the type of an entrypoint of a script."(args2emacs_mode_switchno_print_source_flag)(prefixes["get";"script";"entrypoint";"type";"of"]@@string~name:"entrypoint"~desc:"the entrypoint to describe"@@prefixes["for"]@@Program.source_param@@stop)(fun(emacs_mode,no_print_source)entrypointprogramcctxt->matchprogramwith|program,[]->entrypoint_typecctxt~chain:cctxt#chain~block:cctxt#blockprogram~entrypoint>>=funentrypoint_type->print_entrypoint_type~emacs:emacs_mode~show_source:(notno_print_source)~parsed:program~entrypointcctxtentrypoint_type|res_with_errorswhenemacs_mode->cctxt#message"(@[<v 0>(entrypoint . ())@ (errors . %a)@])"Michelson_v1_emacs.report_errorsres_with_errors>>=fun()->return_unit|parsed,errors->cctxt#message"%a"(funppf()->Michelson_v1_error_reporter.report_errors~details:(notno_print_source)~parsed~show_source:(notno_print_source)ppferrors)()>>=fun()->cctxt#error"syntax error in program");command~group~desc:"Ask the node to list the entrypoints of a script."(args2emacs_mode_switchno_print_source_flag)(prefixes["get";"script";"entrypoints";"for"]@@Program.source_param@@stop)(fun(emacs_mode,no_print_source)programcctxt->matchprogramwith|program,[]->list_entrypointscctxt~chain:cctxt#chain~block:cctxt#blockprogram>>=funentrypoints->print_entrypoints_list~emacs:emacs_mode~show_source:(notno_print_source)~parsed:programcctxtentrypoints|res_with_errorswhenemacs_mode->cctxt#message"(@[<v 0>(entrypoints . ())@ (errors . %a)@])"Michelson_v1_emacs.report_errorsres_with_errors>>=fun()->return_unit|parsed,errors->cctxt#message"%a"(funppf()->Michelson_v1_error_reporter.report_errors~details:(notno_print_source)~parsed~show_source:(notno_print_source)ppferrors)()>>=fun()->cctxt#error"syntax error in program");command~desc:"Conversion of Michelson script from Micheline, JSON or binary to \
Micheline, JSON, binary or OCaml"(args1zero_loc_switch)(prefixes["convert";"script"]@@file_or_literal_param@@prefix"from"@@convert_input_format_param@@prefix"to"@@convert_output_format_param@@stop)(funzero_locexpr_stringfrom_formatto_format(cctxt:Protocol_client_context.full)->(matchfrom_formatwith|`Michelson->letprogram=Michelson_v1_parser.parse_toplevelexpr_stringinLwt.return@@Micheline_parser.no_parsing_errorprogram>>=?funprogram->(typecheck_programcctxt~chain:cctxt#chain~block:cctxt#blockprogram>>=function|Error_asres->print_typecheck_result~emacs:false~show_types:true~print_source_on_error:trueprogramrescctxt|Ok_->return_unit)>>=?fun()->returnprogram.expanded|`JSON->(matchData_encoding.Json.from_stringexpr_stringwith|Errorerr->cctxt#error"%s"err|Okjson->safe_decode_jsoncctxtAlpha_context.Script.expr_encodingjson)|`Binary->(bytes_of_prefixed_stringexpr_string>>=?funbytes->matchData_encoding.Binary.of_bytes_optAlpha_context.Script.expr_encodingbyteswith|None->failwith"Could not decode bytes"|Someexpr->returnexpr))>>=?fun(expression:Alpha_context.Script.expr)->letoutput=matchto_formatwith|`Michelson->Micheline_printer.printableMichelson_v1_primitives.string_of_primexpression|>Format.asprintf"%a"Micheline_printer.print_expr|`JSON->Data_encoding.Json.(constructAlpha_context.Script.expr_encodingexpression|>to_string)|`Binary->Format.asprintf"0x%s"(Data_encoding.Binary.(to_bytes_exnAlpha_context.Script.expr_encodingexpression)|>Hex.of_bytes|>Hex.show)|`OCaml->Michelson_v1_printer.micheline_string_of_expression~zero_locexpressionincctxt#message"%s"output>>=fun()->return_unit);command~desc:"Conversion of Micheline expression from Micheline, JSON or binary to \
Micheline, JSON, binary or OCaml"(args2zero_loc_switchdata_type_arg)(prefixes["convert";"data"]@@file_or_literal_param@@prefix"from"@@convert_input_format_param@@prefix"to"@@convert_output_format_param@@stop)(fun(zero_loc,data_ty)data_stringfrom_formatto_format(cctxt:Protocol_client_context.full)->letmicheline_of_exprexpr=Micheline_printer.printableMichelson_v1_primitives.string_of_primexpr|>Format.asprintf"%a"Micheline_printer.print_exprinlettypecheck_parsed~data~ty=Client_proto_programs.typecheck_datacctxt~chain:cctxt#chain~block:cctxt#block~data~ty()>>=function|Errorerrs->failwith"%a"(Michelson_v1_error_reporter.report_errors~details:false~show_source:false?parsed:None)errs|Ok_gas->returndata.expandedinlettypecheck_expr~expr~ty=letdata_string=micheline_of_exprexprinparse_exprdata_string>>=?fundata->typecheck_parsed~data~tyin(matchfrom_formatwith|`Michelson->(parse_exprdata_string>>=?fundata->matchdata_tywith|Somety->typecheck_parsed~data~ty|None->returndata.expanded)|`JSON->(matchData_encoding.Json.from_stringdata_stringwith|Errorerr->cctxt#error"%s"err|Okjson->(safe_decode_jsoncctxtAlpha_context.Script.expr_encodingjson>>=?funexpr->matchdata_tywith|None->returnexpr|Somety->typecheck_expr~expr~ty))|`Binary->(bytes_of_prefixed_stringdata_string>>=?funbytes->matchData_encoding.Binary.of_bytes_optAlpha_context.Script.expr_encodingbyteswith|None->failwith"Could not decode bytes"|Someexpr->(matchdata_tywith|None->returnexpr|Somety->typecheck_expr~expr~ty)))>>=?fun(expression:Alpha_context.Script.expr)->letoutput=matchto_formatwith|`Michelson->micheline_of_exprexpression|`JSON->Data_encoding.Json.(constructAlpha_context.Script.expr_encodingexpression|>to_string)|`Binary->Format.asprintf"0x%s"(Data_encoding.Binary.(to_bytes_exnAlpha_context.Script.expr_encodingexpression)|>Hex.of_bytes|>Hex.show)|`OCaml->Michelson_v1_printer.micheline_string_of_expression~zero_locexpressionincctxt#message"%s"output>>=fun()->return_unit);]