deploy.rs
1 // Copyright (c) 2025 ADnet Contributors 2 // This file is part of the AlphaVM library. 3 4 // Licensed under the Apache License, Version 2.0 (the "License"); 5 // you may not use this file except in compliance with the License. 6 // You may obtain a copy of the License at: 7 8 // http://www.apache.org/licenses/LICENSE-2.0 9 10 // Unless required by applicable law or agreed to in writing, software 11 // distributed under the License is distributed on an "AS IS" BASIS, 12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 // See the License for the specific language governing permissions and 14 // limitations under the License. 15 16 use super::*; 17 18 impl<N: Network> Process<N> { 19 /// Deploys the given program ID, if it does not exist. 20 #[inline] 21 pub fn deploy<A: circuit::Aleo<Network = N>, R: Rng + CryptoRng>( 22 &self, 23 program: &Program<N>, 24 rng: &mut R, 25 ) -> Result<Deployment<N>> { 26 let timer = timer!("Process::deploy"); 27 28 // Compute the stack. 29 let stack = Stack::new(self, program)?; 30 lap!(timer, "Compute the stack"); 31 32 // Return the deployment. 33 let deployment = stack.deploy::<A, R>(rng); 34 lap!(timer, "Construct the deployment"); 35 36 finish!(timer); 37 38 deployment 39 } 40 41 /// Adds the newly-deployed program. 42 /// This method assumes the given deployment **is valid**. 43 #[inline] 44 pub fn load_deployment(&mut self, deployment: &Deployment<N>) -> Result<()> { 45 let timer = timer!("Process::load_deployment"); 46 47 // Compute the program stack. 48 let mut stack = Stack::new(self, deployment.program())?; 49 lap!(timer, "Compute the stack"); 50 51 // Set the program owner. 52 // Note: The program owner is only enforced to be `Some` after `ConsensusVersion::V9` 53 // and is `None` for all programs deployed before the `V9` migration. 54 stack.set_program_owner(deployment.program_owner()); 55 56 // Insert the verifying keys. 57 for (function_name, (verifying_key, _)) in deployment.verifying_keys() { 58 stack.insert_verifying_key(function_name, verifying_key.clone())?; 59 } 60 lap!(timer, "Insert the verifying keys"); 61 62 // Add the stack to the process. 63 self.add_stack(stack); 64 65 finish!(timer); 66 67 Ok(()) 68 } 69 }