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> Inject for ProgramID<A> {
38 type Primitive = console::ProgramID<A::Network>;
39
40 fn new(_: Mode, id: Self::Primitive) -> Self {
42 Self {
43 name: Identifier::new(Mode::Constant, *id.name()),
44 network: Identifier::new(Mode::Constant, *id.network()),
45 }
46 }
47}
48
49impl<A: Aleo> ProgramID<A> {
50 #[inline]
52 pub const fn name(&self) -> &Identifier<A> {
53 &self.name
54 }
55
56 #[inline]
58 pub const fn network(&self) -> &Identifier<A> {
59 &self.network
60 }
61}
62
63impl<A: Aleo> Eject for ProgramID<A> {
64 type Primitive = console::ProgramID<A::Network>;
65
66 fn eject_mode(&self) -> Mode {
68 Mode::Constant
69 }
70
71 fn eject_value(&self) -> Self::Primitive {
73 match console::ProgramID::try_from((self.name.eject_value(), self.network.eject_value())) {
74 Ok(id) => id,
75 Err(error) => A::halt(format!("Failed to eject program ID: {error}")),
76 }
77 }
78}
79
80impl<A: Aleo> Equal<Self> for ProgramID<A> {
81 type Output = Boolean<A>;
82
83 fn is_equal(&self, other: &Self) -> Self::Output {
85 self.name.is_equal(&other.name) & (self.network.is_equal(&other.network))
86 }
87
88 fn is_not_equal(&self, other: &Self) -> Self::Output {
90 self.name.is_not_equal(&other.name) | (self.network.is_not_equal(&other.network))
91 }
92}