snarkvm_ledger_store/
lib.rs

1// Copyright (c) 2019-2025 Provable Inc.
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
16#![forbid(unsafe_code)]
17#![warn(clippy::cast_possible_truncation)]
18
19pub mod helpers;
20
21mod block;
22pub use block::*;
23
24mod consensus;
25pub use consensus::*;
26
27mod program;
28pub use program::*;
29
30mod transaction;
31pub use transaction::*;
32
33mod transition;
34pub use transition::*;
35
36#[macro_export]
37macro_rules! cow_to_copied {
38    ($cow:expr) => {
39        match $cow {
40            std::borrow::Cow::Borrowed(inner) => *inner,
41            std::borrow::Cow::Owned(inner) => inner,
42        }
43    };
44}
45
46#[macro_export]
47macro_rules! cow_to_cloned {
48    ($cow:expr) => {
49        match $cow {
50            std::borrow::Cow::Borrowed(inner) => (*inner).clone(),
51            std::borrow::Cow::Owned(inner) => inner,
52        }
53    };
54}
55
56use console::prelude::{Result, bail};
57
58#[derive(Copy, Clone, Debug, PartialEq, Eq)]
59pub enum FinalizeMode {
60    /// Invoke finalize as a real run.
61    RealRun,
62    /// Invoke finalize as a dry run.
63    DryRun,
64}
65
66impl FinalizeMode {
67    /// Returns the u8 value of the finalize mode.
68    #[inline]
69    pub const fn to_u8(self) -> u8 {
70        match self {
71            Self::RealRun => 0,
72            Self::DryRun => 1,
73        }
74    }
75
76    /// Returns a finalize mode from a given u8.
77    #[inline]
78    pub fn from_u8(value: u8) -> Result<Self> {
79        match value {
80            0 => Ok(Self::RealRun),
81            1 => Ok(Self::DryRun),
82            _ => bail!("Invalid finalize mode of '{value}'"),
83        }
84    }
85}