aleo_development_server/
cli.rs

1// Copyright (C) 2019-2023 Aleo Systems Inc.
2// This file is part of the Aleo SDK library.
3
4// The Aleo SDK library is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8
9// The Aleo SDK library is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13
14// You should have received a copy of the GNU General Public License
15// along with the Aleo SDK library. If not, see <https://www.gnu.org/licenses/>.
16
17use super::*;
18use clap::Parser;
19
20/// The Aleo Development Server is a tool to help developers build and deploy Aleo
21/// programs. The server is built in Rust and performs the proving and verification
22/// operations required to deploy and execute Aleo programs. Once it has performed
23/// these operations, the resulting deployments or executions will be broadcast to the
24/// Aleo Network. The server receives the information necessary to deploy and execute
25/// programs from the user via a REST API. Developers can use any language of choice
26/// (javascript, python, etc..) to send RESTful requests to the server. This server is
27/// meant to be used in trusted contexts such as local dev environments or a trusted
28/// private network within a cloud environment, etc. and should not be used to create
29/// a public API. A javascript client for this server is available in the Aleo SDK -
30/// <https://www.npmjs.com/package/@aleohq/sdk>
31#[derive(Debug, Parser)]
32#[clap(name = "Aleo Development Server", author = "The Aleo Team <hello@aleo.org>")]
33pub struct CLI {
34    /// Development Server subcommands
35    #[clap(subcommand)]
36    pub command: Command,
37}
38
39#[derive(Debug, Parser)]
40pub enum Command {
41    /// Start the development server - `aleo-develop start --help` for usage info
42    Start {
43        /// Optional `private key ciphertext` to start the development server with.
44        /// If this is provided to the server on startup, the server will store this
45        /// ciphertext in memory and look for an optional `password` field in the
46        /// json body of the deploy, execute, and transfer requests it receives. If
47        /// the `password` field is found in a request, it will attempt to use it
48        /// to decrypt the `private key ciphertext` into a `private key` and use the
49        /// `private key` to create program deployment and execution transactions on
50        /// the Aleo Network.
51        #[clap(short, long)]
52        key_ciphertext: Option<Ciphertext<Testnet3>>,
53        /// Uri and port the development server will listen on [default: 0.0.0.0:4040]
54        #[clap(short = 'a', long)]
55        server_address: Option<SocketAddr>,
56        /// Aleo Network peer uri to connect to [default: https://vm.aleo.org/api].
57        /// This is the peer the development server will send its completed deploy
58        /// and execute transactions to. The peer must be running the testnet3 api
59        /// <https://developer.aleo.org/testnet/getting_started/overview/> in order
60        /// for the development server to successfully send transactions to the Aleo
61        /// Network.
62        #[clap(short, long)]
63        peer: Option<String>,
64        /// Start the server with debug logging enabled [default: false]
65        #[clap(short, long)]
66        debug: bool,
67    },
68}
69
70impl Command {
71    pub fn parse(self) -> Result<Rest<Testnet3>> {
72        match self {
73            Command::Start { server_address, key_ciphertext: key, peer, debug } => {
74                Rest::initialize(server_address, key, peer, debug)
75            }
76        }
77    }
78}