moonproof-contracts 0.2.2

Node-side host orchestration for the moonproof contract pipeline — providers, deploy/call/maintenance lifecycle, fee balancing, submission, indexer-driven sync
Documentation
//! Midnight provider trait — port of
//! `@midnight-ntwrk/midnight-js-types/src/midnight-provider.ts`.
//!
//! Submits a finalized, sealed transaction to a consensus node and
//! returns its identifier. Concrete impls wrap the existing
//! `moonproof-node-client` (Substrate WebSocket JSON-RPC submission).

use moonproof_macros::async_trait;

use crate::error::Result;
use crate::tx_phase::FinalizedTx;
use crate::types::TransactionId;

/// Rust port of TS `MidnightProvider`.
#[async_trait]
pub trait MidnightProvider: Send + Sync + std::fmt::Debug {
    /// Submit a finalized (proven + sealed) transaction to the
    /// network.
    ///
    /// Input: a [`FinalizedTx`] — the wire form the node's
    /// `pallet_midnight.send_mn_transaction` accepts.
    ///
    /// Output: the transaction identifier the chain assigned (hex
    /// string). Callers thread this through
    /// [`super::PublicDataProvider::watch_for_tx_data`] to wait for
    /// finalisation.
    async fn submit_tx(&self, tx: FinalizedTx) -> Result<TransactionId>;
}

#[async_trait]
impl<T: MidnightProvider + ?Sized> MidnightProvider for std::sync::Arc<T> {
    async fn submit_tx(&self, tx: FinalizedTx) -> Result<TransactionId> {
        (**self).submit_tx(tx).await
    }
}

#[async_trait]
impl<T: MidnightProvider + ?Sized> MidnightProvider for Box<T> {
    async fn submit_tx(&self, tx: FinalizedTx) -> Result<TransactionId> {
        (**self).submit_tx(tx).await
    }
}