snapshot.rs (2183B)
1 use super::{InventoryCheckpointRef, OperationError}; 2 use radroots_domain::stock::{ObligationBacking, PoolView}; 3 4 /// Current selected-executor physical stock and its pool-backed installed 5 /// obligations at one confirmed inventory checkpoint. Preparatory claims and 6 /// never-stock-backed future promises are not installed obligation totals. 7 /// This metadata grants no authority, completeness beyond this pool, or effect. 8 #[derive(Clone, Eq, PartialEq)] 9 pub struct StockSnapshot { 10 pool: PoolView, 11 installed: ObligationBacking, 12 checkpoint: InventoryCheckpointRef, 13 } 14 impl StockSnapshot { 15 /// Reconstructs checked metadata only. The qualified store must authenticate 16 /// original allocations, current backing, permissions and the final fence. 17 pub fn from_host_metadata( 18 pool: PoolView, 19 installed: ObligationBacking, 20 checkpoint: InventoryCheckpointRef, 21 ) -> Result<Self, OperationError> { 22 let physical = pool.snapshot().balances().physical(); 23 let held = physical 24 .committed_hold 25 .checked_add(physical.physical_quarantine) 26 .map_err(|_| OperationError::RecoveryRequired)?; 27 if pool.snapshot().version().get() == 0 28 || checkpoint.revision().get() == 0 29 || installed.remaining() > pool.snapshot().balances().introduced() 30 || installed.backed() > held 31 { 32 return Err(OperationError::RecoveryRequired); 33 } 34 Ok(Self { 35 pool, 36 installed, 37 checkpoint, 38 }) 39 } 40 pub const fn pool(&self) -> &PoolView { 41 &self.pool 42 } 43 /// Remaining = backed + deficit for known pool-backed installed obligations. 44 /// Pending issuance risk remains represented by the physical held categories. 45 pub const fn installed_obligations(&self) -> ObligationBacking { 46 self.installed 47 } 48 pub const fn checkpoint(&self) -> InventoryCheckpointRef { 49 self.checkpoint 50 } 51 } 52 impl core::fmt::Debug for StockSnapshot { 53 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { 54 f.write_str("StockSnapshot(<private current metadata>)") 55 } 56 }