snarkvm_console_program/data/record/
mod.rsmod entry;
pub use entry::Entry;
mod helpers;
pub use helpers::Owner;
mod bytes;
mod decrypt;
mod encrypt;
mod equal;
mod find;
mod is_owner;
mod num_randomizers;
mod parse_ciphertext;
mod parse_plaintext;
mod serial_number;
mod serialize;
mod tag;
mod to_bits;
mod to_commitment;
mod to_fields;
use crate::{Access, Ciphertext, Identifier, Literal, Plaintext, ProgramID};
use snarkvm_console_account::{Address, PrivateKey, ViewKey};
use snarkvm_console_network::prelude::*;
use snarkvm_console_types::{Boolean, Field, Group, Scalar};
use indexmap::IndexMap;
#[derive(Clone)]
pub struct Record<N: Network, Private: Visibility> {
owner: Owner<N, Private>,
data: IndexMap<Identifier<N>, Entry<N, Private>>,
nonce: Group<N>,
}
impl<N: Network, Private: Visibility> Record<N, Private> {
pub fn from_plaintext(
owner: Owner<N, Plaintext<N>>,
data: IndexMap<Identifier<N>, Entry<N, Plaintext<N>>>,
nonce: Group<N>,
) -> Result<Record<N, Plaintext<N>>> {
let reserved = [Identifier::from_str("owner")?];
ensure!(!has_duplicates(data.keys().chain(reserved.iter())), "Found a duplicate entry name in a record");
ensure!(data.len() <= N::MAX_DATA_ENTRIES, "Found a record that exceeds size ({})", data.len());
Ok(Record { owner, data, nonce })
}
pub fn from_ciphertext(
owner: Owner<N, Ciphertext<N>>,
data: IndexMap<Identifier<N>, Entry<N, Ciphertext<N>>>,
nonce: Group<N>,
) -> Result<Record<N, Ciphertext<N>>> {
let reserved = [Identifier::from_str("owner")?];
ensure!(!has_duplicates(data.keys().chain(reserved.iter())), "Found a duplicate entry name in a record");
ensure!(data.len() <= N::MAX_DATA_ENTRIES, "Found a record that exceeds size ({})", data.len());
Ok(Record { owner, data, nonce })
}
}
impl<N: Network, Private: Visibility> Record<N, Private> {
pub const fn owner(&self) -> &Owner<N, Private> {
&self.owner
}
pub const fn data(&self) -> &IndexMap<Identifier<N>, Entry<N, Private>> {
&self.data
}
pub const fn nonce(&self) -> &Group<N> {
&self.nonce
}
}
impl<N: Network, Private: Visibility> Record<N, Private> {
pub fn into_owner(self) -> Owner<N, Private> {
self.owner
}
pub fn into_data(self) -> IndexMap<Identifier<N>, Entry<N, Private>> {
self.data
}
pub fn into_nonce(self) -> Group<N> {
self.nonce
}
}