balius_sdk/txbuilder/
mod.rs

1pub(crate) mod asset_math;
2pub mod plutus;
3
4#[derive(Debug, thiserror::Error)]
5pub enum BuildError {
6    #[error("Builder is incomplete")]
7    Incomplete,
8    #[error("Conflicting requirement")]
9    Conflicting,
10    #[error("UTxO decoding failed")]
11    UtxoDecode,
12    #[error("UTxO set is empty")]
13    EmptyUtxoSet,
14    #[error("Transaction has no inputs")]
15    MalformedScript,
16    #[error("Could not decode address")]
17    MalformedAddress,
18    #[error("Could not decode datum bytes")]
19    MalformedDatum,
20    #[error("Invalid bytes length for datum hash")]
21    MalformedDatumHash,
22    #[error("Input/policy pointed to by redeemer not found in tx")]
23    RedeemerTargetMissing,
24    #[error("Invalid network ID")]
25    InvalidNetworkId,
26    #[error("Corrupted transaction bytes in built transaction")]
27    CorruptedTxBytes,
28    #[error("Public key for private key is malformed")]
29    MalformedKey,
30    #[error("Asset name must be 32 bytes or less")]
31    AssetNameTooLong,
32    #[error("Asset value must be less than 9223372036854775807")]
33    AssetValueTooHigh,
34    #[error("Total outputs of this transaction are greater than total inputs")]
35    OutputsTooHigh,
36    #[error("Invalid asset policy id hex")]
37    MalformedAssetPolicyIdHex,
38    #[error("Malformed TxoRef")]
39    MalformedTxoRef,
40    #[error("Ledger error: {0}")]
41    LedgerError(String),
42}
43
44impl From<crate::wit::balius::app::ledger::LedgerError> for BuildError {
45    fn from(err: crate::wit::balius::app::ledger::LedgerError) -> Self {
46        BuildError::LedgerError(err.to_string())
47    }
48}
49
50use std::sync::Arc;
51
52pub use pallas_codec as codec;
53pub use pallas_primitives::conway as primitives;
54pub use utxorpc_spec::utxorpc::v1alpha::cardano::PParams;
55
56pub trait Ledger {
57    fn read_utxos(&self, refs: &[dsl::TxoRef]) -> Result<dsl::UtxoSet, BuildError>;
58    fn search_utxos(&self, pattern: &dsl::UtxoPattern) -> Result<dsl::UtxoSet, BuildError>;
59    fn read_params(&self) -> Result<PParams, BuildError>;
60}
61
62#[derive(Clone)]
63pub struct BuildContext {
64    pub network: primitives::NetworkId,
65    pub pparams: PParams,
66    pub total_input: primitives::Value,
67    pub spent_output: primitives::Value,
68    pub estimated_fee: u64,
69    pub ledger: Arc<Box<dyn Ledger>>,
70
71    pub tx_body: Option<primitives::TransactionBody>,
72    pub parent_output: Option<primitives::TransactionOutput>,
73}
74
75impl BuildContext {
76    pub fn with_parent_output(&self, output: primitives::TransactionOutput) -> Self {
77        let mut ctx = self.clone();
78        ctx.parent_output = Some(output);
79        ctx
80    }
81}
82
83mod build;
84mod dsl;
85
86pub use build::*;
87pub use dsl::*;