ledger_state.rs (1749B)
1 use std::{ 2 collections::{BTreeMap, BTreeSet}, 3 time::{SystemTime, UNIX_EPOCH}, 4 }; 5 6 use super::{ 7 Amount, Block, BurnTicket, FinalityCheckpoint, LaunchProfile, LineageOwnerValues, OutPoint, 8 Transaction, TransactionV2, TxOutput, UtxoLineageRoot, 9 }; 10 use crate::compact::CompactBlockContext; 11 12 #[derive(Clone, Debug)] 13 pub struct Ledger { 14 pub(super) chain: Vec<Block>, 15 pub(super) genesis_allocations: BTreeMap<String, Amount>, 16 pub(super) utxos: BTreeMap<OutPoint, TxOutput>, 17 pub(super) utxo_lineage: BTreeMap<OutPoint, UtxoLineageRoot>, 18 pub(super) lineage_values: BTreeMap<UtxoLineageRoot, Amount>, 19 pub(super) lineage_owners: LineageOwnerValues, 20 pub(super) tickets: Vec<BurnTicket>, 21 pub(super) mined_transaction_ids: BTreeSet<String>, 22 pub(super) pending: Vec<Transaction>, 23 pub(super) orphans: Vec<Transaction>, 24 pub(super) pending_bytes: usize, 25 pub(super) orphan_bytes: usize, 26 pub(super) pending_v2: Vec<TransactionV2>, 27 pub(super) pending_v2_bytes: usize, 28 pub(super) mine_reward: Amount, 29 /// PoW difficulty after each completed retarget window. Index zero is the 30 /// launch difficulty; index `n` is the difficulty at anchor height 31 /// `n * MINE_RETARGET_WINDOW_BLOCKS`. 32 pub(super) mine_difficulty_windows: Vec<u32>, 33 pub(super) initial_vdf_rounds: u64, 34 pub(super) vdf_rounds: u64, 35 pub(super) launch_profile: LaunchProfile, 36 pub(super) compact_block_context: CompactBlockContext, 37 pub(super) objective_finality_checkpoint: Option<FinalityCheckpoint>, 38 } 39 40 pub(super) fn unix_now_ms() -> u64 { 41 SystemTime::now() 42 .duration_since(UNIX_EPOCH) 43 .unwrap_or_default() 44 .as_millis() 45 .try_into() 46 .unwrap_or(u64::MAX) 47 }