snarkvm_synthesizer_debug/vm/
authorize.rs1use super::*;
16
17impl<N: Network, C: ConsensusStorage<N>> VM<N, C> {
18 #[inline]
20 pub fn authorize<R: Rng + CryptoRng>(
21 &self,
22 private_key: &PrivateKey<N>,
23 program_id: impl TryInto<ProgramID<N>>,
24 function_name: impl TryInto<Identifier<N>>,
25 inputs: impl IntoIterator<IntoIter = impl ExactSizeIterator<Item = impl TryInto<Value<N>>>>,
26 rng: &mut R,
27 ) -> Result<Authorization<N>> {
28 let timer = timer!("VM::authorize");
29
30 let program_id = program_id.try_into().map_err(|_| anyhow!("Invalid program ID"))?;
32 let function_name = function_name.try_into().map_err(|_| anyhow!("Invalid function name"))?;
34 let inputs = inputs
36 .into_iter()
37 .enumerate()
38 .map(|(index, input)| {
39 input
40 .try_into()
41 .map_err(|_| anyhow!("Failed to parse input #{index} for '{program_id}/{function_name}'"))
42 })
43 .collect::<Result<Vec<_>>>()?;
44 lap!(timer, "Prepare inputs");
45
46 let result = self.authorize_raw(private_key, program_id, function_name, inputs, rng);
48 finish!(timer, "Authorize the call");
49 result
50 }
51
52 #[inline]
55 pub fn authorize_fee_private<R: Rng + CryptoRng>(
56 &self,
57 private_key: &PrivateKey<N>,
58 credits: Record<N, Plaintext<N>>,
59 base_fee_in_microcredits: u64,
60 priority_fee_in_microcredits: u64,
61 deployment_or_execution_id: Field<N>,
62 rng: &mut R,
63 ) -> Result<Authorization<N>> {
64 macro_rules! logic {
65 ($process:expr, $network:path, $aleo:path) => {{
66 let authorization = $process.authorize_fee_private::<$aleo, _>(
68 cast_ref!(&private_key as PrivateKey<$network>),
69 cast_ref!(credits as Record<$network, Plaintext<$network>>).clone(),
70 base_fee_in_microcredits,
71 priority_fee_in_microcredits,
72 *cast_ref!(deployment_or_execution_id as Field<$network>),
73 rng,
74 )?;
75 Ok(cast_ref!(authorization as Authorization<N>).clone())
77 }};
78 }
79
80 let timer = timer!("VM::authorize_fee_private");
82 let result = process!(self, logic);
83 finish!(timer, "Compute the authorization");
84 result
85 }
86
87 #[inline]
89 pub fn authorize_fee_public<R: Rng + CryptoRng>(
90 &self,
91 private_key: &PrivateKey<N>,
92 base_fee_in_microcredits: u64,
93 priority_fee_in_microcredits: u64,
94 deployment_or_execution_id: Field<N>,
95 rng: &mut R,
96 ) -> Result<Authorization<N>> {
97 macro_rules! logic {
98 ($process:expr, $network:path, $aleo:path) => {{
99 let authorization = $process.authorize_fee_public::<$aleo, _>(
101 cast_ref!(&private_key as PrivateKey<$network>),
102 base_fee_in_microcredits,
103 priority_fee_in_microcredits,
104 *cast_ref!(deployment_or_execution_id as Field<$network>),
105 rng,
106 )?;
107 Ok(cast_ref!(authorization as Authorization<N>).clone())
109 }};
110 }
111
112 let timer = timer!("VM::authorize_fee_public");
114 let result = process!(self, logic);
115 finish!(timer, "Compute the authorization");
116 result
117 }
118}
119
120impl<N: Network, C: ConsensusStorage<N>> VM<N, C> {
121 #[inline]
123 fn authorize_raw<R: Rng + CryptoRng>(
124 &self,
125 private_key: &PrivateKey<N>,
126 program_id: ProgramID<N>,
127 function_name: Identifier<N>,
128 inputs: Vec<Value<N>>,
129 rng: &mut R,
130 ) -> Result<Authorization<N>> {
131 macro_rules! logic {
132 ($process:expr, $network:path, $aleo:path) => {{
133 let authorization = $process.authorize::<$aleo, _>(
135 cast_ref!(&private_key as PrivateKey<$network>),
136 cast_ref!(program_id as ProgramID<$network>),
137 cast_ref!(function_name as Identifier<$network>),
138 cast_ref!(inputs as Vec<Value<$network>>).iter(),
139 rng,
140 )?;
141 Ok(cast_ref!(authorization as Authorization<N>).clone())
143 }};
144 }
145
146 let timer = timer!("VM::authorize_raw");
148 let result = process!(self, logic);
149 finish!(timer, "Compute the authorization");
150 result
151 }
152}