truthlinked-state 0.1.0

State transition, account, cell, staking, oracle, MCP, and token logic for TruthLinked.
//! Truthlinked State Src Lib
//!
//! Owns the public crate surface and shared exports used by downstream components.
//! State changes are consensus-sensitive and must preserve deterministic execution and serialization.

pub mod cells;
pub mod constants;
pub mod log;
pub mod metrics;
pub mod parallel_executor;
pub mod pq_execution;
pub mod trth;
pub mod vm;

pub use log::Log;
pub use pq_execution::State;
pub use trth::{format_amount, parse_amount, TokenInfo};

// Genesis hash for genesis fingerprint
static GENESIS_HASH: std::sync::OnceLock<[u8; 32]> = std::sync::OnceLock::new();
static CURRENT_HEIGHT: std::sync::atomic::AtomicU64 = std::sync::atomic::AtomicU64::new(0);

pub fn set_genesis_hash(hash: [u8; 32]) {
    let _ = GENESIS_HASH.set(hash);
}

pub fn get_genesis_hash() -> [u8; 32] {
    *GENESIS_HASH.get().unwrap_or(&[0u8; 32])
}

pub fn set_current_height(height: u64) {
    CURRENT_HEIGHT.store(height, std::sync::atomic::Ordering::SeqCst);
}

pub fn get_current_height() -> Option<u64> {
    let height = CURRENT_HEIGHT.load(std::sync::atomic::Ordering::SeqCst);
    if height > 0 {
        Some(height)
    } else {
        None
    }
}

pub fn is_testnet() -> bool {
    let genesis = get_genesis_hash();
    genesis == [0u8; 32]
}
pub mod system_cells;