moonproof-contracts 0.2.1

Node-side host orchestration for the moonproof contract pipeline — providers, deploy/call/maintenance lifecycle, fee balancing, submission, indexer-driven sync
Documentation
//! Data shapes flowing between the unproven-tx builders
//! (`create_unproven_deploy_tx`, `create_unproven_call_tx`), the
//! submit-tx pipeline (`submit_tx`), and the high-level
//! `deploy_contract` / `find_deployed_contract` / `call` entry points.
//!
//! Private state and circuit return values are typed as
//! [`RuntimeValue`] uniformly — the IR descriptors carry shape
//! information; values are dynamically typed at this layer.

use moonproof_ledger::coin_structure::coin::Info as ShieldedCoinInfo;
use moonproof_ledger::coin_structure::contract::ContractAddress;
use moonproof_ledger::onchain_runtime::state::ContractState;
use moonproof_ledger::signatures::SigningKey;
use moonproof_ledger::storage::db::InMemoryDB;
use moonproof_runtime_ir::RuntimeValue;

use crate::tx_phase::UnprovenTx;
use crate::types::{CallResult, FinalizedTxData};
use crate::utils::zswap_utils::CompactZswapLocalState;

/// Data relevant to any unsubmitted transaction: the typed unproven
/// ledger transaction + the list of new coins it creates so the
/// wallet can start watching for them.
#[derive(Debug, Clone)]
pub struct UnsubmittedTxData {
    /// The pre-prove transaction. Goes straight into the proof
    /// provider's `prove_tx` — no serialize/deserialize hop needed.
    pub unproven_tx: UnprovenTx,
    /// Shielded coins that the transaction produces. The wallet
    /// should track these so they become spendable after the tx lands.
    pub new_coins: Vec<ShieldedCoinInfo>,
}

// =====================================================================
// Deploy tx
// =====================================================================

/// Public portion of a deploy tx (shared between unsubmitted +
/// finalized shapes).
#[derive(Debug, Clone)]
pub struct UnsubmittedDeployTxPublicData {
    /// The deterministic address the deploy will produce on-chain.
    pub contract_address: ContractAddress,
    /// The initial contract state the deploy installs.
    pub initial_contract_state: ContractState<InMemoryDB>,
}

/// Private portion of a deploy tx — signing key, initial private
/// state, the unproven tx (until it's submitted), shielded new coins,
/// and the constructor's initial zswap local state.
#[derive(Debug, Clone)]
pub struct UnsubmittedDeployTxPrivateData {
    /// The signing key the deploy added as the contract's
    /// maintenance authority. The deployer keeps this locally.
    pub signing_key: SigningKey,
    /// The initial private state the constructor was run against.
    /// Persisted locally if the tx succeeds.
    pub initial_private_state: RuntimeValue,
    /// The constructor's initial zswap local state.
    pub initial_zswap_local_state: CompactZswapLocalState,
    /// The pre-prove deploy tx. `None` on the find path: a contract
    /// connected via [`crate::find_deployed_contract`] doesn't carry
    /// a fresh unproven deploy — the deploy already happened.
    pub unproven_tx: Option<UnprovenTx>,
    /// Shielded coins the constructor produced.
    pub new_coins: Vec<ShieldedCoinInfo>,
}

/// Unsubmitted deploy tx data — output of [`crate::create_unproven_deploy_tx`].
#[derive(Debug, Clone)]
pub struct UnsubmittedDeployTxData {
    pub public: UnsubmittedDeployTxPublicData,
    pub private: UnsubmittedDeployTxPrivateData,
}

/// Public data on a finalized deploy — combines the finalized-tx
/// observation with the deploy's own public fields
/// (`contract_address`, `initial_contract_state`).
#[derive(Debug, Clone)]
pub struct FinalizedDeployTxPublicData {
    pub finalized: FinalizedTxData,
    pub contract_address: ContractAddress,
    pub initial_contract_state: ContractState<InMemoryDB>,
}

/// Finalized deploy tx data — adds the finalized-tx observation to
/// [`UnsubmittedDeployTxData`].
#[derive(Debug, Clone)]
pub struct FinalizedDeployTxData {
    pub public: FinalizedDeployTxPublicData,
    pub private: UnsubmittedDeployTxPrivateData,
}

// =====================================================================
// Call tx
// =====================================================================

/// Unsubmitted call tx data — the output of `create_unproven_call_tx`.
#[derive(Debug, Clone)]
pub struct UnsubmittedCallTxData {
    /// Public + private halves of the circuit execution.
    pub result: CallResult,
    /// Plus the ledger tx + new coins.
    pub tx: UnsubmittedTxData,
}

/// Finalized call tx data — adds the finalized-tx observation to the
/// unsubmitted form.
#[derive(Debug, Clone)]
pub struct FinalizedCallTxData {
    pub result: CallResult,
    pub tx: UnsubmittedTxData,
    pub finalized: FinalizedTxData,
}

/// Async (fire-and-forget) call-tx submission result.
#[derive(Debug, Clone)]
pub struct SubmittedCallTx {
    /// The transaction id the node assigned, returned immediately
    /// after submission.
    pub tx_id: crate::types::TransactionId,
    /// The full unsubmitted call-tx data — private state etc.,
    /// preserved for the caller so they can advance their local state
    /// before the tx lands.
    pub call_tx_data: UnsubmittedCallTxData,
}