Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file client_proto_programs_commands.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339(*****************************************************************************)(* *)(* Open Source License *)(* Copyright (c) 2018 Dynamic Ledger Solutions, Inc. <contact@tezos.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_argsletcommands()=letopenTezos_clicinletshow_types_switch=switch~long:"details"~short:'v'~doc:"show the types of each instruction"()inletemacs_mode_switch=switch~long:"emacs"?short:None~doc:"output in `michelson-mode.el` compatible format"()inlettrace_stack_switch=switch~long:"trace-stack"~doc:"show the stack after each step"()inletamount_arg=Client_proto_args.tez_arg~parameter:"amount"~doc:"amount of the transfer in \xEA\x9C\xA9"~default:"0.05"inletcustom_gas_flag=arg~long:"gas"~short:'G'~doc:"Initial quantity of gas for typechecking and execution"~placeholder:"gas"(parameter(fun_ctxstr->tryletv=Z.of_stringstrinassert(Compare.Z.(v>=Z.zero));returnvwith_->failwith"invalid gas limit (must be a positive number)"))inletresolve_max_gascctxtblock=function|None->Alpha_services.Constants.allcctxt(`Main,block)>>=?fun{parametric={hard_gas_limit_per_operation;_};_}->returnhard_gas_limit_per_operation|Somegas->returngasinletdata_parameter=Tezos_clic.parameter(fun_data->Lwt.return(Micheline_parser.no_parsing_error@@Michelson_v1_parser.parse_expressiondata))inletbytes_parameter~name~desc=Tezos_clic.param~name~desc(parameter(fun(_cctxt:Alpha_client_context.full)s->matchifString.lengths<2||s.[0]<>'0'||s.[1]<>'x'thenNoneelseHex.to_bytes(`Hex(String.subs2(String.lengths-2)))with|Somes->returns|None->failwith"Invalid bytes, expecting hexadecimal notation (e.g. \
0x1234abcd)"))inletsignature_parameter=Tezos_clic.parameter(fun_cctxts->matchTezos_crypto.Signature.V0.of_b58check_optswith|Somes->returns|None->failwith"Not given a valid signature")in[command~group~desc:"Lists all scripts in the library."no_options(fixed["list";"known";"scripts"])(fun()(cctxt:Alpha_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:Alpha_client_context.full)->Program.to_sourceprogram>>=?funsource->cctxt#message"%s\n"source>>=fun()->return_unit);command~group~desc:"Ask the node to run a script."(args3trace_stack_switchamount_argno_print_source_flag)(prefixes["run";"script"]@@Program.source_param@@prefixes["on";"storage"]@@Tezos_clic.param~name:"storage"~desc:"the storage data"data_parameter@@prefixes["and";"input"]@@Tezos_clic.param~name:"storage"~desc:"the input data"data_parameter@@stop)(fun(trace_exec,amount,no_print_source)programstorageinputcctxt->Lwt.return@@Micheline_parser.no_parsing_errorprogram>>=?funprogram->letshow_source=notno_print_sourceiniftrace_execthentracecctxt~block:cctxt#block~amount~program~storage~input()>>=funres->print_trace_resultcctxt~show_source~parsed:programreselseruncctxt~block:cctxt#block~amount~program~storage~input()>>=funres->print_run_resultcctxt~show_source~parsed:programres);command~group~desc:"Ask the node to typecheck a script."(args4show_types_switchemacs_mode_switchno_print_source_flagcustom_gas_flag)(prefixes["typecheck";"script"]@@Program.source_param@@stop)(fun(show_types,emacs_mode,no_print_source,original_gas)programcctxt->matchprogramwith|program,[]->resolve_max_gascctxtcctxt#blockoriginal_gas>>=?funoriginal_gas->typecheck_programcctxt~block:cctxt#block~gas:original_gasprogram>>=funres->print_typecheck_result~emacs:emacs_mode~show_types~print_source_on_error:(notno_print_source)programrescctxt|res_with_errorswhenemacs_mode->cctxt#message"(@[<v 0>(types . ())@ (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 typecheck a data expression."(args2no_print_source_flagcustom_gas_flag)(prefixes["typecheck";"data"]@@Tezos_clic.param~name:"data"~desc:"the data to typecheck"data_parameter@@prefixes["against";"type"]@@Tezos_clic.param~name:"type"~desc:"the expected type"data_parameter@@stop)(fun(no_print_source,custom_gas)datatycctxt->resolve_max_gascctxtcctxt#blockcustom_gas>>=?funoriginal_gas->Client_proto_programs.typecheck_datacctxt~block:cctxt#block~gas:original_gas~data~ty()>>=function|Okgas->cctxt#message"@[<v 0>Well typed@,Gas remaining: %a@]"Alpha_context.Gas.ppgas>>=fun()->return_unit|Errorerrs->cctxt#warning"%a"(Michelson_v1_error_reporter.report_errors~details:false~show_source:(notno_print_source)?parsed:None)errs>>=fun()->cctxt#error"ill-typed data");command~group~desc:"Ask the node to pack a data expression.\n\
The returned hash is the same as what Michelson instruction `PACK` \
would have produced.\n\
Also displays the result of hashing this packed data with `BLAKE2B`, \
`SHA256` or `SHA512` instruction."(args1custom_gas_flag)(prefixes["hash";"data"]@@Tezos_clic.param~name:"data"~desc:"the data to hash"data_parameter@@prefixes["of";"type"]@@Tezos_clic.param~name:"type"~desc:"type of the data"data_parameter@@stop)(funcustom_gasdatatypcctxt->resolve_max_gascctxtcctxt#blockcustom_gas>>=?funoriginal_gas->Alpha_services.Helpers.Scripts.pack_datacctxt(`Main,cctxt#block)(data.expanded,typ.expanded,Someoriginal_gas)>>=function|Ok(bytes,remaining_gas)->lethash=Script_expr_hash.hash_bytes[bytes]incctxt#message"Raw packed data: 0x%a@,\
Hash: %a@,\
Raw Blake2b hash: 0x%a@,\
Raw Sha256 hash: 0x%a@,\
Raw Sha512 hash: 0x%a@,\
Gas remaining: %a"Hex.pp(Hex.of_bytesbytes)Script_expr_hash.pphashHex.pp(Hex.of_bytes(Script_expr_hash.to_byteshash))Hex.pp(Hex.of_bytes(Environment.Raw_hashes.sha256bytes))Hex.pp(Hex.of_bytes(Environment.Raw_hashes.sha512bytes))Alpha_context.Gas.ppremaining_gas>>=fun()->return_unit|Errorerrs->cctxt#warning"%a"(Michelson_v1_error_reporter.report_errors~details:false~show_source:false?parsed:None)errs>>=fun()->cctxt#error"ill-formed data");command~group~desc:"Sign a raw sequence of bytes and display it using the format expected \
by Michelson instruction `CHECK_SIGNATURE`."no_options(prefixes["sign";"bytes"]@@bytes_parameter~name:"data"~desc:"the raw data to sign"@@prefixes["for"]@@Client_keys_v0.Secret_key.source_param@@stop)(fun()bytesskcctxt->Client_keys_v0.signcctxtskbytes>>=?funsignature->cctxt#message"Signature: %a"Tezos_crypto.Signature.V0.ppsignature>>=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"]@@Tezos_clic.param~name:"signature"~desc:"the signature to check"signature_parameter@@stop)(funquietbytes(_,(key_locator,_))signature(cctxt:#Alpha_client_context.full)->Client_keys_v0.checkkey_locatorsignaturebytes>>=?function|false->cctxt#error"invalid signature"|true->ifquietthenreturn_unitelsecctxt#message"Signature check successful.">>=fun()->return_unit);]