snarkvm_circuit_program/id/
mod.rs1#[cfg(test)]
17use snarkvm_circuit_types::environment::assert_scope;
18
19mod to_address;
20mod to_bits;
21mod to_fields;
22
23use crate::Identifier;
24use snarkvm_circuit_network::Aleo;
25use snarkvm_circuit_types::{Address, Boolean, Field, environment::prelude::*};
26
27#[derive(Clone)]
30pub struct ProgramID<A: Aleo> {
31 name: Identifier<A>,
33 network: Identifier<A>,
35}
36
37#[cfg(feature = "console")]
38impl<A: Aleo> Inject for ProgramID<A> {
39 type Primitive = console::ProgramID<A::Network>;
40
41 fn new(_: Mode, id: Self::Primitive) -> Self {
43 Self {
44 name: Identifier::new(Mode::Constant, *id.name()),
45 network: Identifier::new(Mode::Constant, *id.network()),
46 }
47 }
48}
49
50impl<A: Aleo> ProgramID<A> {
51 #[inline]
53 pub const fn name(&self) -> &Identifier<A> {
54 &self.name
55 }
56
57 #[inline]
59 pub const fn network(&self) -> &Identifier<A> {
60 &self.network
61 }
62}
63
64#[cfg(feature = "console")]
65impl<A: Aleo> Eject for ProgramID<A> {
66 type Primitive = console::ProgramID<A::Network>;
67
68 fn eject_mode(&self) -> Mode {
70 Mode::Constant
71 }
72
73 fn eject_value(&self) -> Self::Primitive {
75 match console::ProgramID::try_from((self.name.eject_value(), self.network.eject_value())) {
76 Ok(id) => id,
77 Err(error) => A::halt(format!("Failed to eject program ID: {error}")),
78 }
79 }
80}
81
82impl<A: Aleo> Equal<Self> for ProgramID<A> {
83 type Output = Boolean<A>;
84
85 fn is_equal(&self, other: &Self) -> Self::Output {
87 self.name.is_equal(&other.name) & (self.network.is_equal(&other.network))
88 }
89
90 fn is_not_equal(&self, other: &Self) -> Self::Output {
92 self.name.is_not_equal(&other.name) | (self.network.is_not_equal(&other.network))
93 }
94}