1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
mod bytes;
mod serialize;
mod string;
use crate::{Certificate, Program, VerifyingKey};
use console::{
network::prelude::*,
program::{Identifier, ProgramID},
};
use indexmap::IndexMap;
#[derive(Clone, PartialEq, Eq)]
pub struct Deployment<N: Network> {
edition: u16,
program: Program<N>,
verifying_keys: IndexMap<Identifier<N>, (VerifyingKey<N>, Certificate<N>)>,
}
impl<N: Network> Deployment<N> {
pub fn new(
edition: u16,
program: Program<N>,
verifying_keys: IndexMap<Identifier<N>, (VerifyingKey<N>, Certificate<N>)>,
) -> Result<Self> {
Ok(Self { edition, program, verifying_keys })
}
pub const fn edition(&self) -> u16 {
self.edition
}
pub const fn program(&self) -> &Program<N> {
&self.program
}
pub const fn program_id(&self) -> &ProgramID<N> {
self.program.id()
}
pub const fn verifying_keys(&self) -> &IndexMap<Identifier<N>, (VerifyingKey<N>, Certificate<N>)> {
&self.verifying_keys
}
}
#[cfg(test)]
pub(crate) mod test_helpers {
use super::*;
use crate::{Process, Program};
use console::network::Testnet3;
use once_cell::sync::OnceCell;
type CurrentNetwork = Testnet3;
type CurrentAleo = circuit::network::AleoV0;
pub(crate) fn sample_deployment() -> Deployment<CurrentNetwork> {
static INSTANCE: OnceCell<Deployment<CurrentNetwork>> = OnceCell::new();
INSTANCE
.get_or_init(|| {
let (string, program) = Program::<CurrentNetwork>::parse(
r"
program testing.aleo;
function compute:
input r0 as u32.private;
input r1 as u32.public;
add r0 r1 into r2;
output r2 as u32.public;",
)
.unwrap();
assert!(string.is_empty(), "Parser did not consume all of the string: '{string}'");
let rng = &mut test_crypto_rng();
let process = Process::load().unwrap();
process.deploy::<CurrentAleo, _>(&program, rng).unwrap()
})
.clone()
}
}