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
37impl<A: Aleo> ProgramID<A> {
38 pub fn constant(id: console::ProgramID<A::Network>) -> Self {
40 Self { name: Identifier::constant(*id.name()), network: Identifier::constant(*id.network()) }
41 }
42
43 pub fn public(id: console::ProgramID<A::Network>) -> Self {
46 Self { name: Identifier::public(*id.name()), network: Identifier::public(*id.network()) }
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
64impl<A: Aleo> Eject for ProgramID<A> {
65 type Primitive = console::ProgramID<A::Network>;
66
67 fn eject_mode(&self) -> Mode {
69 Mode::Constant
70 }
71
72 fn eject_value(&self) -> Self::Primitive {
74 match console::ProgramID::try_from((self.name.eject_value(), self.network.eject_value())) {
75 Ok(id) => id,
76 Err(error) => A::halt(format!("Failed to eject program ID: {error}")),
77 }
78 }
79}
80
81impl<A: Aleo> Equal<Self> for ProgramID<A> {
82 type Output = Boolean<A>;
83
84 fn is_equal(&self, other: &Self) -> Self::Output {
86 self.name.is_equal(&other.name) & (self.network.is_equal(&other.network))
87 }
88
89 fn is_not_equal(&self, other: &Self) -> Self::Output {
91 self.name.is_not_equal(&other.name) | (self.network.is_not_equal(&other.network))
92 }
93}