namada_storage/
conversion_state.rs

1//! Shielded tokens conversion state
2
3use std::collections::BTreeMap;
4
5pub use namada_core::address::Address;
6use namada_core::borsh::{BorshDeserialize, BorshSerialize};
7pub use namada_core::masp::MaspEpoch;
8pub use namada_core::masp_primitives::asset_type::AssetType;
9pub use namada_core::masp_primitives::convert::AllowedConversion;
10pub use namada_core::masp_primitives::merkle_tree::FrozenCommitmentTree;
11pub use namada_core::masp_primitives::sapling::Node as SaplingNode;
12pub use namada_core::token::{Denomination, MaspDigitPos};
13use namada_macros::BorshDeserializer;
14#[cfg(feature = "migrations")]
15use namada_migrations::*;
16
17/// A representation of a leaf in the conversion tree
18#[derive(Debug, BorshSerialize, BorshDeserialize, BorshDeserializer)]
19pub struct ConversionLeaf {
20    /// The token associated with this asset type
21    pub token: Address,
22    /// The denomination associated with the above toke
23    pub denom: Denomination,
24    /// The digit position covered by this asset type
25    pub digit_pos: MaspDigitPos,
26    /// The masp epoch of the asset type
27    pub epoch: MaspEpoch,
28    /// The actual conversion and generator
29    pub conversion: AllowedConversion,
30    /// The position of this leaf in the conversion tree
31    pub leaf_pos: usize,
32}
33
34/// A representation of the conversion state
35#[derive(
36    Debug, Default, BorshSerialize, BorshDeserialize, BorshDeserializer,
37)]
38pub struct ConversionState {
39    /// The last amount of the native token distributed
40    #[deprecated = "Current native precision has been moved into the native \
41                    precision storage key."]
42    pub current_precision: Option<u128>,
43    /// The tree currently containing all the conversions
44    pub tree: FrozenCommitmentTree<SaplingNode>,
45    /// Map assets to their latest conversion and position in Merkle tree
46    pub assets: BTreeMap<AssetType, ConversionLeaf>,
47}
48
49/// Able to borrow conversion state.
50pub trait ReadConversionState {
51    /// Borrow immutable conversion state
52    fn conversion_state(&self) -> &ConversionState;
53}
54
55/// Able to borrow mutable conversion state.
56pub trait WithConversionState: ReadConversionState {
57    /// Borrow mutable conversion state
58    fn conversion_state_mut(&mut self) -> &mut ConversionState;
59}