moonproof-runtime 0.2.1

Wasm-friendly Compact contract runtime core — IR walker, IR-driven circuit executor, contract state, runtime values
Documentation
//! Compact-runtime-side zswap local state — the per-circuit-execution
//! view of "outputs the circuit just produced + inputs it spent + the
//! caller's coin public key".
//!
//! Port of the data shape of
//! `@midnight-ntwrk/midnight-js-protocol/compact-runtime`'s
//! `ZswapLocalState`. This is **distinct from** the wallet-side
//! `ZswapWalletState` (`moonproof_ledger::zswap::local::State`): the wallet
//! state tracks *received* coins after on-chain confirmation; this
//! state tracks *unsubmitted* coin moves emitted during circuit
//! execution.
//!
//! Lives in the runtime crate because the IR executor consumes it; the
//! lifecycle layer (`moonproof_contracts`) owns the translator that turns
//! it into a ledger-typed `UnprovenOffer`.

use moonproof_ledger::coin_structure::coin::{
    Info as CoinInfo, QualifiedInfo as QualifiedCoinInfo,
};
use moonproof_ledger::coin_structure::transfer::Recipient;

use crate::types::CoinPublicKey;

/// One entry in [`CompactZswapLocalState::outputs`]. Pairs a
/// shielded-coin info value with its recipient — mirrors the TS
/// `{ coinInfo, recipient }` shape.
#[derive(Debug, Clone, PartialEq)]
pub struct CompactZswapOutput {
    pub coin_info: CoinInfo,
    pub recipient: Recipient,
}

/// Compact-runtime-side zswap local state.
#[derive(Debug, Clone)]
pub struct CompactZswapLocalState {
    pub coin_public_key: CoinPublicKey,
    /// Insertion index for the next pending output — TS
    /// `currentIndex`. Not consulted by the offer translator for the
    /// no-coin case but preserved verbatim for round-trip fidelity
    /// with TS.
    pub current_index: u64,
    /// Inputs the circuit consumed — qualified shielded coins that
    /// were already on-chain.
    pub inputs: Vec<QualifiedCoinInfo>,
    /// Outputs the circuit produced — coin info + recipient pairs.
    pub outputs: Vec<CompactZswapOutput>,
}

impl CompactZswapLocalState {
    /// Construct an empty state pinned to `coin_public_key`. Matches
    /// TS `emptyZswapLocalState(coinPublicKey)`.
    #[must_use]
    pub fn empty(coin_public_key: CoinPublicKey) -> Self {
        Self {
            coin_public_key,
            current_index: 0,
            inputs: Vec::new(),
            outputs: Vec::new(),
        }
    }
}