package tezos-client-006-PsCARTHA
Tezos/Protocol: protocol specific library for `tezos-client`
Install
Dune Dependency
Authors
Maintainers
Sources
tezos-17.3.tar.gz
sha256=7062cd57addd452852598a2214ade393130efa087b99068d53713bdf912b3680
sha512=08e4091144a03ce3c107fb91a66501bd8b65ca3278917c455a2eaac6df3e108ade63f6ab8340a4bb152d60f404326e464d0ec95d26cafe8e82f870465d24a5fc
doc/src/tezos-client-006-PsCARTHA.commands/client_proto_programs_commands.ml.html
Source file client_proto_programs_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 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766
(*****************************************************************************) (* *) (* 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. *) (* *) (*****************************************************************************) open Protocol let group = { Tezos_clic.name = "scripts"; title = "Commands for managing the library of known scripts"; } open Tezos_micheline open Client_proto_programs open Client_proto_args open Client_proto_contracts let safe_decode_json (cctxt : Protocol_client_context.full) encoding json = match Data_encoding.Json.destruct encoding json with | exception Data_encoding.Json.Cannot_destruct (_, exc) -> cctxt#error "could not decode json (%a)" (Data_encoding.Json.print_error ~print_unknown:(fun fmt exc -> Format.fprintf fmt "%s" (Printexc.to_string exc))) exc | exception ((Stack_overflow | Out_of_memory) as exc) -> raise exc | exception exc -> cctxt#error "could not decode json (%s)" (Printexc.to_string exc) | expr -> return expr let commands () = let open Tezos_clic in let show_types_switch = switch ~long:"details" ~short:'v' ~doc:"show the types of each instruction" () in let emacs_mode_switch = switch ~long:"emacs" ?short:None ~doc:"output in `michelson-mode.el` compatible format" () in let trace_stack_switch = switch ~long:"trace-stack" ~doc:"show the stack after each step" () in let zero_loc_switch = switch ~short:'z' ~long:"zero-loc" ~doc:"replace location with \"0\"" () in let amount_arg = Client_proto_args.tez_arg ~parameter:"amount" ~doc:"amount of the transfer in \xEA\x9C\xA9" ~default:"0.05" in let source_arg = ContractAlias.destination_arg ~name:"source" ~doc:"name of the source (i.e. SENDER) contract for the transaction" () in let payer_arg = ContractAlias.destination_arg ~name:"payer" ~doc:"name of the payer (i.e. SOURCE) contract for the transaction" () in let custom_gas_flag = arg ~long:"gas" ~short:'G' ~doc:"Initial quantity of gas for typechecking and execution" ~placeholder:"gas" (parameter (fun _ctx str -> try let v = Z.of_string str in assert (Compare.Z.(v >= Z.zero)) ; return v with _ -> failwith "invalid gas limit (must be a positive number)")) in let resolve_max_gas cctxt block = function | None -> Alpha_services.Constants.all cctxt (cctxt#chain, block) >>=? fun {parametric = {hard_gas_limit_per_operation; _}; _} -> return hard_gas_limit_per_operation | Some gas -> return gas in let parse_expr expr = Lwt.return @@ Micheline_parser.no_parsing_error @@ Michelson_v1_parser.parse_expression expr in let data_parameter = parameter (fun _ data -> parse_expr data) in let data_type_arg = arg ~doc:"the given data will be type-checked against this type" ~short:'t' ~long:"type" ~placeholder:"unit" data_parameter in let bytes_parameter ~name ~desc = param ~name ~desc Client_proto_args.bytes_parameter in let signature_parameter = parameter (fun _cctxt s -> match Tezos_crypto.Signature.V0.of_b58check_opt s with | Some s -> return s | None -> failwith "Not given a valid signature") in let convert_input_format_param = param ~name:"input_format" ~desc:"format of the input for conversion" (parameter ~autocomplete:(fun _ -> return ["michelson"; "json"; "binary"]) (fun _ s -> match String.lowercase_ascii s with | "michelson" -> return `Michelson | "json" -> return `JSON | "binary" -> return `Binary | _ -> failwith "invalid input format, expecting one of \"michelson\", \ \"json\" or \"binary\".")) in let convert_output_format_param = param ~name:"output_format" ~desc:"format of the conversion output" (parameter ~autocomplete:(fun _ -> return ["michelson"; "json"; "binary"; "ocaml"]) (fun _ s -> match String.lowercase_ascii s with | "michelson" -> return `Michelson | "json" -> return `JSON | "binary" -> return `Binary | "ocaml" -> return `OCaml | _ -> failwith "invalid output format, expecting one of \"michelson\", \ \"json\", \"binary\" or \"ocaml\".")) in let file_or_literal_param = param ~name:"source" ~desc:"literal or a path to a file" (parameter (fun cctxt s -> cctxt#read_file s >>= function | Ok v -> return v | Error _ -> return s)) in [ command ~group ~desc:"Lists all scripts in the library." no_options (fixed ["list"; "known"; "scripts"]) (fun () (cctxt : Protocol_client_context.full) -> Program.load cctxt >>=? fun list -> 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) (fun force name hash cctxt -> Program.of_fresh cctxt force name >>=? fun name -> Program.add ~force cctxt name hash); command ~group ~desc:"Remove a script from the library." no_options (prefixes ["forget"; "script"] @@ Program.alias_param @@ stop) (fun () (name, _) cctxt -> Program.del cctxt name); 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_source program >>=? fun source -> cctxt#message "%s\n" source >>= fun () -> return_unit); command ~group ~desc:"Ask the node to run a script." (args7 trace_stack_switch amount_arg source_arg payer_arg no_print_source_flag custom_gas_flag entrypoint_arg) (prefixes ["run"; "script"] @@ Program.source_param @@ prefixes ["on"; "storage"] @@ param ~name:"storage" ~desc:"the storage data" data_parameter @@ prefixes ["and"; "input"] @@ param ~name:"input" ~desc:"the input data" data_parameter @@ stop) (fun (trace_exec, amount, source, payer, no_print_source, gas, entrypoint) program storage input cctxt -> let source = Option.map snd source in let payer = Option.map snd payer in Lwt.return @@ Micheline_parser.no_parsing_error program >>=? fun program -> let show_source = not no_print_source in if trace_exec then trace cctxt ~chain:cctxt#chain ~block:cctxt#block ~amount ~program ~storage ~input ?source ?payer ?gas ?entrypoint () >>= fun res -> print_trace_result cctxt ~show_source ~parsed:program res else run cctxt ~chain:cctxt#chain ~block:cctxt#block ~amount ~program ~storage ~input ?source ?payer ?gas ?entrypoint () >>= fun res -> print_run_result cctxt ~show_source ~parsed:program res); command ~group ~desc:"Ask the node to typecheck a script." (args4 show_types_switch emacs_mode_switch no_print_source_flag custom_gas_flag) (prefixes ["typecheck"; "script"] @@ Program.source_param @@ stop) (fun (show_types, emacs_mode, no_print_source, original_gas) program cctxt -> match program with | program, [] -> resolve_max_gas cctxt cctxt#block original_gas >>=? fun original_gas -> typecheck_program cctxt ~chain:cctxt#chain ~block:cctxt#block ~gas:original_gas program >>= fun res -> print_typecheck_result ~emacs:emacs_mode ~show_types ~print_source_on_error:(not no_print_source) program res cctxt | res_with_errors when emacs_mode -> cctxt#message "(@[<v 0>(types . ())@ (errors . %a)@])" Michelson_v1_emacs.report_errors res_with_errors >>= fun () -> return_unit | parsed, errors -> cctxt#message "%a" (fun ppf () -> Michelson_v1_error_reporter.report_errors ~details:(not no_print_source) ~parsed ~show_source:(not no_print_source) ppf errors) () >>= fun () -> cctxt#error "syntax error in program"); command ~group ~desc:"Ask the node to typecheck a data expression." (args2 no_print_source_flag custom_gas_flag) (prefixes ["typecheck"; "data"] @@ param ~name:"data" ~desc:"the data to typecheck" data_parameter @@ prefixes ["against"; "type"] @@ param ~name:"type" ~desc:"the expected type" data_parameter @@ stop) (fun (no_print_source, custom_gas) data ty cctxt -> resolve_max_gas cctxt cctxt#block custom_gas >>=? fun original_gas -> Client_proto_programs.typecheck_data cctxt ~chain:cctxt#chain ~block:cctxt#block ~gas:original_gas ~data ~ty () >>= function | Ok gas -> cctxt#message "@[<v 0>Well typed@,Gas remaining: %a@]" Alpha_context.Gas.pp gas >>= fun () -> return_unit | Error errs -> cctxt#warning "%a" (Michelson_v1_error_reporter.report_errors ~details:false ~show_source:(not no_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." (args1 custom_gas_flag) (prefixes ["hash"; "data"] @@ param ~name:"data" ~desc:"the data to hash" data_parameter @@ prefixes ["of"; "type"] @@ param ~name:"type" ~desc:"type of the data" data_parameter @@ stop) (fun custom_gas data typ cctxt -> resolve_max_gas cctxt cctxt#block custom_gas >>=? fun original_gas -> Alpha_services.Helpers.Scripts.pack_data cctxt (cctxt#chain, cctxt#block) (data.expanded, typ.expanded, Some original_gas) >>= function | Ok (bytes, remaining_gas) -> let hash = Script_expr_hash.hash_bytes [bytes] in cctxt#message "Raw packed data: 0x%a@,\ Script-expression-ID-Hash: %a@,\ Raw Script-expression-ID-Hash: 0x%a@,\ Ledger Blake2b hash: %s@,\ Raw Sha256 hash: 0x%a@,\ Raw Sha512 hash: 0x%a@,\ Gas remaining: %a" Hex.pp (Hex.of_bytes bytes) Script_expr_hash.pp hash Hex.pp (Hex.of_bytes (Script_expr_hash.to_bytes hash)) (Tezos_crypto.Base58.raw_encode Tezos_crypto.Blake2B.(hash_bytes [bytes] |> to_string)) Hex.pp (Hex.of_bytes (Environment.Raw_hashes.sha256 bytes)) Hex.pp (Hex.of_bytes (Environment.Raw_hashes.sha512 bytes)) Alpha_context.Gas.pp remaining_gas >>= fun () -> return_unit | Error errs -> 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: "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 () bytes cctxt -> (if Bytes.get bytes 0 != '\005' then failwith "Not a piece of packed Michelson data (must start with `0x05`)" else return_unit) >>=? fun () -> (* Remove first byte *) let bytes = Bytes.sub bytes 1 (Bytes.length bytes - 1) in match Data_encoding.Binary.of_bytes_opt Alpha_context.Script.expr_encoding bytes with | None -> failwith "Could not decode bytes" | Some expr -> cctxt#message "%a" Michelson_v1_printer.print_expr_unwrapped expr >>= fun () -> return_unit); 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 () bytes sk cctxt -> Client_keys_v0.sign cctxt sk bytes >>=? fun signature -> cctxt#message "Signature: %a" Tezos_crypto.Signature.V0.pp signature >>= 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) (fun quiet bytes (_, (key_locator, _)) signature (cctxt : #Protocol_client_context.full) -> Client_keys_v0.check key_locator signature bytes >>=? function | false -> cctxt#error "invalid signature" | true -> if quiet then return_unit else cctxt#message "Signature check successful." >>= fun () -> return_unit); command ~group ~desc:"Ask the type of an entrypoint of a script." (args2 emacs_mode_switch no_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) entrypoint program cctxt -> match program with | program, [] -> entrypoint_type cctxt ~chain:cctxt#chain ~block:cctxt#block program ~entrypoint >>= fun entrypoint_type -> print_entrypoint_type ~emacs:emacs_mode ~show_source:(not no_print_source) ~parsed:program ~entrypoint cctxt entrypoint_type | res_with_errors when emacs_mode -> cctxt#message "(@[<v 0>(entrypoint . ())@ (errors . %a)@])" Michelson_v1_emacs.report_errors res_with_errors >>= fun () -> return_unit | parsed, errors -> cctxt#message "%a" (fun ppf () -> Michelson_v1_error_reporter.report_errors ~details:(not no_print_source) ~parsed ~show_source:(not no_print_source) ppf errors) () >>= fun () -> cctxt#error "syntax error in program"); command ~group ~desc:"Ask the node to list the entrypoints of a script." (args2 emacs_mode_switch no_print_source_flag) (prefixes ["get"; "script"; "entrypoints"; "for"] @@ Program.source_param @@ stop) (fun (emacs_mode, no_print_source) program cctxt -> match program with | program, [] -> list_entrypoints cctxt ~chain:cctxt#chain ~block:cctxt#block program >>= fun entrypoints -> print_entrypoints_list ~emacs:emacs_mode ~show_source:(not no_print_source) ~parsed:program cctxt entrypoints | res_with_errors when emacs_mode -> cctxt#message "(@[<v 0>(entrypoints . ())@ (errors . %a)@])" Michelson_v1_emacs.report_errors res_with_errors >>= fun () -> return_unit | parsed, errors -> cctxt#message "%a" (fun ppf () -> Michelson_v1_error_reporter.report_errors ~details:(not no_print_source) ~parsed ~show_source:(not no_print_source) ppf errors) () >>= fun () -> cctxt#error "syntax error in program"); command ~group ~desc: "Ask the node to list the unreachable paths in a script's parameter \ type." (args2 emacs_mode_switch no_print_source_flag) (prefixes ["get"; "script"; "unreachable"; "paths"; "for"] @@ Program.source_param @@ stop) (fun (emacs_mode, no_print_source) program cctxt -> match program with | program, [] -> list_unreachables cctxt ~chain:cctxt#chain ~block:cctxt#block program >>= fun entrypoints -> print_unreachables ~emacs:emacs_mode ~show_source:(not no_print_source) ~parsed:program cctxt entrypoints | res_with_errors when emacs_mode -> cctxt#message "(@[<v 0>(entrypoints . ())@ (errors . %a)@])" Michelson_v1_emacs.report_errors res_with_errors >>= fun () -> return_unit | parsed, errors -> cctxt#message "%a" (fun ppf () -> Michelson_v1_error_reporter.report_errors ~details:(not no_print_source) ~parsed ~show_source:(not no_print_source) ppf errors) () >>= fun () -> cctxt#error "syntax error in program"); command ~group ~desc:"Ask the node to expand the Michelson macros in a script." no_options (prefixes ["expand"; "macros"; "in"] @@ Program.source_param @@ stop) (fun () program (cctxt : Protocol_client_context.full) -> Lwt.return @@ Micheline_parser.no_parsing_error program >>=? fun program -> cctxt#message "%a" (fun ppf () : unit -> Michelson_v1_printer.print_expr_unwrapped ppf program.expanded) () >>= fun () -> return_unit); command ~desc: "Conversion of Michelson script from Micheline, JSON or binary to \ Micheline, JSON, binary or OCaml" (args1 zero_loc_switch) (prefixes ["convert"; "script"] @@ file_or_literal_param @@ prefix "from" @@ convert_input_format_param @@ prefix "to" @@ convert_output_format_param @@ stop) (fun zero_loc expr_string from_format to_format (cctxt : Protocol_client_context.full) -> (match from_format with | `Michelson -> let program = Michelson_v1_parser.parse_toplevel expr_string in Lwt.return @@ Micheline_parser.no_parsing_error program >>=? fun program -> (typecheck_program cctxt ~chain:cctxt#chain ~block:cctxt#block program >>= function | Error _ as res -> print_typecheck_result ~emacs:false ~show_types:true ~print_source_on_error:true program res cctxt | Ok _ -> return_unit) >>=? fun () -> return program.expanded | `JSON -> ( match Data_encoding.Json.from_string expr_string with | Error err -> cctxt#error "%s" err | Ok json -> safe_decode_json cctxt Alpha_context.Script.expr_encoding json) | `Binary -> ( bytes_of_prefixed_string expr_string >>=? fun bytes -> match Data_encoding.Binary.of_bytes_opt Alpha_context.Script.expr_encoding bytes with | None -> failwith "Could not decode bytes" | Some expr -> return expr)) >>=? fun (expression : Alpha_context.Script.expr) -> let output = match to_format with | `Michelson -> Micheline_printer.printable Michelson_v1_primitives.string_of_prim expression |> Format.asprintf "%a" Micheline_printer.print_expr | `JSON -> Data_encoding.Json.( construct Alpha_context.Script.expr_encoding expression |> to_string) | `Binary -> Format.asprintf "0x%s" (Data_encoding.Binary.( to_bytes_exn Alpha_context.Script.expr_encoding expression) |> Hex.of_bytes |> Hex.show) | `OCaml -> Michelson_v1_printer.micheline_string_of_expression ~zero_loc expression in cctxt#message "%s" output >>= fun () -> return_unit); command ~desc: "Conversion of Micheline expression from Micheline, JSON or binary to \ Micheline, JSON, binary or OCaml" (args2 zero_loc_switch data_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_string from_format to_format (cctxt : Protocol_client_context.full) -> let micheline_of_expr expr = Micheline_printer.printable Michelson_v1_primitives.string_of_prim expr |> Format.asprintf "%a" Micheline_printer.print_expr in let typecheck_parsed ~data ~ty = Client_proto_programs.typecheck_data cctxt ~chain:cctxt#chain ~block:cctxt#block ~data ~ty () >>= function | Error errs -> failwith "%a" (Michelson_v1_error_reporter.report_errors ~details:false ~show_source:false ?parsed:None) errs | Ok _gas -> return data.expanded in let typecheck_expr ~expr ~ty = let data_string = micheline_of_expr expr in parse_expr data_string >>=? fun data -> typecheck_parsed ~data ~ty in (match from_format with | `Michelson -> ( parse_expr data_string >>=? fun data -> match data_ty with | Some ty -> typecheck_parsed ~data ~ty | None -> return data.expanded) | `JSON -> ( match Data_encoding.Json.from_string data_string with | Error err -> cctxt#error "%s" err | Ok json -> ( safe_decode_json cctxt Alpha_context.Script.expr_encoding json >>=? fun expr -> match data_ty with | None -> return expr | Some ty -> typecheck_expr ~expr ~ty)) | `Binary -> ( bytes_of_prefixed_string data_string >>=? fun bytes -> match Data_encoding.Binary.of_bytes_opt Alpha_context.Script.expr_encoding bytes with | None -> failwith "Could not decode bytes" | Some expr -> ( match data_ty with | None -> return expr | Some ty -> typecheck_expr ~expr ~ty))) >>=? fun (expression : Alpha_context.Script.expr) -> let output = match to_format with | `Michelson -> micheline_of_expr expression | `JSON -> Data_encoding.Json.( construct Alpha_context.Script.expr_encoding expression |> to_string) | `Binary -> Format.asprintf "0x%s" (Data_encoding.Binary.( to_bytes_exn Alpha_context.Script.expr_encoding expression) |> Hex.of_bytes |> Hex.show) | `OCaml -> Michelson_v1_printer.micheline_string_of_expression ~zero_loc expression in cctxt#message "%s" output >>= fun () -> return_unit); ]
sectionYPositions = computeSectionYPositions($el), 10)"
x-init="setTimeout(() => sectionYPositions = computeSectionYPositions($el), 10)"
>