use super::*;
impl<N: Network> Stack<N> {
#[inline]
pub fn authorize<A: circuit::Aleo<Network = N>, R: Rng + CryptoRng>(
&self,
private_key: &PrivateKey<N>,
function_name: impl TryInto<Identifier<N>>,
inputs: impl ExactSizeIterator<Item = impl TryInto<Value<N>>>,
rng: &mut R,
) -> Result<Authorization<N>> {
let timer = timer!("Stack::authorize");
let program_id = *self.program.id();
let function_name = function_name.try_into().map_err(|_| anyhow!("Invalid function name"))?;
let input_types = self.get_function(&function_name)?.input_types();
lap!(timer, "Retrieve the input types");
let is_root = true;
let caller = None;
let root_tvk = None;
let request =
Request::sign(private_key, program_id, function_name, inputs, &input_types, root_tvk, is_root, rng)?;
lap!(timer, "Compute the request");
let authorization = Authorization::new(request.clone());
let call_stack = CallStack::Authorize(vec![request], *private_key, authorization.clone());
let _response = self.execute_function::<A, R>(call_stack, caller, root_tvk, rng)?;
finish!(timer, "Construct the authorization from the function");
Ok(authorization)
}
}