tx_bakery/
submitter.rs

1//! Trait for a component capable of submitting transactions
2
3use plutus_ledger_api::{csl::lib as csl, v3::transaction::TransactionHash};
4use std::collections::BTreeMap;
5use std::future::Future;
6use thiserror::Error;
7
8/// Component which can submit write actions to the chain
9pub trait Submitter {
10    fn evaluate_transaction(
11        &self,
12        tx_builder: &csl::TransactionBuilder,
13        plutus_scripts: &[csl::PlutusScript],
14        redeemers: &[csl::Redeemer],
15    ) -> impl Future<
16        Output = Result<BTreeMap<(csl::RedeemerTag, csl::BigNum), csl::ExUnits>, SubmitterError>,
17    >;
18
19    /// Submit a fully build and balanced tranasaction
20    fn submit_transaction(
21        &self,
22        tx: &csl::FixedTransaction,
23    ) -> impl Future<Output = Result<TransactionHash, SubmitterError>>;
24
25    /// Wait for transaction confirmation on the chain
26    fn await_tx_confirm(
27        &self,
28        tx_hash: &TransactionHash,
29    ) -> impl Future<Output = Result<(), SubmitterError>>;
30}
31
32#[derive(Error, Debug)]
33#[error(transparent)]
34pub struct SubmitterError(pub anyhow::Error);