https://gitlab.com/tezos/tezos
Raw File
Tip revision: 6d193fe1a62dd11f28202d59c4d58beb336108b8 authored by Thomas Letan on 28 July 2022, 13:55:47 UTC
tmp
Tip revision: 6d193fe
main_dal.ml
(*****************************************************************************)
(*                                                                           *)
(* Open Source License                                                       *)
(* Copyright (c) 2022 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.                                                 *)
(*                                                                           *)
(*****************************************************************************)

let group =
  {Clic.name = "dal-daemon"; title = "Commands related to the DAL daemon"}

let data_dir_arg =
  let default = Configuration.default_data_dir in
  Clic.default_arg
    ~long:"data-dir"
    ~placeholder:"data-dir"
    ~doc:
      (Format.sprintf
         "The path to the DAL daemon data directory. Default value is %s"
         default)
    ~default
    (Client_config.string_parameter ())

let rpc_addr_arg =
  let default = Configuration.default_rpc_addr in
  Clic.default_arg
    ~long:"rpc-addr"
    ~placeholder:"rpc-address|ip"
    ~doc:
      (Format.sprintf
         "The address the smart-contract rollup node listens to. Default value \
          is %s"
         default)
    ~default
    (Client_config.string_parameter ())

let int_parameter =
  let open Clic in
  parameter (fun _ p ->
      try Lwt.return_ok (int_of_string p) with _ -> failwith "Cannot read int")

let rpc_port_arg =
  let default = Configuration.default_rpc_port |> string_of_int in
  Clic.default_arg
    ~long:"rpc-port"
    ~placeholder:"rpc-port"
    ~doc:
      (Format.sprintf
         "The port the smart-contract rollup node listens to. Default value is \
          %s"
         default)
    ~default
    int_parameter

let no_trusted_setup_arg =
  Clic.switch
    ~long:"no-trusted-setup"
    ~doc:(Format.sprintf "Allow the DAL Node to run without trusted setup")
    ()

let config_init_command =
  let open Lwt_result_syntax in
  let open Clic in
  command
    ~group
    ~desc:"Configure DAL node."
    (args3 data_dir_arg rpc_addr_arg rpc_port_arg)
    (prefixes ["init-config"] stop)
    (fun (data_dir, rpc_addr, rpc_port) cctxt ->
      let open Configuration in
      let config = {data_dir; rpc_addr; rpc_port} in
      let* () = save config in
      let*! _ =
        cctxt#message "DAL node configuration written in %s" (filename config)
      in
      return ())

let run_command =
  let open Clic in
  command
    ~group
    ~desc:"Run the DAL daemon."
    (args2 data_dir_arg no_trusted_setup_arg)
    (prefixes ["run"] @@ stop)
    (fun (data_dir, no_trusted_setup) cctxt ->
      Daemon.run ~data_dir ~no_trusted_setup cctxt)

let commands () = [run_command; config_init_command]

let select_commands _ _ =
  let open Lwt_result_syntax in
  return (commands ())

let () = Client_main_run.run (module Client_config) ~select_commands
back to top