1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
//! 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
}
}