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: Identifier<N>,
inputs: &[Value<N>],
rng: &mut R,
) -> Result<Authorization<N>> {
ensure!(!self.program.functions().is_empty(), "Program '{}' has no functions", self.program.id());
let function = self.get_function(&function_name)?;
let input_types = function.input_types();
if function.inputs().len() != input_types.len() {
bail!(
"Function '{function_name}' in program '{}' expects {} inputs, but {} types were found.",
self.program.id(),
function.inputs().len(),
input_types.len()
)
}
let request = Request::sign(private_key, *self.program.id(), function_name, inputs, &input_types, rng)?;
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, rng)?;
Ok(authorization)
}
}