snarkvm_console_program/locator/mod.rs
1// Copyright 2024 Aleo Network Foundation
2// This file is part of the snarkVM library.
3
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at:
7
8// http://www.apache.org/licenses/LICENSE-2.0
9
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15
16mod bytes;
17mod parse;
18mod serialize;
19mod to_fields;
20
21use crate::{Identifier, ProgramID};
22use snarkvm_console_network::prelude::*;
23use snarkvm_console_types::Field;
24
25/// A locator is of the form `{program_id}/{resource}` (i.e. `howard.aleo/notify`).
26#[derive(Copy, Clone, PartialEq, Eq, Hash)]
27pub struct Locator<N: Network> {
28 /// The program ID.
29 id: ProgramID<N>,
30 /// The program resource.
31 resource: Identifier<N>,
32}
33
34impl<N: Network> Locator<N> {
35 /// Initializes a locator from a program ID and resource.
36 pub const fn new(program_id: ProgramID<N>, resource: Identifier<N>) -> Self {
37 Self { id: program_id, resource }
38 }
39}
40
41impl<N: Network> Locator<N> {
42 /// Returns the program ID.
43 #[inline]
44 pub const fn program_id(&self) -> &ProgramID<N> {
45 &self.id
46 }
47
48 /// Returns the program name.
49 #[inline]
50 pub const fn name(&self) -> &Identifier<N> {
51 self.id.name()
52 }
53
54 /// Returns the network-level domain (NLD).
55 #[inline]
56 pub const fn network(&self) -> &Identifier<N> {
57 self.id.network()
58 }
59
60 /// Returns the resource name.
61 #[inline]
62 pub const fn resource(&self) -> &Identifier<N> {
63 &self.resource
64 }
65}