diff --git a/CHANGES.rst b/CHANGES.rst index 4306e135c0ca70de8967ef551618ec942bdc0e08..89e614edcbad10a2cdb2ac4c25dc2bcc881c9b82 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -73,6 +73,8 @@ Client support legacy ``endorsement`` kind instead of ``attestation``. (MR :gl:`!11871`) +- **Breaking change** Removed read-write commands specific to Nairobi (MR :gl:`!12058`) + Baker ----- diff --git a/src/proto_017_PtNairob/lib_client_commands/client_proto_context_commands.ml b/src/proto_017_PtNairob/lib_client_commands/client_proto_context_commands.ml index 8baea4a80d1e8bae8f00eb782463d15d4d6042b2..0c466473e76901913f4e2fca765aad205763f95c 100644 --- a/src/proto_017_PtNairob/lib_client_commands/client_proto_context_commands.ml +++ b/src/proto_017_PtNairob/lib_client_commands/client_proto_context_commands.ml @@ -39,7 +39,7 @@ let save_zk_rollup ~force (cctxt : #Client_context.full) alias_name rollup = let*! () = cctxt#message "Epoxy rollup memorized as %s" alias_name in return_unit -let encrypted_switch = +let encrypted_switch : (_, Protocol_client_context.full) Tezos_clic.arg = Tezos_clic.switch ~long:"encrypted" ~doc:"encrypt the key on-disk" () let normalize_types_switch = @@ -76,11 +76,6 @@ let report_michelson_errors ?(no_print_source = false) ~msg return_none | Ok data -> return_some data -let block_hash_param = - Tezos_clic.parameter (fun (cctxt : #Client_context.full) s -> - try Lwt_result_syntax.return (Block_hash.of_b58check_exn s) - with _ -> cctxt#error "Parameter '%s' is an invalid block hash" s) - let group = { Tezos_clic.name = "context"; @@ -794,2432 +789,17 @@ let commands_ro () = return_unit); ] -(* ----------------------------------------------------------------------------*) -(* After the activation of a new version of the protocol, the older protocols - are only kept in the code base to replay the history of the chain and to query - old states. - - The commands that are not useful anymore in the old protocols are removed, - this is called protocol freezing. The commands below are those that can be - removed during protocol freezing. - - The rule of thumb to know if a command should be kept at freezing is that all - commands that modify the state of the chain should be removed and conversely - all commands that are used to query the context should be kept. For this - reason, we call read-only (or RO for short) the commands that are kept and - read-write (or RW for short) the commands that are removed. - - There are some exceptions to this rule however, for example the command - "octez-client wait for to be included" is classified as RW despite having - no effect on the context because it has no use case once all RW commands are - removed. - - Keeping this in mind, the developer should decide where to add a new command. - At the end of the file, RO and RW commands are concatenated into one list that - is then exported in the mli file. *) -(* ----------------------------------------------------------------------------*) - -let dry_run_switch = +let dry_run_switch : (_, Protocol_client_context.full) Tezos_clic.arg = Tezos_clic.switch ~long:"dry-run" ~short:'D' ~doc:"don't inject the operation, just display it" () -let verbose_signing_switch = +let verbose_signing_switch : (_, Protocol_client_context.full) Tezos_clic.arg = 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 transfer_command amount (source : Contract.t) destination - (cctxt : #Client_context.printer) - ( fee, - dry_run, - verbose_signing, - simulation, - force, - gas_limit, - safety_guard, - storage_limit, - counter, - arg, - no_print_source, - fee_parameter, - entrypoint, - replace_by_fees, - successor_level ) = - let open Lwt_result_syntax 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 - let*! () = - if force && not simulation then - let*! () = check_force_dependency "--gas-limit" gas_limit in - let*! () = check_force_dependency "--storage-limit" storage_limit in - check_force_dependency "--fee" fee - else Lwt.return_unit - in - let*! r = - match source with - | Originated contract_hash -> - let contract = source in - let* source = - Managed_contract.get_contract_manager cctxt contract_hash - in - let* _, src_pk, src_sk = Client_keys.get_key cctxt source in - 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 - ?safety_guard - ?storage_limit - ?counter - () - | Implicit source -> - let* _, src_pk, src_sk = Client_keys.get_key cctxt source in - 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 - ?safety_guard - ?storage_limit - ?counter - ~replace_by_fees - ~successor_level - () - in - let*! (_ : (_ Injection.result * Contract_hash.t list) option) = - report_michelson_errors - ~no_print_source - ~msg:"transfer simulation failed" - cctxt - r - in - return_unit - -let prepare_batch_operation cctxt ?arg ?fee ?gas_limit ?storage_limit - ?entrypoint (source : Contract.t) index batch = - let open Lwt_result_syntax in - let* destination = - Client_proto_contracts.Contract_alias.find_destination - cctxt - batch.destination - in - let* amount = tez_of_string_exn cctxt index "amount" batch.amount in - let* batch_fee = tez_of_opt_string_exn cctxt index "fee" batch.fee in - 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 - let* parameters = parse_arg_transfer arg in - let* operation = - match source with - | Originated _ -> - Managed_contract.build_transaction_operation - cctxt - ~chain:cctxt#chain - ~block:cctxt#block - ~contract:source - ~destination - ?entrypoint - ?arg - ~amount - ?fee - ?gas_limit - ?storage_limit - () - | Implicit _ -> - return - (build_transaction_operation - ~amount - ~parameters - ?entrypoint - ?fee - ?gas_limit - ?storage_limit - destination) - in - return (Annotated_manager_operation.Annotated_manager_operation operation) - -let commands_network network () = - let open Tezos_clic in - match network with - | 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"] - @@ Client_proto_args.json_encoded_param - ~name:"activation_key" - ~desc: - "Activate an Alphanet/Zeronet faucet account from the JSON \ - (file or directly inlined)." - Client_proto_context.activation_key_encoding - @@ stop) - (fun (force, encrypted) name activation_key cctxt -> - let open Lwt_result_syntax in - let* name = Secret_key.of_fresh cctxt force name in - let* _res = - activate_account - cctxt - ~chain:cctxt#chain - ~block:cctxt#block - ?confirmations:cctxt#confirmations - ~encrypted - ~force - activation_key - name - in - return_unit); - ] - | 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 (cctxt : #Client_context.full) code -> - match - Blinded_public_key_hash.activation_code_of_hex code - with - | Some c -> Lwt_result_syntax.return c - | None -> cctxt#error "Hexadecimal parsing failure")) - ~desc:"Activation code obtained from the Tezos foundation." - @@ stop) - (fun dry_run (name, _pkh) code cctxt -> - let open Lwt_result_syntax in - let* _res = - activate_existing_account - cctxt - ~chain:cctxt#chain - ~block:cctxt#block - ?confirmations:cctxt#confirmations - ~dry_run - name - code - in - return_unit); - ] - -let commands_rw () = - let open Client_proto_programs in - let open Tezos_micheline in - let open Tezos_clic in - [ - command - ~group - ~desc:"Set the delegate of a contract." - (args5 - fee_arg - dry_run_switch - verbose_signing_switch - simulate_switch - fee_parameter_args) - (prefixes ["set"; "delegate"; "for"] - @@ Contract_alias.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, fee_parameter) - contract - delegate - (cctxt : Protocol_client_context.full) -> - let open Lwt_result_syntax in - match contract with - | Originated contract -> - let* source = - Managed_contract.get_contract_manager cctxt contract - in - let* _, src_pk, src_sk = Client_keys.get_key cctxt source in - let*! errors = - 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) - in - let*! (_ : - (Operation_hash.t - * _ contents - * _ Apply_results.contents_result) - option) = - report_michelson_errors - ~no_print_source:true - ~msg:"Setting delegate through entrypoints failed." - cctxt - errors - in - return_unit - | Implicit mgr -> - let* _, src_pk, manager_sk = Client_keys.get_key cctxt mgr in - let* (_ : _ Injection.result) = - 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 - in - return_unit); - command - ~group - ~desc:"Withdraw the delegate from a contract." - (args4 fee_arg dry_run_switch verbose_signing_switch fee_parameter_args) - (prefixes ["withdraw"; "delegate"; "from"] - @@ Contract_alias.destination_param ~name:"src" ~desc:"source contract" - @@ stop) - (fun (fee, dry_run, verbose_signing, fee_parameter) - contract - (cctxt : Protocol_client_context.full) -> - let open Lwt_result_syntax in - match contract with - | Originated contract -> - let* source = - Managed_contract.get_contract_manager cctxt contract - in - let* _, src_pk, src_sk = Client_keys.get_key cctxt source in - let*! errors = - 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 - in - let*! (_ : _ Injection.result option) = - report_michelson_errors - ~no_print_source:true - ~msg:"Withdrawing delegate through entrypoints failed." - cctxt - errors - in - return_unit - | Implicit mgr -> - let* _, src_pk, manager_sk = Client_keys.get_key cctxt mgr in - let*! (_ : _ Injection.result tzresult) = - 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 - in - return_unit); - command - ~group - ~desc:"Launch a smart contract on the blockchain." - (args11 - fee_arg - dry_run_switch - verbose_signing_switch - gas_limit_arg - safety_guard_arg - storage_limit_arg - delegate_arg - (Client_keys.force_switch ()) - init_arg - no_print_source_flag - fee_parameter_args) - (prefixes ["originate"; "contract"] - @@ Raw_contract_alias.fresh_alias_param - ~name:"new" - ~desc:"name of the new contract" - @@ prefix "transferring" - @@ tez_param ~name:"qty" ~desc:"amount taken from source" - @@ prefix "from" - @@ Client_keys.Public_key_hash.source_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, - safety_guard, - storage_limit, - delegate, - force, - initial_storage, - no_print_source, - fee_parameter ) - alias_name - balance - source - program - (cctxt : Protocol_client_context.full) -> - let open Lwt_result_syntax in - let* alias_name = Raw_contract_alias.of_fresh cctxt force alias_name in - let* {expanded = code; _} = - Lwt.return (Micheline_parser.no_parsing_error program) - in - let* _, src_pk, src_sk = Client_keys.get_key cctxt source in - let*! errors = - originate_contract - cctxt - ~chain:cctxt#chain - ~block:cctxt#block - ?confirmations:cctxt#confirmations - ~dry_run - ~verbose_signing - ?fee - ?gas_limit - ?safety_guard - ?storage_limit - ~delegate - ~initial_storage - ~balance - ~source - ~src_pk - ~src_sk - ~code - ~fee_parameter - () - in - let*! o = - report_michelson_errors - ~no_print_source - ~msg:"origination simulation failed" - cctxt - errors - in - match o with - | None -> return_unit - | Some (_res, contract) -> - if dry_run then return_unit - else save_contract ~force cctxt alias_name contract); - command - ~group - ~desc: - "Execute multiple transfers from a single source account.\n\ - If one of the transfers fails, none of them get executed." - (args14 - default_fee_arg - dry_run_switch - verbose_signing_switch - simulate_switch - force_switch - default_gas_limit_arg - safety_guard_arg - default_storage_limit_arg - counter_arg - default_arg_arg - no_print_source_flag - fee_parameter_args - default_entrypoint_arg - replace_by_fees_arg) - (prefixes ["multiple"; "transfers"; "from"] - @@ Contract_alias.destination_param - ~name:"src" - ~desc:"name of the source contract" - @@ prefix "using" - @@ json_encoded_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 (, : ...) } (, ...) ]', where an \ - optional can either be \"fee\", \"gas-limit\", \ - \"storage-limit\", \"arg\", or \"entrypoint\"." - ~pp_error:(fun json fmt exn -> - match (json, exn) with - | `A lj, Data_encoding.Json.Cannot_destruct ([`Index n], exn) -> - Format.fprintf - fmt - "Invalid transfer at index %i: %a %a" - n - (fun ppf -> Data_encoding.Json.print_error ppf) - exn - (Format.pp_print_option Data_encoding.Json.pp) - (List.nth_opt lj n) - | _, (Data_encoding.Json.Cannot_destruct _ as exn) -> - Format.fprintf - fmt - "Invalid transfer file: %a %a" - (fun ppf -> Data_encoding.Json.print_error ppf) - exn - Data_encoding.Json.pp - json - | _, exn -> raise exn - (* this case can't happen because only `Cannot_destruct` error are - given to this pp *)) - (Data_encoding.list - Client_proto_context.batch_transfer_operation_encoding) - @@ stop) - (fun ( fee, - dry_run, - verbose_signing, - simulation, - force, - gas_limit, - safety_guard, - storage_limit, - counter, - arg, - no_print_source, - fee_parameter, - entrypoint, - replace_by_fees ) - source - operations - cctxt -> - (* 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 open Lwt_result_syntax in - 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 - let*! () = - if force && not simulation then - let*! () = check_force_dependency "--gas-limit" gas_limit in - let*! () = check_force_dependency "--storage-limit" storage_limit in - check_force_dependency "--fee" fee - else Lwt.return_unit - in - let prepare i = - prepare_batch_operation - cctxt - ?arg - ?fee - ?gas_limit - ?storage_limit - ?entrypoint - source - i - in - match operations with - | [] -> cctxt#error "Empty operation list" - | operations -> - let* source = - match source with - | Originated contract -> - Managed_contract.get_contract_manager cctxt contract - | Implicit source -> return source - in - let* _, src_pk, src_sk = Client_keys.get_key cctxt source in - let* contents = List.mapi_ep prepare operations in - let (Manager_list contents) = - Annotated_manager_operation.manager_of_list contents - in - let*! errors = - Injection.inject_manager_operation - cctxt - ~chain:cctxt#chain - ~block:cctxt#block - ?confirmations:cctxt#confirmations - ~dry_run - ~verbose_signing - ~simulation - ~force - ~source - ~fee:(Limit.of_option fee) - ~gas_limit:(Limit.of_option gas_limit) - ~storage_limit:(Limit.of_option storage_limit) - ?safety_guard - ?counter - ~src_pk - ~src_sk - ~replace_by_fees - ~fee_parameter - contents - in - let*! (_ : - (Operation_hash.t - * packed_operation - * _ contents_list - * _ Apply_results.contents_result_list) - option) = - report_michelson_errors - ~no_print_source - ~msg:"multiple transfers simulation failed" - cctxt - errors - in - return_unit); - command - ~group - ~desc:"Execute an Epoxy origination operation.\n" - (args14 - force_switch - default_fee_arg - dry_run_switch - verbose_signing_switch - simulate_switch - default_gas_limit_arg - safety_guard_arg - default_storage_limit_arg - counter_arg - default_arg_arg - no_print_source_flag - fee_parameter_args - default_entrypoint_arg - replace_by_fees_arg) - (prefixes ["originate"; "epoxy"] - @@ Epoxy_alias.fresh_alias_param - ~name:"epoxy" - ~desc:"Fresh name for an Epoxy rollup" - @@ prefix "from" - @@ Client_keys.Public_key_hash.source_param - ~name:"src" - ~desc:"name of the source contract" - @@ prefix "public_parameters" - @@ param - ~name:"public_parameters" - ~desc:"public_parameters" - Zk_rollup_params.plonk_public_parameters_parameter - @@ prefix "init_state" - @@ param - ~name:"init_state" - ~desc:"init_state" - Zk_rollup_params.state_parameter - @@ prefix "circuits_info" - @@ param - ~name:"circuits_info" - ~desc:"circuits_info" - Zk_rollup_params.circuits_info_parameter - @@ prefix "nb_ops" - @@ param ~name:"nb_ops" ~desc:"nb_ops" int_parameter - @@ stop) - (fun ( force, - fee, - dry_run, - verbose_signing, - simulation, - gas_limit, - safety_guard, - storage_limit, - counter, - _arg, - _no_print_source, - fee_parameter, - _entrypoint, - _replace_by_fees ) - alias - source - public_parameters - init_state - circuits_info - nb_ops - cctxt -> - let open Lwt_result_syntax in - let* _, src_pk, src_sk = Client_keys.get_key cctxt source in - let* _, _, res = - zk_rollup_originate - cctxt - ~chain:cctxt#chain - ~block:cctxt#block - ~dry_run - ~verbose_signing - ?fee - ?gas_limit - ?safety_guard - ?storage_limit - ?counter - ?confirmations:cctxt#confirmations - ~simulation - ~source - ~src_pk - ~src_sk - ~fee_parameter - ~public_parameters - ~circuits_info - ~init_state - ~nb_ops - () - in - let*? res = - match res with - | Apply_results.Manager_operation_result - { - operation_result = - Apply_operation_result.Applied - (Apply_results.Zk_rollup_origination_result - {originated_zk_rollup; _}); - _; - } -> - Ok originated_zk_rollup - | _ -> error_with "Epoxy rollup was not correctly originated" - in - let* alias_name = Epoxy_alias.of_fresh cctxt force alias in - save_zk_rollup ~force cctxt alias_name res); - command - ~group - ~desc:"Execute an Epoxy publish operation.\n" - (args13 - default_fee_arg - dry_run_switch - verbose_signing_switch - simulate_switch - default_gas_limit_arg - safety_guard_arg - default_storage_limit_arg - counter_arg - default_arg_arg - no_print_source_flag - fee_parameter_args - default_entrypoint_arg - replace_by_fees_arg) - (prefixes ["epoxy"; "publish"; "from"] - @@ Client_keys.Public_key_hash.source_param - ~name:"src" - ~desc:"name of the source contract" - @@ prefix "rollup" - @@ param ~name:"rollup" ~desc:"rollup" Zk_rollup_params.address_parameter - @@ prefix "ops" - @@ param ~name:"ops" ~desc:"ops" Zk_rollup_params.operations_parameter - @@ stop) - (fun ( fee, - dry_run, - verbose_signing, - simulation, - gas_limit, - safety_guard, - storage_limit, - counter, - _arg, - _no_print_source, - fee_parameter, - _entrypoint, - _replace_by_fees ) - source - zk_rollup - ops - cctxt -> - let open Lwt_result_syntax in - let* _, src_pk, src_sk = Client_keys.get_key cctxt source in - let* _res = - zk_rollup_publish - cctxt - ~chain:cctxt#chain - ~block:cctxt#block - ~dry_run - ~verbose_signing - ?fee - ?gas_limit - ?safety_guard - ?storage_limit - ?counter - ?confirmations:cctxt#confirmations - ~simulation - ~source - ~src_pk - ~src_sk - ~fee_parameter - ~zk_rollup - ~ops - () - in - return_unit); - command - ~group - ~desc:"Execute an Epoxy update operation.\n" - (args13 - default_fee_arg - dry_run_switch - verbose_signing_switch - simulate_switch - default_gas_limit_arg - safety_guard_arg - default_storage_limit_arg - counter_arg - default_arg_arg - no_print_source_flag - fee_parameter_args - default_entrypoint_arg - replace_by_fees_arg) - (prefixes ["epoxy"; "update"; "from"] - @@ Client_keys.Public_key_hash.source_param - ~name:"src" - ~desc:"name of the source contract" - @@ prefix "rollup" - @@ param ~name:"rollup" ~desc:"rollup" Zk_rollup_params.address_parameter - @@ prefix "update" - @@ param ~name:"update" ~desc:"update" Zk_rollup_params.update_parameter - @@ stop) - (fun ( fee, - dry_run, - verbose_signing, - simulation, - gas_limit, - safety_guard, - storage_limit, - counter, - _arg, - _no_print_source, - fee_parameter, - _entrypoint, - _replace_by_fees ) - source - zk_rollup - update - cctxt -> - let open Lwt_result_syntax in - let* _, src_pk, src_sk = Client_keys.get_key cctxt source in - let* _res = - zk_rollup_update - cctxt - ~chain:cctxt#chain - ~block:cctxt#block - ~dry_run - ~verbose_signing - ?fee - ?gas_limit - ?safety_guard - ?storage_limit - ?counter - ?confirmations:cctxt#confirmations - ~simulation - ~source - ~src_pk - ~src_sk - ~fee_parameter - ~zk_rollup - ~update - () - in - return_unit); - command - ~group - ~desc:"Transfer tokens / call a smart contract." - (args15 - fee_arg - dry_run_switch - verbose_signing_switch - simulate_switch - force_switch - gas_limit_arg - safety_guard_arg - storage_limit_arg - counter_arg - arg_arg - no_print_source_flag - fee_parameter_args - entrypoint_arg - replace_by_fees_arg - successor_level_arg) - (prefixes ["transfer"] - @@ tez_param ~name:"qty" ~desc:"amount taken from source" - @@ prefix "from" - @@ Contract_alias.destination_param - ~name:"src" - ~desc:"name of the source contract" - @@ prefix "to" - @@ Contract_alias.destination_param - ~name:"dst" - ~desc:"name/literal of the destination contract" - @@ stop) - (fun ( fee, - dry_run, - verbose_signing, - simulation, - force, - gas_limit, - safety_guard, - storage_limit, - counter, - arg, - no_print_source, - fee_parameter, - entrypoint, - replace_by_fees, - successor_level ) - amount - source - destination - cctxt -> - transfer_command - amount - source - destination - cctxt - ( fee, - dry_run, - verbose_signing, - simulation, - force, - gas_limit, - safety_guard, - storage_limit, - counter, - arg, - no_print_source, - fee_parameter, - entrypoint, - replace_by_fees, - successor_level )); - command - ~group - ~desc:"Register a global constant" - (args7 - fee_arg - dry_run_switch - verbose_signing_switch - simulate_switch - fee_parameter_args - storage_limit_arg - counter_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" - @@ Client_keys.Public_key_hash.source_param - ~name:"src" - ~desc:"name of the account registering the global constant" - @@ stop) - (fun ( fee, - dry_run, - verbose_signing, - simulation, - fee_parameter, - storage_limit, - counter ) - global_constant_str - source - cctxt -> - let open Lwt_result_syntax in - let* _, src_pk, src_sk = Client_keys.get_key cctxt source in - let*! errors = - register_global_constant - cctxt - ~chain:cctxt#chain - ~block:cctxt#block - ~dry_run - ~verbose_signing - ?fee - ?storage_limit - ?counter - ?confirmations:cctxt#confirmations - ~simulation - ~source - ~src_pk - ~src_sk - ~fee_parameter - ~constant:global_constant_str - () - in - let*! (_ : _ Injection.result option) = - report_michelson_errors - ~no_print_source:false - ~msg:"register global constant simulation failed" - cctxt - errors - in - return_unit); - command - ~group - ~desc:"Call a smart contract (same as 'transfer 0')." - (args15 - fee_arg - dry_run_switch - verbose_signing_switch - simulate_switch - force_switch - gas_limit_arg - safety_guard_arg - storage_limit_arg - counter_arg - arg_arg - no_print_source_flag - fee_parameter_args - entrypoint_arg - replace_by_fees_arg - successor_level_arg) - (prefixes ["call"] - @@ Contract_alias.destination_param - ~name:"dst" - ~desc:"name/literal of the destination contract" - @@ prefix "from" - @@ Contract_alias.destination_param - ~name:"src" - ~desc:"name of the source contract" - @@ stop) - (fun ( fee, - dry_run, - verbose_signing, - simulation, - force, - gas_limit, - safety_guard, - storage_limit, - counter, - arg, - no_print_source, - fee_parameter, - entrypoint, - replace_by_fees, - successor_level ) - destination - source - cctxt -> - let amount = Tez.zero in - transfer_command - amount - source - destination - cctxt - ( fee, - dry_run, - verbose_signing, - simulation, - force, - gas_limit, - safety_guard, - storage_limit, - counter, - arg, - no_print_source, - fee_parameter, - entrypoint, - replace_by_fees, - successor_level )); - command - ~group - ~desc:"Reveal the public key of the contract manager." - (args4 fee_arg dry_run_switch verbose_signing_switch fee_parameter_args) - (prefixes ["reveal"; "key"; "for"] - @@ Client_keys.Public_key_hash.source_param - ~name:"src" - ~desc:"name of the source contract" - @@ stop) - (fun (fee, dry_run, verbose_signing, fee_parameter) source cctxt -> - let open Lwt_result_syntax in - let* _, src_pk, src_sk = Client_keys.get_key cctxt source in - let* _res = - reveal - cctxt - ~dry_run - ~verbose_signing - ~chain:cctxt#chain - ~block:cctxt#block - ?confirmations:cctxt#confirmations - ~source - ?fee - ~src_pk - ~src_sk - ~fee_parameter - () - in - return_unit); - command - ~group - ~desc:"Register the public key hash as a delegate." - (args4 fee_arg dry_run_switch verbose_signing_switch fee_parameter_args) - (prefixes ["register"; "key"] - @@ Public_key_hash.source_param ~name:"mgr" ~desc:"the delegate key" - @@ prefixes ["as"; "delegate"] - @@ stop) - (fun (fee, dry_run, verbose_signing, fee_parameter) src_pkh cctxt -> - let open Lwt_result_syntax in - let* _, src_pk, src_sk = Client_keys.get_key cctxt src_pkh in - let*! r = - 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 - in - match r with - | Ok _ -> return_unit - | Error - [ - Environment.Ecoproto_error - Delegate_storage.Contract.Active_delegate; - ] -> - let*! () = cctxt#message "Delegate already activated." in - return_unit - | Error el -> Lwt.return_error el); - command - ~group - ~desc:"Register the public key hash as a delegate." - (args4 fee_arg dry_run_switch verbose_signing_switch fee_parameter_args) - (prefixes ["register"; "key"] - @@ Public_key_hash.source_param ~name:"mgr" ~desc:"the delegate key" - @@ prefixes ["as"; "delegate"; "with"; "consensus"; "key"] - @@ Public_key.source_param ~name:"key" ~desc:"the consensus key" - @@ stop) - (fun (fee, dry_run, verbose_signing, fee_parameter) - src_pkh - (name_pk, consensus_pk) - cctxt -> - let open Lwt_result_syntax in - let* _, src_pk, src_sk = Client_keys.get_key cctxt src_pkh in - let* consensus_pk = - match consensus_pk with - | Some pk -> return pk - | None -> Client_keys.public_key name_pk - in - let*! r = - register_as_delegate - cctxt - ~chain:cctxt#chain - ~block:cctxt#block - ?confirmations:cctxt#confirmations - ~dry_run - ~fee_parameter - ~verbose_signing - ?fee - ~manager_sk:src_sk - ~consensus_pk - src_pk - in - match r with - | Ok _ -> return_unit - | Error - [ - Environment.Ecoproto_error - Delegate_storage.Contract.Active_delegate; - ] -> - let*! () = cctxt#message "Delegate already activated." in - return_unit - | Error el -> Lwt.return_error el); - command - ~group - ~desc:"Update the consensus key of a delegate." - (args4 fee_arg dry_run_switch verbose_signing_switch fee_parameter_args) - (prefixes ["set"; "consensus"; "key"; "for"] - @@ Public_key_hash.source_param ~name:"mgr" ~desc:"the delegate key" - @@ prefixes ["to"] - @@ Public_key.source_param ~name:"key" ~desc:"the consensus key" - @@ stop) - (fun (fee, dry_run, verbose_signing, fee_parameter) - delegate_pkh - (name_pk, consensus_pk) - cctxt -> - let open Lwt_result_syntax in - let* _, delegate_pk, delegate_sk = - Client_keys.get_key cctxt delegate_pkh - in - let* consensus_pk = - match consensus_pk with - | Some pk -> return pk - | None -> Client_keys.public_key name_pk - in - let*! r = - update_consensus_key - cctxt - ~chain:cctxt#chain - ~block:cctxt#block - ?confirmations:cctxt#confirmations - ~dry_run - ~fee_parameter - ~verbose_signing - ?fee - ~consensus_pk - ~manager_sk:delegate_sk - delegate_pk - in - match r with Ok _ -> return_unit | Error el -> Lwt.return_error el); - command - ~group - ~desc:"Drain all funds from a delegate." - (args2 dry_run_switch verbose_signing_switch) - (prefixes ["drain"; "delegate"] - @@ Public_key_hash.source_param ~name:"mgr" ~desc:"the delegate key" - @@ prefixes ["to"] - @@ Public_key_hash.source_param ~name:"dest" ~desc:"the consensus key" - @@ stop) - (fun (dry_run, verbose_signing) delegate_pkh consensus_pkh cctxt -> - let open Lwt_result_syntax in - let* _, _consensus_pk, consensus_sk = - Client_keys.get_key cctxt consensus_pkh - in - let*! r = - drain_delegate - cctxt - ~chain:cctxt#chain - ~block:cctxt#block - ?confirmations:cctxt#confirmations - ~dry_run - ~verbose_signing - ~consensus_pkh - ~consensus_sk - ~delegate:delegate_pkh - () - in - match r with Ok _ -> return_unit | Error el -> Lwt.return_error el); - command - ~group - ~desc:"Drain all funds from a delegate." - (args2 dry_run_switch verbose_signing_switch) - (prefixes ["drain"; "delegate"] - @@ Public_key_hash.source_param ~name:"mgr" ~desc:"the delegate key" - @@ prefixes ["to"] - @@ Public_key_hash.source_param ~name:"dest" ~desc:"the destination key" - @@ prefixes ["with"] - @@ Public_key_hash.source_param - ~name:"consensus_key" - ~desc:"the consensus key" - @@ stop) - (fun (dry_run, verbose_signing) - delegate_pkh - destination_pkh - consensus_pkh - cctxt -> - let open Lwt_result_syntax in - let* _, _consensus_pk, consensus_sk = - Client_keys.get_key cctxt consensus_pkh - in - let*! r = - drain_delegate - cctxt - ~chain:cctxt#chain - ~block:cctxt#block - ?confirmations:cctxt#confirmations - ~dry_run - ~verbose_signing - ~consensus_pkh - ~consensus_sk - ~destination:destination_pkh - ~delegate:delegate_pkh - () - in - match r with Ok _ -> return_unit | Error el -> Lwt.return_error el); - 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_parameter ())) - (default_arg - ~long:"check-previous" - ~placeholder:"num_blocks" - ~doc:"number of previous blocks to check" - ~default:"10" - (non_negative_parameter ())) - (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 (cctxt : #Client_context.full) x -> - match Operation_hash.of_b58check_opt x with - | None -> cctxt#error "Invalid operation hash: '%s'" x - | Some hash -> Lwt_result_syntax.return hash)) - @@ prefixes ["to"; "be"; "included"] - @@ stop) - (fun (confirmations, predecessors, branch) - operation_hash - (ctxt : Protocol_client_context.full) -> - let open Lwt_result_syntax in - let* (_ : Block_hash.t * int * int) = - Client_confirmations.wait_for_operation_inclusion - ctxt - ~chain:ctxt#chain - ~confirmations - ~predecessors - ?branch - operation_hash - in - 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 fail." - ~long:"force" - ())) - (prefixes ["submit"; "proposals"; "for"] - @@ Client_keys.Public_key_hash.source_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 (cctxt : #Client_context.full) x -> - match Protocol_hash.of_b58check_opt x with - | None -> cctxt#error "Invalid proposal hash: '%s'" x - | Some hash -> Lwt_result_syntax.return hash)))) - (fun (dry_run, verbose_signing, force) - src_pkh - proposals - (cctxt : Protocol_client_context.full) -> - let open Lwt_result_syntax in - let* src_name, _src_pk, src_sk = Client_keys.get_key cctxt src_pkh in - let* info = - 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 - in - let*! () = - match info.current_period_kind with - | Proposal -> Lwt.return_unit - | _ -> - (if force then cctxt#warning else cctxt#error) - "Not in a proposal period" - in - let* known_protos = Shell_services.Protocol.list cctxt in - let* known_proposals = - get_proposals ~chain:cctxt#chain ~block:cctxt#block cctxt - in - let* has_voting_power = - let*! r = - Alpha_services.Delegate.voting_power - cctxt - (cctxt#chain, cctxt#block) - src_pkh - in - match r with - | Ok voting_power -> return (voting_power <> 0L) - | Error - (Environment.Ecoproto_error (Delegate_services.Not_registered _) - :: _) -> - return false - | Error _ as err -> Lwt.return err - in - (* 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 errors = ref [] in - let error ppf = - Format.kasprintf (fun s -> errors := s :: !errors) ppf - in - if proposals = [] then error "Empty proposal list." ; - if - Compare.List_length_with.( - proposals > Constants.max_proposals_per_delegate) - then - error - "Too many proposals: %d > %d." - (List.length proposals) - 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 has_voting_power then - error - "Public-key-hash `%a` from account `%s` does not appear to have \ - voting rights." - Signature.Public_key_hash.pp - src_pkh - src_name ; - if !errors <> [] then - let*! () = - 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 ()) - in - return_false - else return_true - in - let* all_valid = check_proposals proposals in - let*! () = - 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." - in - let*! r = - submit_proposals - ~dry_run - ~verbose_signing - cctxt - ~chain:cctxt#chain - ~block:cctxt#block - ~src_sk - src_pkh - proposals - in - match r with - | Ok _res -> return_unit - | Error errs -> - let*! () = - match errs with - | [ - Unregistered_error - (`O [("kind", `String "generic"); ("error", `String msg)]); - ] -> - cctxt#message - "Error:@[@.%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)) - | el -> cctxt#message "Error:@ %a" pp_print_trace el - in - cctxt#error "Failed to submit proposals"); - command - ~group - ~desc:"Submit a ballot" - (args3 - verbose_signing_switch - dry_run_switch - (switch - ~doc: - "Do not fail when the checks that try to prevent the user from \ - shooting themselves in the foot do fail." - ~long:"force" - ())) - (prefixes ["submit"; "ballot"; "for"] - @@ Client_keys.Public_key_hash.source_param - ~name:"delegate" - ~desc:"the delegate who votes" - @@ param - ~name:"proposal" - ~desc:"the protocol hash proposal to vote for" - (parameter (fun (cctxt : #Client_context.full) x -> - match Protocol_hash.of_b58check_opt x with - | None -> cctxt#error "Invalid proposal hash: '%s'" x - | Some hash -> Lwt_result_syntax.return hash)) - @@ param - ~name:"ballot" - ~desc: - "the ballot value (yea, nay, or pass; yay is a deprecated synonym \ - for yea)" - (parameter - ~autocomplete:(fun _ -> - Lwt_result_syntax.return ["yea"; "nay"; "pass"]) - (fun (cctxt : #Client_context.full) s -> - let open Lwt_result_syntax in - (* 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 -> cctxt#error "Invalid ballot: '%s'" s)) - @@ stop) - (fun (verbose_signing, dry_run, force) - src_pkh - proposal - ballot - (cctxt : Protocol_client_context.full) -> - let open Lwt_result_syntax in - let* src_name, _src_pk, src_sk = Client_keys.get_key cctxt src_pkh in - let* info = - 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 - in - let* current_proposal = - Alpha_services.Voting.current_proposal cctxt (cctxt#chain, cctxt#block) - in - let* () = - match (info.current_period_kind, current_proposal) with - | (Exploration | Promotion), Some current_proposal -> - if Protocol_hash.equal proposal current_proposal then return_unit - else - let*! () = - (if force then cctxt#warning else cctxt#error) - "Unexpected proposal, expected: %a" - Protocol_hash.pp - current_proposal - in - return_unit - | _ -> - let*! () = - (if force then cctxt#warning else cctxt#error) - "Not in Exploration or Promotion period" - in - return_unit - in - let* has_voting_power = - let*! r = - Alpha_services.Delegate.voting_power - cctxt - (cctxt#chain, cctxt#block) - src_pkh - in - match r with - | Ok voting_power -> return (voting_power <> 0L) - | Error - (Environment.Ecoproto_error (Delegate_services.Not_registered _) - :: _) -> - return false - | Error _ as err -> Lwt.return err - in - let*! () = - if has_voting_power then Lwt.return_unit - else - (if force then cctxt#warning else cctxt#error) - "Public-key-hash `%a` from account `%s` does not appear to have \ - voting rights." - Signature.Public_key_hash.pp - src_pkh - src_name - in - let* _res = - submit_ballot - cctxt - ~chain:cctxt#chain - ~block:cctxt#block - ~src_sk - src_pkh - ~verbose_signing - ~dry_run - proposal - ballot - in - return_unit); - command - ~group - ~desc:"Set the deposits limit of a registered delegate." - (args5 - fee_arg - dry_run_switch - verbose_signing_switch - simulate_switch - fee_parameter_args) - (prefixes ["set"; "deposits"; "limit"; "for"] - @@ Contract_alias.destination_param ~name:"src" ~desc:"source contract" - @@ prefix "to" - @@ tez_param - ~name:"deposits limit" - ~desc:"the maximum amount of frozen deposits" - @@ stop) - (fun (fee, dry_run, verbose_signing, simulation, fee_parameter) - contract - limit - (cctxt : Protocol_client_context.full) -> - let open Lwt_result_syntax in - match contract with - | Originated _ -> - cctxt#error - "Cannot change deposits limit on contract %a. This operation is \ - invalid on originated contracts or unregistered delegate \ - contracts." - Contract.pp - contract - | Implicit mgr -> - let* _, src_pk, manager_sk = Client_keys.get_key cctxt mgr in - let* (_ : _ Injection.result) = - set_deposits_limit - cctxt - ~chain:cctxt#chain - ~block:cctxt#block - ?confirmations:cctxt#confirmations - ~dry_run - ~verbose_signing - ~simulation - ~fee_parameter - ?fee - mgr - ~src_pk - ~manager_sk - (Some limit) - in - return_unit); - command - ~group - ~desc:"Remove the deposits limit of a registered delegate." - (args5 - fee_arg - dry_run_switch - verbose_signing_switch - simulate_switch - fee_parameter_args) - (prefixes ["unset"; "deposits"; "limit"; "for"] - @@ Contract_alias.destination_param ~name:"src" ~desc:"source contract" - @@ stop) - (fun (fee, dry_run, verbose_signing, simulation, fee_parameter) - contract - (cctxt : Protocol_client_context.full) -> - let open Lwt_result_syntax in - match contract with - | Originated _ -> - cctxt#error - "Cannot change deposits limit on contract %a. This operation is \ - invalid on originated contracts or unregistered delegate \ - contracts." - Contract.pp - contract - | Implicit mgr -> - let* _, src_pk, manager_sk = Client_keys.get_key cctxt mgr in - let* (_ : _ Injection.result) = - set_deposits_limit - cctxt - ~chain:cctxt#chain - ~block:cctxt#block - ?confirmations:cctxt#confirmations - ~dry_run - ~verbose_signing - ~simulation - ~fee_parameter - ?fee - mgr - ~src_pk - ~manager_sk - None - in - return_unit); - command - ~group - ~desc:"Increase the paid storage of a smart contract." - (args6 - force_switch - fee_arg - dry_run_switch - verbose_signing_switch - simulate_switch - fee_parameter_args) - (prefixes ["increase"; "the"; "paid"; "storage"; "of"] - @@ Originated_contract_alias.destination_param - ~name:"contract" - ~desc:"name of the smart contract" - @@ prefix "by" - @@ non_negative_z_param ~name:"amount" ~desc:"amount of increase in bytes" - @@ prefixes ["bytes"; "from"] - @@ Public_key_hash.source_param - ~name:"payer" - ~desc:"payer of the storage increase" - @@ stop) - (fun (force, fee, dry_run, verbose_signing, simulation, fee_parameter) - contract - amount_in_bytes - payer - (cctxt : Protocol_client_context.full) -> - let open Lwt_result_syntax in - let* _, src_pk, manager_sk = Client_keys.get_key cctxt payer in - let* (_ : _ Injection.result) = - increase_paid_storage - cctxt - ~chain:cctxt#chain - ~block:cctxt#block - ~force - ~dry_run - ~verbose_signing - ?fee - ?confirmations:cctxt#confirmations - ~simulation - ~source:payer - ~src_pk - ~manager_sk - ~destination:contract - ~fee_parameter - ~amount_in_bytes - () - in - return_unit); - command - ~group - ~desc: - "Transfer tickets from an implicit account to a contract or another \ - implicit account." - (args7 - fee_arg - dry_run_switch - verbose_signing_switch - simulate_switch - fee_parameter_args - storage_limit_arg - counter_arg) - (prefix "transfer" - @@ non_negative_z_param ~name:"qty" ~desc:"Amount of tickets to transfer." - @@ prefixes ["tickets"; "from"] - @@ Client_keys.Public_key_hash.source_param - ~name:"tickets owner" - ~desc:"Implicit account owning the tickets." - @@ prefix "to" - @@ Contract_alias.destination_param - ~name:"recipient contract" - ~desc:"Contract receiving the tickets." - @@ prefixes ["with"; "entrypoint"] - @@ Tezos_clic.param - ~name:"entrypoint" - ~desc: - "Entrypoint to use on the receiving contract or implicit account. \ - Needs to be \"default\" for implicit account destinations." - entrypoint_parameter - @@ prefixes ["and"; "contents"] - @@ Tezos_clic.param - ~name:"tickets content" - ~desc:"Content of the tickets." - Client_proto_args.string_parameter - @@ prefixes ["and"; "type"] - @@ Tezos_clic.param - ~name:"tickets type" - ~desc:"Type of the tickets." - Client_proto_args.string_parameter - @@ prefixes ["and"; "ticketer"] - @@ Contract_alias.destination_param - ~name:"tickets ticketer" - ~desc:"Ticketer contract of the tickets." - @@ stop) - (fun ( fee, - dry_run, - verbose_signing, - simulation, - fee_parameter, - storage_limit, - counter ) - amount - source - destination - entrypoint - contents - ty - ticketer - cctxt -> - let open Lwt_result_syntax in - let* _, src_pk, src_sk = Client_keys.get_key cctxt source in - match Ticket_amount.of_zint amount with - | Some amount -> - let* _res = - transfer_ticket - cctxt - ~chain:cctxt#chain - ~block:cctxt#block - ~dry_run - ~verbose_signing - ?fee - ?storage_limit - ?counter - ?confirmations:cctxt#confirmations - ~simulation - ~source - ~src_pk - ~src_sk - ~fee_parameter - ~contents - ~ty - ~ticketer - ~amount - ~destination - ~entrypoint - () - in - return_unit - | None -> cctxt#error "ticket quantity should not be zero or negative"); - command - ~group - ~desc:"Originate a new smart rollup." - (args8 - fee_arg - dry_run_switch - verbose_signing_switch - simulate_switch - fee_parameter_args - storage_limit_arg - counter_arg - (Client_keys.force_switch ())) - (prefixes ["originate"; "smart"; "rollup"] - @@ Soru_alias.fresh_alias_param - ~name:"alias" - ~desc:"name of the new smart rollup" - @@ prefix "from" - @@ Client_keys.Public_key_hash.source_param - ~name:"src" - ~desc:"Name of the account originating the smart rollup." - @@ prefixes ["of"; "kind"] - @@ param - ~name:"smart_rollup_kind" - ~desc:"Kind of the smart rollup to be originated." - Sc_rollup_params.rollup_kind_parameter - @@ prefixes ["of"; "type"] - @@ param - ~name:"parameters_type" - ~desc: - "The interface of the smart rollup including its entrypoints and \ - their signatures." - data_parameter - @@ prefixes ["with"; "kernel"] - @@ param - ~name:"kernel" - ~desc:"The kernel for the smart rollup." - Sc_rollup_params.boot_sector_parameter - @@ stop) - (fun ( fee, - dry_run, - verbose_signing, - simulation, - fee_parameter, - storage_limit, - counter, - force ) - alias - source - kind - parameters_ty - boot_sector - cctxt -> - let open Lwt_result_syntax in - let* _, src_pk, src_sk = Client_keys.get_key cctxt source in - let (Packed (module R) as pvm) = Sc_rollup.Kind.pvm_of kind in - let Michelson_v1_parser.{expanded; _} = parameters_ty in - let parameters_ty = Script.lazy_expr expanded in - let* boot_sector = boot_sector pvm in - let* _, _, res = - sc_rollup_originate - cctxt - ~chain:cctxt#chain - ~block:cctxt#block - ~dry_run - ~verbose_signing - ?fee - ?storage_limit - ?counter - ?confirmations:cctxt#confirmations - ~simulation - ~source - ~src_pk - ~src_sk - ~fee_parameter - ~kind - ~boot_sector - ~parameters_ty - () - in - match res with - | Apply_results.Manager_operation_result - { - operation_result = - Apply_operation_result.Applied - (Apply_results.Sc_rollup_originate_result - {address = rollup_address; _}); - _; - } -> - if dry_run then return_unit - else - let* alias = Soru_alias.of_fresh cctxt force alias in - let* () = Soru_alias.add ~force cctxt alias rollup_address in - let*! () = - cctxt#message - {|Smart rollup %a memorized as "%s"|} - Sc_rollup.Address.pp - rollup_address - alias - in - return_unit - | _ -> return_unit); - command - ~group - ~desc:"Send one or more messages to a smart rollup." - (args9 - fee_arg - dry_run_switch - verbose_signing_switch - simulate_switch - fee_parameter_args - gas_limit_arg - safety_guard_arg - storage_limit_arg - counter_arg) - (prefixes ["send"; "smart"; "rollup"; "message"] - @@ param - ~name:"messages" - ~desc: - "The message(s) to be sent to the rollup (syntax: \ - bin:|text:|hex:|file:)." - Sc_rollup_params.messages_parameter - @@ prefixes ["from"] - @@ Client_keys.Public_key_hash.source_param - ~name:"src" - ~desc:"Name of the source contract." - @@ stop) - (fun ( fee, - dry_run, - verbose_signing, - simulation, - fee_parameter, - gas_limit, - safety_guard, - storage_limit, - counter ) - messages - source - cctxt -> - let open Lwt_result_syntax in - let* messages = - match messages with - | `Bin message -> return [message] - | `Json messages -> ( - match Data_encoding.(Json.destruct (list string) messages) with - | exception _ -> - cctxt#error - "Could not read list of messages (expected list of bytes)" - | "raw" :: messages -> return messages - | "hex" :: messages -> - let* messages = - List.map_es - (fun message -> - match Hex.to_string (`Hex message) with - | None -> - cctxt#error - "'%s' is not a valid hex encoded message" - message - | Some msg -> return [msg]) - messages - in - return @@ List.flatten messages - | _messages -> assert false) - in - let* _, src_pk, src_sk = Client_keys.get_key cctxt source in - let* _res = - sc_rollup_add_messages - cctxt - ~chain:cctxt#chain - ~block:cctxt#block - ?dry_run:(Some dry_run) - ?verbose_signing:(Some verbose_signing) - ?fee - ?gas_limit - ?safety_guard - ?storage_limit - ?counter - ?confirmations:cctxt#confirmations - ~simulation - ~source - ~messages - ~src_pk - ~src_sk - ~fee_parameter - () - in - return_unit); - command - ~group - ~desc:"Publish a commitment for a smart rollup" - (args7 - fee_arg - dry_run_switch - verbose_signing_switch - simulate_switch - storage_limit_arg - counter_arg - fee_parameter_args) - (prefixes ["publish"; "commitment"] - @@ prefixes ["from"] - @@ Client_keys.Public_key_hash.source_param - ~name:"src" - ~desc:"Name of the source contract." - @@ prefixes ["for"; "smart"; "rollup"] - @@ Sc_rollup_params.sc_rollup_address_param - ~desc: - "The address of the smart rollup where the commitment will be \ - published." - @@ prefixes ["with"; "compressed"; "state"] - @@ param - ~name:"compressed_state" - ~desc:"The compressed state of the smart rollup for the commitment." - Sc_rollup_params.compressed_state_parameter - @@ prefixes ["at"; "inbox"; "level"] - @@ param - ~name:"inbox_level" - ~desc:"The inbox level for the commitment." - (raw_level_parameter ()) - @@ prefixes ["and"; "predecessor"] - @@ param - ~name:"predecessor" - ~desc:"The hash of the commitment's predecessor" - Sc_rollup_params.commitment_hash_parameter - @@ prefixes ["and"; "number"; "of"; "ticks"] - @@ param - ~name:"number_of_ticks" - ~desc:"The number of ticks for the commitment." - Sc_rollup_params.number_of_ticks_parameter - @@ stop) - (fun ( fee, - dry_run, - verbose_signing, - simulation, - storage_limit, - counter, - fee_parameter ) - source - rollup - compressed_state - inbox_level - predecessor - number_of_ticks - cctxt -> - let open Lwt_result_syntax in - let* _, src_pk, src_sk = Client_keys.get_key cctxt source in - let commitment : Alpha_context.Sc_rollup.Commitment.t = - {compressed_state; inbox_level; predecessor; number_of_ticks} - in - let* _res = - sc_rollup_publish - cctxt - ~chain:cctxt#chain - ~block:cctxt#block - ~dry_run - ~verbose_signing - ?fee - ?storage_limit - ?counter - ?confirmations:cctxt#confirmations - ~simulation - ~source - ~rollup - ~commitment - ~src_pk - ~src_sk - ~fee_parameter - () - in - return_unit); - command - ~group - ~desc:"Cement a commitment for a smart rollup." - (args7 - fee_arg - dry_run_switch - verbose_signing_switch - simulate_switch - storage_limit_arg - counter_arg - fee_parameter_args) - (prefixes ["cement"; "commitment"] - @@ param - ~name:"commitment" - ~desc:"The hash of the commitment to be cemented for a smart rollup." - Sc_rollup_params.commitment_hash_parameter - @@ prefixes ["from"] - @@ Client_keys.Public_key_hash.source_param - ~name:"src" - ~desc:"Name of the source contract." - @@ prefixes ["for"; "smart"; "rollup"] - @@ Sc_rollup_params.sc_rollup_address_param - ~desc: - "The address of the smart rollup of which the commitment will be \ - cemented." - @@ stop) - (fun ( fee, - dry_run, - verbose_signing, - simulation, - storage_limit, - counter, - fee_parameter ) - commitment - source - rollup - cctxt -> - let open Lwt_result_syntax in - let* _, src_pk, src_sk = Client_keys.get_key cctxt source in - let* _res = - sc_rollup_cement - cctxt - ~chain:cctxt#chain - ~block:cctxt#block - ~dry_run - ~verbose_signing - ?fee - ?storage_limit - ?counter - ?confirmations:cctxt#confirmations - ~simulation - ~source - ~rollup - ~commitment - ~src_pk - ~src_sk - ~fee_parameter - () - in - return_unit); - command - ~group - ~desc:"Timeout a staker from dispute on a smart rollup." - (args7 - fee_arg - dry_run_switch - verbose_signing_switch - simulate_switch - storage_limit_arg - counter_arg - fee_parameter_args) - (prefixes ["timeout"; "dispute"; "on"; "smart"; "rollup"] - @@ Sc_rollup_params.sc_rollup_address_param - ~desc: - "The address of the smart rollup where the staker of the dispute \ - has timed-out." - @@ prefixes ["with"] - @@ Client_keys.Public_key_hash.source_param - ~name:"staker1" - ~desc:"The staker that has timed out." - @@ prefixes ["against"] - @@ Client_keys.Public_key_hash.source_param - ~name:"staker2" - ~desc:"The opponent of this staker." - @@ prefixes ["from"] - @@ Client_keys.Public_key_hash.source_param - ~name:"src" - ~desc:"Name of the source contract." - @@ stop) - (fun ( fee, - dry_run, - verbose_signing, - simulation, - storage_limit, - counter, - fee_parameter ) - rollup - staker1 - staker2 - source - cctxt -> - let open Lwt_result_syntax in - let* games = - Plugin.RPC.Sc_rollup.ongoing_refutation_games - cctxt - (cctxt#chain, cctxt#block) - rollup - staker1 - in - let* alice, bob = - let* answer = - List.find_es - (fun (_, alice, bob) -> - let stakers = Sc_rollup.Game.Index.make staker1 staker2 in - return - Signature.Public_key_hash.( - alice = stakers.alice && bob = stakers.bob)) - games - in - match answer with - | None -> - cctxt#error - "Couldn't find an ongoing dispute for this staker on this \ - rollup." - | Some (_, alice, bob) -> return (alice, bob) - in - let* _, src_pk, src_sk = Client_keys.get_key cctxt source in - let* _res = - sc_rollup_timeout - cctxt - ~chain:cctxt#chain - ~block:cctxt#block - ~dry_run - ~verbose_signing - ?fee - ?storage_limit - ?counter - ?confirmations:cctxt#confirmations - ~simulation - ~source - ~rollup - ~alice - ~bob - ~src_pk - ~src_sk - ~fee_parameter - () - in - return_unit); - command - ~group - ~desc:"List originated smart rollups." - no_options - (prefixes ["list"; "smart"; "rollups"] @@ stop) - (fun () (cctxt : Protocol_client_context.full) -> - let open Lwt_result_syntax in - let* rollups = - Plugin.RPC.Sc_rollup.list cctxt (cctxt#chain, cctxt#block) - in - let*! () = - List.iter_s - (fun addr -> - cctxt#message "%s" (Sc_rollup.Address.to_b58check addr)) - rollups - in - return_unit); - command - ~group - ~desc: - "Execute a message from a smart rollup's outbox of a cemented \ - commitment." - (args7 - fee_arg - dry_run_switch - verbose_signing_switch - simulate_switch - fee_parameter_args - storage_limit_arg - counter_arg) - (prefixes ["execute"; "outbox"; "message"; "of"; "smart"; "rollup"] - @@ Sc_rollup_params.sc_rollup_address_param - ~desc:"The address of the smart rollup where the message resides." - @@ prefix "from" - @@ Client_keys.Public_key_hash.source_param - ~name:"source" - ~desc:"The account used for executing the outbox message." - @@ prefixes ["for"; "commitment"; "hash"] - @@ param - ~name:"cemented commitment" - ~desc:"The hash of the cemented commitment of the rollup." - Sc_rollup_params.commitment_hash_parameter - @@ prefixes ["and"; "output"; "proof"] - @@ param - ~name:"output proof" - ~desc: - "The output proof containing the outbox level, index and message." - bytes_parameter - @@ stop) - (fun ( fee, - dry_run, - verbose_signing, - simulation, - fee_parameter, - storage_limit, - counter ) - rollup - source - cemented_commitment - output_proof - cctxt -> - let open Lwt_result_syntax in - let* _, src_pk, src_sk = Client_keys.get_key cctxt source in - let* _res = - sc_rollup_execute_outbox_message - cctxt - ~chain:cctxt#chain - ~block:cctxt#block - ~dry_run - ~verbose_signing - ?fee - ?storage_limit - ?counter - ?confirmations:cctxt#confirmations - ~simulation - ~source - ~rollup - ~cemented_commitment - ~output_proof:(Bytes.to_string output_proof) - ~src_pk - ~src_sk - ~fee_parameter - () - in - return_unit); - command - ~group - ~desc:"Recover commitment bond from a smart rollup." - (args7 - fee_arg - dry_run_switch - verbose_signing_switch - simulate_switch - fee_parameter_args - storage_limit_arg - counter_arg) - (prefixes ["recover"; "bond"; "of"] - @@ Client_keys.Public_key_hash.source_param - ~name:"staker" - ~desc:"The implicit account that owns the frozen bond." - @@ prefixes ["for"; "smart"; "rollup"] - @@ Sc_rollup_params.sc_rollup_address_param - ~desc:"The address of the smart rollup of the bond." - @@ prefixes ["from"] - @@ Client_keys.Public_key_hash.source_param - ~name:"src" - ~desc:"The implicit account that triggers the operation." - @@ stop) - (fun ( fee, - dry_run, - verbose_signing, - simulation, - fee_parameter, - storage_limit, - counter ) - staker - sc_rollup - source - cctxt -> - let open Lwt_result_syntax in - let* _, src_pk, src_sk = Client_keys.get_key cctxt source in - let* _res = - sc_rollup_recover_bond - cctxt - ~chain:cctxt#chain - ~block:cctxt#block - ~dry_run - ~verbose_signing - ?fee - ?storage_limit - ?counter - ?confirmations:cctxt#confirmations - ~simulation - ~source - ~src_pk - ~src_sk - ~fee_parameter - ~sc_rollup - ~staker - () - in - return_unit); - ] - -let commands network () = - commands_rw () @ commands_network network () @ commands_ro () +let commands _network () = commands_ro () diff --git a/src/proto_alpha/lib_client_commands/client_proto_context_commands.ml b/src/proto_alpha/lib_client_commands/client_proto_context_commands.ml index aed69a798ad1da1a3d4a58c64cb5b3ead03b470f..5a485d15ab3c9c51ec7224b391d8284571e1d0d5 100644 --- a/src/proto_alpha/lib_client_commands/client_proto_context_commands.ml +++ b/src/proto_alpha/lib_client_commands/client_proto_context_commands.ml @@ -61,7 +61,7 @@ let save_zk_rollup ~force (cctxt : #Client_context.full) alias_name rollup = let*! () = cctxt#message "Epoxy rollup memorized as %s" alias_name in return_unit -let encrypted_switch = +let encrypted_switch : (_, Protocol_client_context.full) Tezos_clic.arg = Tezos_clic.switch ~long:"encrypted" ~doc:"encrypt the key on-disk" () let normalize_types_switch = @@ -847,6 +847,19 @@ let commands_ro () = return_unit); ] +let dry_run_switch : (_, Protocol_client_context.full) Tezos_clic.arg = + Tezos_clic.switch + ~long:"dry-run" + ~short:'D' + ~doc:"don't inject the operation, just display it" + () + +let verbose_signing_switch : (_, Protocol_client_context.full) Tezos_clic.arg = + Tezos_clic.switch + ~long:"verbose-signing" + ~doc:"display extra information before signing the operation" + () + (* ----------------------------------------------------------------------------*) (* After the activation of a new version of the protocol, the older protocols are only kept in the code base to replay the history of the chain and to query @@ -872,19 +885,6 @@ let commands_ro () = is then exported in the mli file. *) (* ----------------------------------------------------------------------------*) -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"