snarkvm_circuit_program/data/future/
mod.rs

1// Copyright (c) 2019-2025 Provable Inc.
2// This file is part of the snarkVM 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
16mod argument;
17pub use argument::Argument;
18
19mod equal;
20mod find;
21mod to_bits;
22mod to_fields;
23
24use crate::{Access, Identifier, Plaintext, ProgramID, Value};
25use snarkvm_circuit_network::Aleo;
26use snarkvm_circuit_types::{Boolean, Field, U16, environment::prelude::*};
27
28/// A future.
29#[derive(Clone)]
30pub struct Future<A: Aleo> {
31    /// The program ID.
32    program_id: ProgramID<A>,
33    /// The name of the function.
34    function_name: Identifier<A>,
35    /// The arguments.
36    arguments: Vec<Argument<A>>,
37}
38
39impl<A: Aleo> Inject for Future<A> {
40    type Primitive = console::Future<A::Network>;
41
42    /// Initializes a circuit of the given mode and future.
43    fn new(mode: Mode, value: Self::Primitive) -> Self {
44        Self::from(
45            Inject::new(mode, *value.program_id()),
46            Inject::new(mode, *value.function_name()),
47            Inject::new(mode, value.arguments().to_vec()),
48        )
49    }
50}
51
52impl<A: Aleo> Eject for Future<A> {
53    type Primitive = console::Future<A::Network>;
54
55    /// Ejects the mode of the circuit future.
56    fn eject_mode(&self) -> Mode {
57        let program_id_mode = Eject::eject_mode(self.program_id());
58        let function_name_mode = Eject::eject_mode(self.function_name());
59        let inputs_mode = Eject::eject_mode(&self.inputs());
60        Mode::combine(Mode::combine(program_id_mode, function_name_mode), inputs_mode)
61    }
62
63    /// Ejects the circuit value.
64    fn eject_value(&self) -> Self::Primitive {
65        Self::Primitive::new(
66            Eject::eject_value(self.program_id()),
67            Eject::eject_value(self.function_name()),
68            self.inputs().iter().map(Eject::eject_value).collect(),
69        )
70    }
71}
72
73impl<A: Aleo> Future<A> {
74    /// Returns a future from the given program ID, function name, and arguments.
75    #[inline]
76    pub const fn from(program_id: ProgramID<A>, function_name: Identifier<A>, arguments: Vec<Argument<A>>) -> Self {
77        Self { program_id, function_name, arguments }
78    }
79
80    /// Returns the program ID.
81    #[inline]
82    pub const fn program_id(&self) -> &ProgramID<A> {
83        &self.program_id
84    }
85
86    /// Returns the name of the function.
87    #[inline]
88    pub const fn function_name(&self) -> &Identifier<A> {
89        &self.function_name
90    }
91
92    /// Returns the inputs.
93    #[inline]
94    pub fn inputs(&self) -> &[Argument<A>] {
95        &self.arguments
96    }
97}