1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
// Copyright (C) 2019-2023 Aleo Systems Inc.
// This file is part of the snarkVM library.
// The snarkVM library is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// The snarkVM library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with the snarkVM library. If not, see <https://www.gnu.org/licenses/>.
#[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::{environment::prelude::*, Address, Boolean, Field};
/// A program ID is of the form `{name}.{network}`.
/// If no `network`-level domain is specified, the default network is used.
#[derive(Clone)]
pub struct ProgramID<A: Aleo> {
/// The program name.
name: Identifier<A>,
/// The network-level domain (NLD).
network: Identifier<A>,
}
#[cfg(console)]
impl<A: Aleo> Inject for ProgramID<A> {
type Primitive = console::ProgramID<A::Network>;
/// Injects a program ID with the given primitive.
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> {
/// Returns the program name.
#[inline]
pub const fn name(&self) -> &Identifier<A> {
&self.name
}
/// Returns the network-level domain (NLD).
#[inline]
pub const fn network(&self) -> &Identifier<A> {
&self.network
}
}
#[cfg(console)]
impl<A: Aleo> Eject for ProgramID<A> {
type Primitive = console::ProgramID<A::Network>;
/// Ejects the mode of the program ID.
fn eject_mode(&self) -> Mode {
Mode::Constant
}
/// Ejects a program ID into a primitive.
fn eject_value(&self) -> Self::Primitive {
console::ProgramID::from((self.name.eject_value(), self.network.eject_value()))
}
}