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
//! Trait for a component capable of submitting transactions

use plutus_ledger_api::{csl::lib as csl, v2::transaction::TransactionHash};
use std::collections::BTreeMap;
use std::future::Future;
use thiserror::Error;

/// Component which can submit write actions to the chain
pub trait Submitter {
    fn evaluate_transaction(
        &self,
        tx_builder: &csl::TransactionBuilder,
        plutus_scripts: &[csl::PlutusScript],
        redeemers: &[csl::Redeemer],
    ) -> impl Future<
        Output = Result<BTreeMap<(csl::RedeemerTag, csl::BigNum), csl::ExUnits>, SubmitterError>,
    >;

    /// Submit a fully build and balanced tranasaction
    fn submit_transaction(
        &self,
        tx: &csl::FixedTransaction,
    ) -> impl Future<Output = Result<TransactionHash, SubmitterError>>;

    /// Wait for transaction confirmation on the chain
    fn await_tx_confirm(
        &self,
        tx_hash: &TransactionHash,
    ) -> impl Future<Output = Result<(), SubmitterError>>;
}

#[derive(Error, Debug)]
#[error(transparent)]
pub struct SubmitterError(pub anyhow::Error);