snarkos_aot/auth/
auth_deploy.rs

1use anyhow::{Ok, Result};
2use clap::Args;
3use clap_stdin::FileOrStdin;
4use snarkvm::console::program::ProgramOwner;
5use snarkvm::synthesizer::{Process, Program};
6
7use super::args::AuthBlob;
8use super::query;
9use crate::Key;
10use crate::Network;
11
12/// Options for authorizing a program deployment.
13#[derive(Debug, Args)]
14pub struct AuthDeployOptions<N: Network> {
15    /// The query to use for the program.
16    #[clap(short, long)]
17    pub query: Option<String>,
18    /// The program to deploy.
19    /// This can be a file or stdin.
20    pub program: FileOrStdin<Program<N>>,
21}
22
23#[derive(Debug, Args)]
24pub struct AuthorizeDeploy<N: Network> {
25    #[clap(flatten)]
26    pub key: Key<N>,
27    #[clap(flatten)]
28    pub options: AuthDeployOptions<N>,
29    /// The seed to use for the authorization generation
30    #[clap(long)]
31    pub seed: Option<u64>,
32}
33
34impl<N: Network> AuthorizeDeploy<N> {
35    pub fn parse(self) -> Result<AuthBlob<N>> {
36        // get the program from the file (or stdin)
37        let program = self.options.program.clone().contents()?;
38        let mut process = Process::load()?;
39        query::get_process_imports(&mut process, &program, self.options.query.as_deref())?;
40
41        let deployment =
42            process.deploy::<N::Circuit, _>(&program, &mut super::rng_from_seed(self.seed))?;
43        let deployment_id = deployment.to_deployment_id()?;
44
45        let private_key = self.key.try_get()?;
46
47        // Construct the owner.
48        let owner = ProgramOwner::new(
49            &private_key,
50            deployment_id,
51            &mut super::rng_from_seed(self.seed),
52        )?;
53
54        Ok(AuthBlob::Deploy {
55            owner,
56            deployment,
57            fee_auth: None,
58        })
59    }
60}