#[cfg(test)]
use snarkvm_circuit_types::environment::assert_scope;
mod to_address;
mod to_bits;
mod to_fields;
use crate::Identifier;
use snarkvm_circuit_network::Aleo;
use snarkvm_circuit_types::{Address, Boolean, Field, environment::prelude::*};
#[derive(Clone)]
pub struct ProgramID<A: Aleo> {
name: Identifier<A>,
network: Identifier<A>,
}
#[cfg(feature = "console")]
impl<A: Aleo> Inject for ProgramID<A> {
type Primitive = console::ProgramID<A::Network>;
fn new(_: Mode, id: Self::Primitive) -> Self {
Self {
name: Identifier::new(Mode::Constant, *id.name()),
network: Identifier::new(Mode::Constant, *id.network()),
}
}
}
impl<A: Aleo> ProgramID<A> {
#[inline]
pub const fn name(&self) -> &Identifier<A> {
&self.name
}
#[inline]
pub const fn network(&self) -> &Identifier<A> {
&self.network
}
}
#[cfg(feature = "console")]
impl<A: Aleo> Eject for ProgramID<A> {
type Primitive = console::ProgramID<A::Network>;
fn eject_mode(&self) -> Mode {
Mode::Constant
}
fn eject_value(&self) -> Self::Primitive {
match console::ProgramID::try_from((self.name.eject_value(), self.network.eject_value())) {
Ok(id) => id,
Err(error) => A::halt(format!("Failed to eject program ID: {error}")),
}
}
}
impl<A: Aleo> Equal<Self> for ProgramID<A> {
type Output = Boolean<A>;
fn is_equal(&self, other: &Self) -> Self::Output {
self.name.is_equal(&other.name) & (self.network.is_equal(&other.network))
}
fn is_not_equal(&self, other: &Self) -> Self::Output {
self.name.is_not_equal(&other.name) | (self.network.is_not_equal(&other.network))
}
}