package tezos-client-011-PtHangz2
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-011-PtHangz2.commands/client_proto_context_commands.ml.html
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 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 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805
(*****************************************************************************) (* *) (* 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 open Alpha_context open Tezos_micheline open Client_proto_context open Client_proto_contracts open Client_proto_programs open Client_keys_v0 open Client_proto_args let encrypted_switch = Tezos_clic.switch ~long:"encrypted" ~doc:"encrypt the key on-disk" () let dry_run_switch = Tezos_clic.switch ~long:"dry-run" ~short:'D' ~doc:"don't inject the operation, just display it" () let verbose_signing_switch = Tezos_clic.switch ~long:"verbose-signing" ~doc:"display extra information before signing the operation" () let simulate_switch = Tezos_clic.switch ~long:"simulation" ~doc: "Simulate the execution of the command, without needing any signatures." () let force_switch = Tezos_clic.switch ~long:"force" ~doc: "Inject the operation even if the simulation results in a failure. This \ switch requires --gas-limit, --storage-limit, and --fee." () 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 json_file_or_text_parameter = Tezos_clic.parameter (fun _ p -> match String.split ~limit:1 ':' p with | ["text"; text] -> return (Ezjsonm.from_string text) | ["file"; path] -> Lwt_utils_unix.Json.read_file path | _ -> ( if Sys.file_exists p then Lwt_utils_unix.Json.read_file p else try return (Ezjsonm.from_string p) with Ezjsonm.Parse_error _ -> failwith "Neither an existing file nor valid JSON: '%s'" p)) let non_negative_param = Tezos_clic.parameter (fun _ s -> match int_of_string_opt s with | Some i when i >= 0 -> return i | _ -> failwith "Parameter should be a non-negative integer literal") let block_hash_param = Tezos_clic.parameter (fun _ s -> try return (Block_hash.of_b58check_exn s) with _ -> failwith "Parameter '%s' is an invalid block hash" s) 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 transfer_command amount source destination (cctxt : #Client_context.printer) ( fee, dry_run, verbose_signing, simulation, force, gas_limit, storage_limit, counter, arg, no_print_source, minimal_fees, minimal_nanotez_per_byte, minimal_nanotez_per_gas_unit, force_low_fee, fee_cap, burn_cap, entrypoint ) = let fee_parameter = { Injection.minimal_fees; minimal_nanotez_per_byte; minimal_nanotez_per_gas_unit; force_low_fee; fee_cap; burn_cap; } in (* When --force is used we want to inject the transfer even if it fails. In that case we cannot rely on simulation to compute limits and fees so we require the corresponding options to be set. *) let check_force_dependency name = function | None -> cctxt#error "When the --force switch is used, the %s option is required." name | _ -> Lwt.return_unit in (if force then check_force_dependency "--gas-limit" gas_limit >>= fun () -> check_force_dependency "--storage-limit" storage_limit >>= fun () -> check_force_dependency "--fee" fee else Lwt.return_unit) >>= fun () -> (match Contract.is_implicit source with | None -> let contract = source in Managed_contract.get_contract_manager cctxt source >>=? fun source -> Client_keys_v0.get_key cctxt source >>=? fun (_, src_pk, src_sk) -> Managed_contract.transfer cctxt ~chain:cctxt#chain ~block:cctxt#block ?confirmations:cctxt#confirmations ~dry_run ~verbose_signing ~simulation ~force ~fee_parameter ?fee ~contract ~source ~src_pk ~src_sk ~destination ?entrypoint ?arg ~amount ?gas_limit ?storage_limit ?counter () | Some source -> Client_keys_v0.get_key cctxt source >>=? fun (_, src_pk, src_sk) -> transfer cctxt ~chain:cctxt#chain ~block:cctxt#block ?confirmations:cctxt#confirmations ~dry_run ~simulation ~force ~verbose_signing ~fee_parameter ~source ?fee ~src_pk ~src_sk ~destination ?entrypoint ?arg ~amount ?gas_limit ?storage_limit ?counter ()) >>= report_michelson_errors ~no_print_source ~msg:"transfer simulation failed" cctxt >>= function | None -> return_unit | Some (_res, _contracts) -> return_unit let tez_of_string_exn index field s = match Tez.of_string s with | Some t -> return t | None -> failwith "Invalid \xEA\x9C\xA9 notation at entry %i, field \"%s\": %s" index field s let tez_of_opt_string_exn index field s = match s with | None -> return None | Some s -> tez_of_string_exn index field s >>=? fun s -> return (Some s) let prepare_batch_operation cctxt ?arg ?fee ?gas_limit ?storage_limit ?entrypoint source index batch = Client_proto_contracts.ContractAlias.find_destination cctxt batch.destination >>=? fun (_, destination) -> tez_of_string_exn index "amount" batch.amount >>=? fun amount -> tez_of_opt_string_exn index "fee" batch.fee >>=? fun batch_fee -> let fee = Option.either batch_fee fee in let arg = Option.either batch.arg arg in let gas_limit = Option.either batch.gas_limit gas_limit in let storage_limit = Option.either batch.storage_limit storage_limit in let entrypoint = Option.either batch.entrypoint entrypoint in parse_arg_transfer arg >>=? fun parameters -> (match Contract.is_implicit source with | None -> Managed_contract.build_transaction_operation cctxt ~chain:cctxt#chain ~block:cctxt#block ~contract:source ~destination ?entrypoint ?arg ~amount ?fee ?gas_limit ?storage_limit () | Some _ -> return (build_transaction_operation ~amount ~parameters ?entrypoint ?fee ?gas_limit ?storage_limit destination)) >>=? fun operation -> return (Annotated_manager_operation.Annotated_manager_operation operation) let commands network () = 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 : Protocol_client_context.full) -> Shell_services.Blocks.Header.shell_header cctxt ~chain:cctxt#chain ~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 : Protocol_client_context.full) -> list_contract_labels cctxt ~chain:cctxt#chain ~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:"Lists cached contracts and their age in LRU ordering." no_options (prefixes ["list"; "cached"; "contracts"] @@ stop) (fun () (cctxt : Protocol_client_context.full) -> cached_contracts cctxt ~chain:cctxt#chain ~block:cctxt#block >>=? fun keys -> List.iter_s (fun (key, size) -> cctxt#message "%a %d" Alpha_context.Contract.pp key size) keys >>= fun () -> return_unit); command ~group ~desc:"Get the key rank of a cache key." no_options (prefixes ["get"; "cached"; "contract"; "rank"; "for"] @@ ContractAlias.destination_param ~name:"src" ~desc:"contract" @@ stop) (fun () (_, contract) (cctxt : Protocol_client_context.full) -> contract_rank cctxt ~chain:cctxt#chain ~block:cctxt#block contract >>=? fun rank -> match rank with | None -> cctxt#error "Invalid contract: %a" Alpha_context.Contract.pp contract >>= fun () -> return_unit | Some rank -> cctxt#message "%d" rank >>= fun () -> return_unit); command ~group ~desc:"Get cache contract size." no_options (prefixes ["get"; "cache"; "contract"; "size"] @@ stop) (fun () (cctxt : Protocol_client_context.full) -> contract_cache_size cctxt ~chain:cctxt#chain ~block:cctxt#block >>=? fun t -> cctxt#message "%d" t >>= fun () -> return_unit); command ~group ~desc:"Get cache contract size limit." no_options (prefixes ["get"; "cache"; "contract"; "size"; "limit"] @@ stop) (fun () (cctxt : Protocol_client_context.full) -> contract_cache_size_limit cctxt ~chain:cctxt#chain ~block:cctxt#block >>=? fun t -> cctxt#message "%d" t >>= 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 : Protocol_client_context.full) -> get_balance cctxt ~chain:cctxt#chain ~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." (args1 (unparsing_mode_arg ~default:"Readable")) (prefixes ["get"; "contract"; "storage"; "for"] @@ ContractAlias.destination_param ~name:"src" ~desc:"source contract" @@ stop) (fun unparsing_mode (_, contract) (cctxt : Protocol_client_context.full) -> get_storage cctxt ~chain:cctxt#chain ~block:cctxt#block ~unparsing_mode 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 value associated to a key in the big map storage of a \ contract (deprecated)." no_options (prefixes ["get"; "big"; "map"; "value"; "for"] @@ Tezos_clic.param ~name:"key" ~desc:"the key to look for" data_parameter @@ prefixes ["of"; "type"] @@ Tezos_clic.param ~name:"type" ~desc:"type of the key" data_parameter @@ prefix "in" @@ ContractAlias.destination_param ~name:"src" ~desc:"source contract" @@ stop) (fun () key key_type (_, contract) (cctxt : Protocol_client_context.full) -> get_contract_big_map_value cctxt ~chain:cctxt#chain ~block:cctxt#block contract (key.expanded, key_type.expanded) >>=? function | None -> cctxt#error "No value associated to this key." | Some value -> cctxt#answer "%a" Michelson_v1_printer.print_expr_unwrapped value >>= fun () -> return_unit); command ~group ~desc:"Get a value in a big map." (args1 (unparsing_mode_arg ~default:"Readable")) (prefixes ["get"; "element"] @@ Tezos_clic.param ~name:"key" ~desc:"the key to look for" (Tezos_clic.parameter (fun _ s -> return (Script_expr_hash.of_b58check_exn s))) @@ prefixes ["of"; "big"; "map"] @@ Tezos_clic.param ~name:"big_map" ~desc:"identifier of the big_map" int_parameter @@ stop) (fun unparsing_mode key id (cctxt : Protocol_client_context.full) -> get_big_map_value cctxt ~chain:cctxt#chain ~block:cctxt#block ~unparsing_mode (Big_map.Id.parse_z (Z.of_int id)) key >>=? fun value -> cctxt#answer "%a" Michelson_v1_printer.print_expr_unwrapped value >>= fun () -> return_unit); command ~group ~desc:"Get the code of a contract." (args1 (unparsing_mode_arg ~default:"Readable")) (prefixes ["get"; "contract"; "code"; "for"] @@ ContractAlias.destination_param ~name:"src" ~desc:"source contract" @@ stop) (fun unparsing_mode (_, contract) (cctxt : Protocol_client_context.full) -> get_script cctxt ~chain:cctxt#chain ~block:cctxt#block ~unparsing_mode 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" Environment.Error_monad.pp_trace errs | Ok code -> let {Michelson_v1_parser.source; _} = Michelson_v1_printer.unparse_toplevel code in cctxt#answer "%s" source >>= return)); command ~group ~desc:"Get the `BLAKE2B` script hash of a contract." no_options (prefixes ["get"; "contract"; "script"; "hash"; "for"] @@ ContractAlias.destination_param ~name:"src" ~desc:"source contract" @@ stop) (fun () (_, contract) (cctxt : Protocol_client_context.full) -> get_script_hash cctxt ~chain:cctxt#chain ~block:cctxt#block contract >>= function | Error trace -> cctxt#error "%a" pp_print_trace trace | Ok None -> cctxt#error "This is not a smart contract." | Ok (Some hash) -> cctxt#answer "%a" Script_expr_hash.pp hash >|= ok); command ~group ~desc:"Get the type of an entrypoint of a contract." no_options (prefixes ["get"; "contract"; "entrypoint"; "type"; "of"] @@ Tezos_clic.string ~name:"entrypoint" ~desc:"the entrypoint to describe" @@ prefixes ["for"] @@ ContractAlias.destination_param ~name:"src" ~desc:"source contract" @@ stop) (fun () entrypoint (_, contract) (cctxt : Protocol_client_context.full) -> Michelson_v1_entrypoints.contract_entrypoint_type cctxt ~chain:cctxt#chain ~block:cctxt#block ~contract ~entrypoint >>= Michelson_v1_entrypoints.print_entrypoint_type cctxt ~emacs:false ~contract ~entrypoint); command ~group ~desc:"Get the entrypoint list of a contract." no_options (prefixes ["get"; "contract"; "entrypoints"; "for"] @@ ContractAlias.destination_param ~name:"src" ~desc:"source contract" @@ stop) (fun () (_, contract) (cctxt : Protocol_client_context.full) -> Michelson_v1_entrypoints.list_contract_entrypoints cctxt ~chain:cctxt#chain ~block:cctxt#block ~contract >>= Michelson_v1_entrypoints.print_entrypoints_list cctxt ~emacs:false ~contract); command ~group ~desc:"Get the list of unreachable paths in a contract's parameter type." no_options (prefixes ["get"; "contract"; "unreachable"; "paths"; "for"] @@ ContractAlias.destination_param ~name:"src" ~desc:"source contract" @@ stop) (fun () (_, contract) (cctxt : Protocol_client_context.full) -> Michelson_v1_entrypoints.list_contract_unreachables cctxt ~chain:cctxt#chain ~block:cctxt#block ~contract >>= Michelson_v1_entrypoints.print_unreachables cctxt ~emacs:false ~contract); 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 : Protocol_client_context.full) -> Client_proto_contracts.get_delegate cctxt ~chain:cctxt#chain ~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 ~desc:"Set the delegate of a contract." (args10 fee_arg dry_run_switch verbose_signing_switch simulate_switch minimal_fees_arg minimal_nanotez_per_byte_arg minimal_nanotez_per_gas_unit_arg force_low_fee_arg fee_cap_arg burn_cap_arg) (prefixes ["set"; "delegate"; "for"] @@ ContractAlias.destination_param ~name:"src" ~desc:"source contract" @@ prefix "to" @@ Public_key_hash.source_param ~name:"dlgt" ~desc:"new delegate of the contract" @@ stop) (fun ( fee, dry_run, verbose_signing, simulation, minimal_fees, minimal_nanotez_per_byte, minimal_nanotez_per_gas_unit, force_low_fee, fee_cap, burn_cap ) (_, contract) delegate (cctxt : Protocol_client_context.full) -> let fee_parameter = { Injection.minimal_fees; minimal_nanotez_per_byte; minimal_nanotez_per_gas_unit; force_low_fee; fee_cap; burn_cap; } in match Contract.is_implicit contract with | None -> Managed_contract.get_contract_manager cctxt contract >>=? fun source -> Client_keys_v0.get_key cctxt source >>=? fun (_, src_pk, src_sk) -> Managed_contract.set_delegate cctxt ~chain:cctxt#chain ~block:cctxt#block ?confirmations:cctxt#confirmations ~dry_run ~verbose_signing ~simulation ~fee_parameter ?fee ~source ~src_pk ~src_sk contract (Some delegate) >>= fun errors -> report_michelson_errors ~no_print_source:true ~msg:"Setting delegate through entrypoints failed." cctxt errors >>= fun _ -> return_unit | Some mgr -> Client_keys_v0.get_key cctxt mgr >>=? fun (_, src_pk, manager_sk) -> set_delegate cctxt ~chain:cctxt#chain ~block:cctxt#block ?confirmations:cctxt#confirmations ~dry_run ~verbose_signing ~simulation ~fee_parameter ?fee mgr (Some delegate) ~src_pk ~manager_sk >>=? fun _ -> return_unit); command ~group ~desc:"Withdraw the delegate from a contract." (args9 fee_arg dry_run_switch verbose_signing_switch minimal_fees_arg minimal_nanotez_per_byte_arg minimal_nanotez_per_gas_unit_arg force_low_fee_arg fee_cap_arg burn_cap_arg) (prefixes ["withdraw"; "delegate"; "from"] @@ ContractAlias.destination_param ~name:"src" ~desc:"source contract" @@ stop) (fun ( fee, dry_run, verbose_signing, minimal_fees, minimal_nanotez_per_byte, minimal_nanotez_per_gas_unit, force_low_fee, fee_cap, burn_cap ) (_, contract) (cctxt : Protocol_client_context.full) -> let fee_parameter = { Injection.minimal_fees; minimal_nanotez_per_byte; minimal_nanotez_per_gas_unit; force_low_fee; fee_cap; burn_cap; } in match Contract.is_implicit contract with | None -> Managed_contract.get_contract_manager cctxt contract >>=? fun source -> Client_keys_v0.get_key cctxt source >>=? fun (_, src_pk, src_sk) -> Managed_contract.set_delegate cctxt ~chain:cctxt#chain ~block:cctxt#block ?confirmations:cctxt#confirmations ~dry_run ~verbose_signing ~fee_parameter ?fee ~source ~src_pk ~src_sk contract None >>= fun errors -> report_michelson_errors ~no_print_source:true ~msg:"Withdrawing delegate through entrypoints failed." cctxt errors >>= fun _ -> return_unit | Some mgr -> Client_keys_v0.get_key cctxt mgr >>=? fun (_, src_pk, manager_sk) -> set_delegate cctxt ~chain:cctxt#chain ~block:cctxt#block ?confirmations:cctxt#confirmations ~dry_run ~verbose_signing ~fee_parameter mgr None ?fee ~src_pk ~manager_sk >>= fun _ -> return_unit); command ~group ~desc:"Launch a smart contract on the blockchain." (args15 fee_arg dry_run_switch verbose_signing_switch gas_limit_arg storage_limit_arg delegate_arg (Client_keys_v0.force_switch ()) init_arg no_print_source_flag minimal_fees_arg minimal_nanotez_per_byte_arg minimal_nanotez_per_gas_unit_arg force_low_fee_arg fee_cap_arg burn_cap_arg) (prefixes ["originate"; "contract"] @@ RawContractAlias.fresh_alias_param ~name:"new" ~desc:"name of the new contract" @@ prefix "transferring" @@ tez_param ~name:"qty" ~desc:"amount taken from source" @@ prefix "from" @@ ContractAlias.destination_param ~name:"src" ~desc:"name of the source contract" @@ prefix "running" @@ Program.source_param ~name:"prg" ~desc: "script of the account\n\ Combine with -init if the storage type is not unit." @@ stop) (fun ( fee, dry_run, verbose_signing, gas_limit, storage_limit, delegate, force, initial_storage, no_print_source, minimal_fees, minimal_nanotez_per_byte, minimal_nanotez_per_gas_unit, force_low_fee, fee_cap, burn_cap ) alias_name balance (_, source) program (cctxt : Protocol_client_context.full) -> RawContractAlias.of_fresh cctxt force alias_name >>=? fun alias_name -> Lwt.return (Micheline_parser.no_parsing_error program) >>=? fun {expanded = code; _} -> match Contract.is_implicit source with | None -> failwith "only implicit accounts can be the source of an origination" | Some source -> ( Client_keys_v0.get_key cctxt source >>=? fun (_, src_pk, src_sk) -> let fee_parameter = { Injection.minimal_fees; minimal_nanotez_per_byte; minimal_nanotez_per_gas_unit; force_low_fee; fee_cap; burn_cap; } in originate_contract cctxt ~chain:cctxt#chain ~block:cctxt#block ?confirmations:cctxt#confirmations ~dry_run ~verbose_signing ?fee ?gas_limit ?storage_limit ~delegate ~initial_storage ~balance ~source ~src_pk ~src_sk ~code ~fee_parameter () >>= fun errors -> report_michelson_errors ~no_print_source ~msg:"origination simulation failed" cctxt errors >>= function | None -> return_unit | Some (_res, contract) -> if dry_run then return_unit else save_contract ~force cctxt alias_name contract >>=? fun () -> return_unit)); command ~group ~desc: "Execute multiple transfers from a single source account.\n\ If one of the transfers fails, none of them get executed." (args16 default_fee_arg dry_run_switch verbose_signing_switch simulate_switch default_gas_limit_arg default_storage_limit_arg counter_arg default_arg_arg no_print_source_flag minimal_fees_arg minimal_nanotez_per_byte_arg minimal_nanotez_per_gas_unit_arg force_low_fee_arg fee_cap_arg burn_cap_arg default_entrypoint_arg) (prefixes ["multiple"; "transfers"; "from"] @@ ContractAlias.destination_param ~name:"src" ~desc:"name of the source contract" @@ prefix "using" @@ param ~name:"transfers.json" ~desc: "List of operations originating from the source contract in JSON \ format (from a file or directly inlined). The input JSON must be \ an array of objects of the form: '[ {\"destination\": dst, \ \"amount\": qty (, <field>: <val> ...) } (, ...) ]', where an \ optional <field> can either be \"fee\", \"gas-limit\", \ \"storage-limit\", \"arg\", or \"entrypoint\"." json_file_or_text_parameter @@ stop) (fun ( fee, dry_run, verbose_signing, simulation, gas_limit, storage_limit, counter, arg, no_print_source, minimal_fees, minimal_nanotez_per_byte, minimal_nanotez_per_gas_unit, force_low_fee, fee_cap, burn_cap, entrypoint ) (_, source) operations_json cctxt -> let fee_parameter = { Injection.minimal_fees; minimal_nanotez_per_byte; minimal_nanotez_per_gas_unit; force_low_fee; fee_cap; burn_cap; } in let prepare i = prepare_batch_operation cctxt ?arg ?fee ?gas_limit ?storage_limit ?entrypoint source i in match Data_encoding.Json.destruct (Data_encoding.list Client_proto_context.batch_transfer_operation_encoding) operations_json with | [] -> failwith "Empty operation list" | operations -> (match Contract.is_implicit source with | None -> Managed_contract.get_contract_manager cctxt source >>=? fun source -> Client_keys_v0.get_key cctxt source >>=? fun (_, src_pk, src_sk) -> return (source, src_pk, src_sk) | Some source -> Client_keys_v0.get_key cctxt source >>=? fun (_, src_pk, src_sk) -> return (source, src_pk, src_sk)) >>=? fun (source, src_pk, src_sk) -> List.mapi_ep prepare operations >>=? fun contents -> let (Manager_list contents) = Annotated_manager_operation.manager_of_list contents in Injection.inject_manager_operation cctxt ~chain:cctxt#chain ~block:cctxt#block ?confirmations:cctxt#confirmations ~dry_run ~verbose_signing ~simulation ~source ~fee:(Limit.of_option fee) ~gas_limit:(Limit.of_option gas_limit) ~storage_limit:(Limit.of_option storage_limit) ?counter ~src_pk ~src_sk ~fee_parameter contents >>= report_michelson_errors ~no_print_source ~msg:"multiple transfers simulation failed" cctxt >>= fun _ -> return_unit | exception (Data_encoding.Json.Cannot_destruct (path, exn2) as exn) -> ( match (path, operations_json) with | [`Index n], `A lj -> ( match List.nth_opt lj n with | Some j -> failwith "Invalid transfer at index %i: %a %a" n (fun ppf -> Data_encoding.Json.print_error ppf) exn2 Data_encoding.Json.pp j | _ -> failwith "Invalid transfer at index %i: %a" n (fun ppf -> Data_encoding.Json.print_error ppf) exn2) | _ -> failwith "Invalid transfer file: %a %a" (fun ppf -> Data_encoding.Json.print_error ppf) exn Data_encoding.Json.pp operations_json)); command ~group ~desc:"Transfer tokens / call a smart contract." (args17 fee_arg dry_run_switch verbose_signing_switch simulate_switch force_switch gas_limit_arg storage_limit_arg counter_arg arg_arg no_print_source_flag minimal_fees_arg minimal_nanotez_per_byte_arg minimal_nanotez_per_gas_unit_arg force_low_fee_arg fee_cap_arg burn_cap_arg entrypoint_arg) (prefixes ["transfer"] @@ tez_param ~name:"qty" ~desc:"amount taken from source" @@ prefix "from" @@ ContractAlias.destination_param ~name:"src" ~desc:"name of the source contract" @@ prefix "to" @@ ContractAlias.destination_param ~name:"dst" ~desc:"name/literal of the destination contract" @@ stop) (fun ( fee, dry_run, verbose_signing, simulation, force, gas_limit, storage_limit, counter, arg, no_print_source, minimal_fees, minimal_nanotez_per_byte, minimal_nanotez_per_gas_unit, force_low_fee, fee_cap, burn_cap, entrypoint ) amount (_, source) (_, destination) cctxt -> transfer_command amount source destination cctxt ( fee, dry_run, verbose_signing, simulation, force, gas_limit, storage_limit, counter, arg, no_print_source, minimal_fees, minimal_nanotez_per_byte, minimal_nanotez_per_gas_unit, force_low_fee, fee_cap, burn_cap, entrypoint )); command ~group ~desc:"Register a global constant" (args12 fee_arg dry_run_switch verbose_signing_switch simulate_switch minimal_fees_arg minimal_nanotez_per_byte_arg minimal_nanotez_per_gas_unit_arg storage_limit_arg counter_arg force_low_fee_arg fee_cap_arg burn_cap_arg) (prefixes ["register"; "global"; "constant"] @@ global_constant_param ~name:"expression" ~desc: "Michelson expression to register. Note the value is not \ typechecked before registration." @@ prefix "from" @@ ContractAlias.destination_param ~name:"src" ~desc:"name of the account registering the global constant" @@ stop) (fun ( fee, dry_run, verbose_signing, simulation, minimal_fees, minimal_nanotez_per_byte, minimal_nanotez_per_gas_unit, storage_limit, counter, force_low_fee, fee_cap, burn_cap ) global_constant_str (_, source) cctxt -> match Contract.is_implicit source with | None -> failwith "Only implicit accounts can register global constants" | Some source -> Client_keys_v0.get_key cctxt source >>=? fun (_, src_pk, src_sk) -> let fee_parameter = { Injection.minimal_fees; minimal_nanotez_per_byte; minimal_nanotez_per_gas_unit; force_low_fee; fee_cap; burn_cap; } in register_global_constant cctxt ~chain:cctxt#chain ~block:cctxt#block ?dry_run:(Some dry_run) ?verbose_signing:(Some verbose_signing) ?fee ?storage_limit ?counter ?confirmations:cctxt#confirmations ~simulation ~source ~src_pk ~src_sk ~fee_parameter ~constant:global_constant_str () >>= fun errors -> report_michelson_errors ~no_print_source:false ~msg:"register global constant simulation failed" cctxt errors >>= fun _ -> return_unit); command ~group ~desc:"Call a smart contract (same as 'transfer 0')." (args17 fee_arg dry_run_switch verbose_signing_switch simulate_switch force_switch gas_limit_arg storage_limit_arg counter_arg arg_arg no_print_source_flag minimal_fees_arg minimal_nanotez_per_byte_arg minimal_nanotez_per_gas_unit_arg force_low_fee_arg fee_cap_arg burn_cap_arg entrypoint_arg) (prefixes ["call"] @@ ContractAlias.destination_param ~name:"dst" ~desc:"name/literal of the destination contract" @@ prefix "from" @@ ContractAlias.destination_param ~name:"src" ~desc:"name of the source contract" @@ stop) (fun ( fee, dry_run, verbose_signing, simulation, force, gas_limit, storage_limit, counter, arg, no_print_source, minimal_fees, minimal_nanotez_per_byte, minimal_nanotez_per_gas_unit, force_low_fee, fee_cap, burn_cap, entrypoint ) (_, destination) (_, source) cctxt -> let amount = Tez.zero in transfer_command amount source destination cctxt ( fee, dry_run, verbose_signing, simulation, force, gas_limit, storage_limit, counter, arg, no_print_source, minimal_fees, minimal_nanotez_per_byte, minimal_nanotez_per_gas_unit, force_low_fee, fee_cap, burn_cap, entrypoint )); command ~group ~desc:"Reveal the public key of the contract manager." (args9 fee_arg dry_run_switch verbose_signing_switch minimal_fees_arg minimal_nanotez_per_byte_arg minimal_nanotez_per_gas_unit_arg force_low_fee_arg fee_cap_arg burn_cap_arg) (prefixes ["reveal"; "key"; "for"] @@ ContractAlias.alias_param ~name:"src" ~desc:"name of the source contract" @@ stop) (fun ( fee, dry_run, verbose_signing, minimal_fees, minimal_nanotez_per_byte, minimal_nanotez_per_gas_unit, force_low_fee, fee_cap, burn_cap ) (_, source) cctxt -> match Contract.is_implicit source with | None -> failwith "only implicit accounts can be revealed" | Some source -> Client_keys_v0.get_key cctxt source >>=? fun (_, src_pk, src_sk) -> let fee_parameter = { Injection.minimal_fees; minimal_nanotez_per_byte; minimal_nanotez_per_gas_unit; force_low_fee; fee_cap; burn_cap; } in reveal cctxt ~dry_run ~verbose_signing ~chain:cctxt#chain ~block:cctxt#block ?confirmations:cctxt#confirmations ~source ?fee ~src_pk ~src_sk ~fee_parameter () >>=? fun _res -> return_unit); command ~group ~desc:"Register the public key hash as a delegate." (args9 fee_arg dry_run_switch verbose_signing_switch minimal_fees_arg minimal_nanotez_per_byte_arg minimal_nanotez_per_gas_unit_arg force_low_fee_arg fee_cap_arg burn_cap_arg) (prefixes ["register"; "key"] @@ Public_key_hash.source_param ~name:"mgr" ~desc:"the delegate key" @@ prefixes ["as"; "delegate"] @@ stop) (fun ( fee, dry_run, verbose_signing, minimal_fees, minimal_nanotez_per_byte, minimal_nanotez_per_gas_unit, force_low_fee, fee_cap, burn_cap ) src_pkh cctxt -> Client_keys_v0.get_key cctxt src_pkh >>=? fun (_, src_pk, src_sk) -> let fee_parameter = { Injection.minimal_fees; minimal_nanotez_per_byte; minimal_nanotez_per_gas_unit; force_low_fee; fee_cap; burn_cap; } in register_as_delegate cctxt ~chain:cctxt#chain ~block:cctxt#block ?confirmations:cctxt#confirmations ~dry_run ~fee_parameter ~verbose_signing ?fee ~manager_sk:src_sk src_pk >>= function | Ok _ -> return_unit | Error [Environment.Ecoproto_error Delegate_storage.Active_delegate] -> cctxt#message "Delegate already activated." >>= fun () -> return_unit | Error el -> Lwt.return_error el); ] @ (match network with | Some `Mainnet -> [] | Some `Testnet | None -> [ command ~group ~desc:"Register and activate an Alphanet/Zeronet faucet account." (args2 (Secret_key.force_switch ()) encrypted_switch) (prefixes ["activate"; "account"] @@ Secret_key.fresh_alias_param @@ prefixes ["with"] @@ param ~name:"activation_key" ~desc: "Activate an Alphanet/Zeronet faucet account from the JSON \ (file or directly inlined)." json_file_or_text_parameter @@ stop) (fun (force, encrypted) name activation_json cctxt -> Secret_key.of_fresh cctxt force name >>=? fun name -> match Data_encoding.Json.destruct Client_proto_context.activation_key_encoding activation_json with | exception (Data_encoding.Json.Cannot_destruct _ as exn) -> Format.kasprintf (fun s -> failwith "%s" s) "Invalid activation file: %a %a" (fun ppf -> Data_encoding.Json.print_error ppf) exn Data_encoding.Json.pp activation_json | key -> activate_account cctxt ~chain:cctxt#chain ~block:cctxt#block ?confirmations:cctxt#confirmations ~encrypted ~force key name >>=? fun _res -> return_unit); ]) @ (match network with | Some `Testnet | None -> [] | Some `Mainnet -> [ command ~group ~desc:"Activate a fundraiser account." (args1 dry_run_switch) (prefixes ["activate"; "fundraiser"; "account"] @@ Public_key_hash.alias_param @@ prefixes ["with"] @@ param ~name:"code" (Tezos_clic.parameter (fun _ctx code -> protect (fun () -> return (Blinded_public_key_hash.activation_code_of_hex code)))) ~desc:"Activation code obtained from the Tezos foundation." @@ stop) (fun dry_run (name, _pkh) code cctxt -> activate_existing_account cctxt ~chain:cctxt#chain ~block:cctxt#block ?confirmations:cctxt#confirmations ~dry_run name code >>=? fun _res -> return_unit); ]) @ [ command ~desc:"Wait until an operation is included in a block" (args3 (default_arg ~long:"confirmations" ~placeholder:"num_blocks" ~doc: "wait until 'N' additional blocks after the operation appears \ in the considered chain" ~default:"0" non_negative_param) (default_arg ~long:"check-previous" ~placeholder:"num_blocks" ~doc:"number of previous blocks to check" ~default:"10" non_negative_param) (arg ~long:"branch" ~placeholder:"block_hash" ~doc: "hash of the oldest block where we should look for the \ operation" block_hash_param)) (prefixes ["wait"; "for"] @@ param ~name:"operation" ~desc:"Operation to be included" (parameter (fun _ x -> match Operation_hash.of_b58check_opt x with | None -> Error_monad.failwith "Invalid operation hash: '%s'" x | Some hash -> return hash)) @@ prefixes ["to"; "be"; "included"] @@ stop) (fun (confirmations, predecessors, branch) operation_hash (ctxt : Protocol_client_context.full) -> Client_confirmations.wait_for_operation_inclusion ctxt ~chain:ctxt#chain ~confirmations ~predecessors ?branch operation_hash >>=? fun _ -> return_unit); command ~desc:"Get receipt for past operation" (args1 (default_arg ~long:"check-previous" ~placeholder:"num_blocks" ~doc:"number of previous blocks to check" ~default:"10" non_negative_param)) (prefixes ["get"; "receipt"; "for"] @@ param ~name:"operation" ~desc:"Operation to be looked up" (parameter (fun _ x -> match Operation_hash.of_b58check_opt x with | None -> Error_monad.failwith "Invalid operation hash: '%s'" x | Some hash -> return hash)) @@ stop) (fun predecessors operation_hash (ctxt : Protocol_client_context.full) -> display_receipt_for_operation ctxt ~chain:ctxt#chain ~predecessors operation_hash >>=? fun _ -> return_unit); command ~group:binary_description ~desc:"Describe unsigned block header" no_options (fixed ["describe"; "unsigned"; "block"; "header"]) (fun () (cctxt : Protocol_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 : Protocol_client_context.full) -> cctxt#message "%a" Data_encoding.Binary_schema.pp (Data_encoding.Binary.describe Alpha_context.Operation.unsigned_encoding) >>= fun () -> return_unit); command ~group ~desc:"Submit protocol proposals" (args3 dry_run_switch verbose_signing_switch (switch ~doc: "Do not fail when the checks that try to prevent the user from \ shooting themselves in the foot do." ~long:"force" ())) (prefixes ["submit"; "proposals"; "for"] @@ ContractAlias.destination_param ~name:"delegate" ~desc:"the delegate who makes the proposal" @@ seq_of_param (param ~name:"proposal" ~desc:"the protocol hash proposal to be submitted" (parameter (fun _ x -> match Protocol_hash.of_b58check_opt x with | None -> Error_monad.failwith "Invalid proposal hash: '%s'" x | Some hash -> return hash)))) (fun (dry_run, verbose_signing, force) (_name, source) proposals (cctxt : Protocol_client_context.full) -> match Contract.is_implicit source with | None -> failwith "only implicit accounts can submit proposals" | Some src_pkh -> ( Client_keys_v0.get_key cctxt src_pkh >>=? fun (src_name, _src_pk, src_sk) -> get_period_info (* Find period info of the successor, because the operation will be injected on the next block at the earliest *) ~successor:true ~chain:cctxt#chain ~block:cctxt#block cctxt >>=? fun info -> (match info.current_period_kind with | Proposal -> return_unit | _ -> cctxt#error "Not in a proposal period") >>=? fun () -> Shell_services.Protocol.list cctxt >>=? fun known_protos -> get_proposals ~chain:cctxt#chain ~block:cctxt#block cctxt >>=? fun known_proposals -> Alpha_services.Voting.listings cctxt (cctxt#chain, cctxt#block) >>=? fun listings -> (* for a proposal to be valid it must either a protocol that was already proposed by somebody else or a protocol known by the node, because the user is the first proposer and just injected it with tezos-admin-client *) let check_proposals proposals : bool tzresult Lwt.t = let n = List.length proposals in let errors = ref [] in let error ppf = Format.kasprintf (fun s -> errors := s :: !errors) ppf in if n = 0 then error "Empty proposal list." ; if n > Constants.max_proposals_per_delegate then error "Too many proposals: %d > %d." n Constants.max_proposals_per_delegate ; (match Base.List.find_all_dups ~compare:Protocol_hash.compare proposals with | [] -> () | dups -> error "There %s: %a." (if Compare.List_length_with.(dups = 1) then "is a duplicate proposal" else "are duplicate proposals") Format.( pp_print_list ~pp_sep:(fun ppf () -> pp_print_string ppf ", ") Protocol_hash.pp) dups) ; List.iter (fun (p : Protocol_hash.t) -> if List.mem ~equal:Protocol_hash.equal p known_protos || Environment.Protocol_hash.Map.mem p known_proposals then () else error "Protocol %a is not a known proposal." Protocol_hash.pp p) proposals ; if not (List.exists (fun (pkh, _) -> Tezos_crypto.Signature.V0.Public_key_hash.equal pkh src_pkh) listings) then error "Public-key-hash `%a` from account `%s` does not appear to \ have voting rights." Tezos_crypto.Signature.V0.Public_key_hash.pp src_pkh src_name ; if !errors <> [] then cctxt#message "There %s with the submission:%t" (if Compare.List_length_with.(!errors = 1) then "is an issue" else "are issues") Format.( fun ppf -> pp_print_cut ppf () ; pp_open_vbox ppf 0 ; List.iter (fun msg -> pp_open_hovbox ppf 2 ; pp_print_string ppf "* " ; pp_print_text ppf msg ; pp_close_box ppf () ; pp_print_cut ppf ()) !errors ; pp_close_box ppf ()) >>= fun () -> return_false else return_true in check_proposals proposals >>=? fun all_valid -> (if all_valid then cctxt#message "All proposals are valid." else if force then cctxt#message "Some proposals are not valid, but `--force` was used." else cctxt#error "Submission failed because of invalid proposals.") >>= fun () -> submit_proposals ~dry_run ~verbose_signing cctxt ~chain:cctxt#chain ~block:cctxt#block ~src_sk src_pkh proposals >>= function | Ok _res -> return_unit | Error errs -> (match errs with | [ Unregistered_error (`O [("kind", `String "generic"); ("error", `String msg)]); ] -> cctxt#message "Error:@[<hov>@.%a@]" Format.pp_print_text (String.split_on_char ' ' msg |> List.filter (function | "" | "\n" -> false | _ -> true) |> String.concat " " |> String.map (function '\n' | '\t' -> ' ' | c -> c)) | trace -> cctxt#message "Error:@ %a" pp_print_trace trace) >>= fun () -> failwith "Failed to submit proposals")); command ~group ~desc:"Submit a ballot" (args2 verbose_signing_switch dry_run_switch) (prefixes ["submit"; "ballot"; "for"] @@ ContractAlias.destination_param ~name:"delegate" ~desc:"the delegate who votes" @@ param ~name:"proposal" ~desc:"the protocol hash proposal to vote for" (parameter (fun _ x -> match Protocol_hash.of_b58check_opt x with | None -> failwith "Invalid proposal hash: '%s'" x | Some hash -> return hash)) @@ param ~name:"ballot" ~desc:"the ballot value (yea/yay, nay, or pass)" (parameter ~autocomplete:(fun _ -> return ["yea"; "nay"; "pass"]) (fun _ s -> (* We should have [Vote.of_string]. *) match String.lowercase_ascii s with | "yay" | "yea" -> return Vote.Yay | "nay" -> return Vote.Nay | "pass" -> return Vote.Pass | s -> failwith "Invalid ballot: '%s'" s)) @@ stop) (fun (verbose_signing, dry_run) (_name, source) proposal ballot (cctxt : Protocol_client_context.full) -> match Contract.is_implicit source with | None -> failwith "only implicit accounts can submit ballot" | Some src_pkh -> Client_keys_v0.get_key cctxt src_pkh >>=? fun (_src_name, _src_pk, src_sk) -> get_period_info (* Find period info of the successor, because the operation will be injected on the next block at the earliest *) ~successor:true ~chain:cctxt#chain ~block:cctxt#block cctxt >>=? fun info -> (match info.current_period_kind with | Exploration | Promotion -> return_unit | _ -> cctxt#error "Not in Exploration or Promotion period") >>=? fun () -> submit_ballot cctxt ~chain:cctxt#chain ~block:cctxt#block ~src_sk src_pkh ~verbose_signing ~dry_run proposal ballot >>=? fun _res -> return_unit); command ~group ~desc:"Summarize the current voting period" no_options (fixed ["show"; "voting"; "period"]) (fun () (cctxt : Protocol_client_context.full) -> get_period_info ~chain:cctxt#chain ~block:cctxt#block cctxt >>=? fun info -> cctxt#message "Current period: %a\nBlocks remaining until end of period: %ld" Data_encoding.Json.pp (Data_encoding.Json.construct Alpha_context.Voting_period.kind_encoding info.current_period_kind) info.remaining >>= fun () -> Shell_services.Protocol.list cctxt >>=? fun known_protos -> get_proposals ~chain:cctxt#chain ~block:cctxt#block cctxt >>=? fun props -> let ranks = Environment.Protocol_hash.Map.bindings props |> List.sort (fun (_, v1) (_, v2) -> Int32.(compare v2 v1)) in let print_proposal = function | None -> cctxt#message "The current proposal has already been cleared." (* The proposal is cleared on the last block of adoption period, and also on the last block of the exploration and promotion periods when the proposal is not approved *) | Some proposal -> cctxt#message "Current proposal: %a" Protocol_hash.pp proposal in match info.current_period_kind with | Proposal -> (* the current proposals are cleared on the last block of the proposal period *) if info.remaining <> 0l then cctxt#answer "Current proposals:%t" Format.( fun ppf -> pp_print_cut ppf () ; pp_open_vbox ppf 0 ; List.iter (fun (p, w) -> fprintf ppf "* %a %ld (%sknown by the node)@." Protocol_hash.pp p w (if List.mem ~equal:Protocol_hash.equal p known_protos then "" else "not ")) ranks ; pp_close_box ppf ()) >>= fun () -> return_unit else cctxt#message "The proposals have already been cleared." >>= fun () -> return_unit | Exploration | Promotion -> print_proposal info.current_proposal >>= fun () -> (* the ballots are cleared on the last block of these periods *) if info.remaining <> 0l then get_ballots_info ~chain:cctxt#chain ~block:cctxt#block cctxt >>=? fun ballots_info -> cctxt#answer "Ballots: %a@,\ Current participation %.2f%%, necessary quorum %.2f%%@,\ Current in favor %ld, needed supermajority %ld" Data_encoding.Json.pp (Data_encoding.Json.construct Vote.ballots_encoding ballots_info.ballots) (Int32.to_float ballots_info.participation /. 100.) (Int32.to_float ballots_info.current_quorum /. 100.) ballots_info.ballots.yay ballots_info.supermajority >>= fun () -> return_unit else cctxt#message "The ballots have already been cleared." >>= fun () -> return_unit | Cooldown -> print_proposal info.current_proposal >>= fun () -> return_unit | Adoption -> print_proposal info.current_proposal >>= fun () -> return_unit); ]
sectionYPositions = computeSectionYPositions($el), 10)"
x-init="setTimeout(() => sectionYPositions = computeSectionYPositions($el), 10)"
>