snarkvm_ledger_store/helpers/memory/
transaction.rsuse crate::{
DeploymentStorage,
DeploymentStore,
ExecutionStorage,
ExecutionStore,
FeeStorage,
FeeStore,
TransactionStorage,
TransactionType,
TransitionStore,
helpers::memory::{MemoryMap, TransitionMemory},
};
use console::{
prelude::*,
program::{Identifier, ProgramID, ProgramOwner},
};
use synthesizer_program::Program;
use synthesizer_snark::{Certificate, Proof, VerifyingKey};
#[derive(Clone)]
pub struct TransactionMemory<N: Network> {
id_map: MemoryMap<N::TransactionID, TransactionType>,
deployment_store: DeploymentStore<N, DeploymentMemory<N>>,
execution_store: ExecutionStore<N, ExecutionMemory<N>>,
fee_store: FeeStore<N, FeeMemory<N>>,
}
#[rustfmt::skip]
impl<N: Network> TransactionStorage<N> for TransactionMemory<N> {
type IDMap = MemoryMap<N::TransactionID, TransactionType>;
type DeploymentStorage = DeploymentMemory<N>;
type ExecutionStorage = ExecutionMemory<N>;
type FeeStorage = FeeMemory<N>;
type TransitionStorage = TransitionMemory<N>;
fn open(transition_store: TransitionStore<N, Self::TransitionStorage>) -> Result<Self> {
let fee_store = FeeStore::<N, FeeMemory<N>>::open(transition_store)?;
let deployment_store = DeploymentStore::<N, DeploymentMemory<N>>::open(fee_store.clone())?;
let execution_store = ExecutionStore::<N, ExecutionMemory<N>>::open(fee_store.clone())?;
Ok(Self { id_map: MemoryMap::default(), deployment_store, execution_store, fee_store })
}
fn id_map(&self) -> &Self::IDMap {
&self.id_map
}
fn deployment_store(&self) -> &DeploymentStore<N, Self::DeploymentStorage> {
&self.deployment_store
}
fn execution_store(&self) -> &ExecutionStore<N, Self::ExecutionStorage> {
&self.execution_store
}
fn fee_store(&self) -> &FeeStore<N, Self::FeeStorage> {
&self.fee_store
}
}
#[derive(Clone)]
#[allow(clippy::type_complexity)]
pub struct DeploymentMemory<N: Network> {
id_map: MemoryMap<N::TransactionID, ProgramID<N>>,
edition_map: MemoryMap<ProgramID<N>, u16>,
reverse_id_map: MemoryMap<(ProgramID<N>, u16), N::TransactionID>,
owner_map: MemoryMap<(ProgramID<N>, u16), ProgramOwner<N>>,
program_map: MemoryMap<(ProgramID<N>, u16), Program<N>>,
verifying_key_map: MemoryMap<(ProgramID<N>, Identifier<N>, u16), VerifyingKey<N>>,
certificate_map: MemoryMap<(ProgramID<N>, Identifier<N>, u16), Certificate<N>>,
fee_store: FeeStore<N, FeeMemory<N>>,
}
#[rustfmt::skip]
impl<N: Network> DeploymentStorage<N> for DeploymentMemory<N> {
type IDMap = MemoryMap<N::TransactionID, ProgramID<N>>;
type EditionMap = MemoryMap<ProgramID<N>, u16>;
type ReverseIDMap = MemoryMap<(ProgramID<N>, u16), N::TransactionID>;
type OwnerMap = MemoryMap<(ProgramID<N>, u16), ProgramOwner<N>>;
type ProgramMap = MemoryMap<(ProgramID<N>, u16), Program<N>>;
type VerifyingKeyMap = MemoryMap<(ProgramID<N>, Identifier<N>, u16), VerifyingKey<N>>;
type CertificateMap = MemoryMap<(ProgramID<N>, Identifier<N>, u16), Certificate<N>>;
type FeeStorage = FeeMemory<N>;
fn open(fee_store: FeeStore<N, Self::FeeStorage>) -> Result<Self> {
Ok(Self {
id_map: MemoryMap::default(),
edition_map: MemoryMap::default(),
reverse_id_map: MemoryMap::default(),
owner_map: MemoryMap::default(),
program_map: MemoryMap::default(),
verifying_key_map: MemoryMap::default(),
certificate_map: MemoryMap::default(),
fee_store,
})
}
fn id_map(&self) -> &Self::IDMap {
&self.id_map
}
fn edition_map(&self) -> &Self::EditionMap {
&self.edition_map
}
fn reverse_id_map(&self) -> &Self::ReverseIDMap {
&self.reverse_id_map
}
fn owner_map(&self) -> &Self::OwnerMap {
&self.owner_map
}
fn program_map(&self) -> &Self::ProgramMap {
&self.program_map
}
fn verifying_key_map(&self) -> &Self::VerifyingKeyMap {
&self.verifying_key_map
}
fn certificate_map(&self) -> &Self::CertificateMap {
&self.certificate_map
}
fn fee_store(&self) -> &FeeStore<N, Self::FeeStorage> {
&self.fee_store
}
}
#[derive(Clone)]
#[allow(clippy::type_complexity)]
pub struct ExecutionMemory<N: Network> {
id_map: MemoryMap<N::TransactionID, (Vec<N::TransitionID>, bool)>,
reverse_id_map: MemoryMap<N::TransitionID, N::TransactionID>,
inclusion_map: MemoryMap<N::TransactionID, (N::StateRoot, Option<Proof<N>>)>,
fee_store: FeeStore<N, FeeMemory<N>>,
}
#[rustfmt::skip]
impl<N: Network> ExecutionStorage<N> for ExecutionMemory<N> {
type IDMap = MemoryMap<N::TransactionID, (Vec<N::TransitionID>, bool)>;
type ReverseIDMap = MemoryMap<N::TransitionID, N::TransactionID>;
type InclusionMap = MemoryMap<N::TransactionID, (N::StateRoot, Option<Proof<N>>)>;
type FeeStorage = FeeMemory<N>;
fn open(fee_store: FeeStore<N, Self::FeeStorage>) -> Result<Self> {
Ok(Self {
id_map: MemoryMap::default(),
reverse_id_map: MemoryMap::default(),
inclusion_map: MemoryMap::default(),
fee_store
})
}
fn id_map(&self) -> &Self::IDMap {
&self.id_map
}
fn reverse_id_map(&self) -> &Self::ReverseIDMap {
&self.reverse_id_map
}
fn inclusion_map(&self) -> &Self::InclusionMap {
&self.inclusion_map
}
fn fee_store(&self) -> &FeeStore<N, Self::FeeStorage> {
&self.fee_store
}
}
#[derive(Clone)]
#[allow(clippy::type_complexity)]
pub struct FeeMemory<N: Network> {
fee_map: MemoryMap<N::TransactionID, (N::TransitionID, N::StateRoot, Option<Proof<N>>)>,
reverse_fee_map: MemoryMap<N::TransitionID, N::TransactionID>,
transition_store: TransitionStore<N, TransitionMemory<N>>,
}
#[rustfmt::skip]
impl<N: Network> FeeStorage<N> for FeeMemory<N> {
type FeeMap = MemoryMap<N::TransactionID, (N::TransitionID, N::StateRoot, Option<Proof<N>>)>;
type ReverseFeeMap = MemoryMap<N::TransitionID, N::TransactionID>;
type TransitionStorage = TransitionMemory<N>;
fn open(transition_store: TransitionStore<N, Self::TransitionStorage>) -> Result<Self> {
Ok(Self {
fee_map: MemoryMap::default(),
reverse_fee_map: MemoryMap::default(),
transition_store,
})
}
fn fee_map(&self) -> &Self::FeeMap {
&self.fee_map
}
fn reverse_fee_map(&self) -> &Self::ReverseFeeMap {
&self.reverse_fee_map
}
fn transition_store(&self) -> &TransitionStore<N, Self::TransitionStorage> {
&self.transition_store
}
}