1use std::collections::HashSet;
2
3use crate::inputs::CanonicalQuery;
4
5pub mod dump;
6pub mod inputs;
7pub mod interop;
8pub mod job;
9pub mod trp;
10
11#[cfg(test)]
12pub(crate) mod test_utils;
13
14pub use job::resolve_tx;
15pub use tx3_tir::model::assets::CanonicalAssets;
16pub use tx3_tir::model::core::{Type, Utxo, UtxoRef, UtxoSet};
17
18pub use tx3_tir::model::v1beta0::{Expression, StructExpr};
20
21#[derive(Debug, thiserror::Error)]
22pub enum Error {
23 #[error("can't compile non-constant tir")]
24 CantCompileNonConstantTir,
25
26 #[error(transparent)]
27 CompileError(#[from] tx3_tir::compile::Error),
28
29 #[error(transparent)]
30 InteropError(#[from] interop::Error),
31
32 #[error(transparent)]
33 ReduceError(#[from] tx3_tir::reduce::Error),
34
35 #[error("expected {0}, got {1:?}")]
36 ExpectedData(String, tx3_tir::model::v1beta0::Expression),
37
38 #[error("input query too broad")]
39 InputQueryTooBroad,
40
41 #[error("input not resolved: {0}")]
42 InputNotResolved(Box<InputNotResolvedError>),
43
44 #[error("missing argument `{key}` of type {ty:?}")]
45 MissingTxArg {
46 key: String,
47 ty: tx3_tir::model::core::Type,
48 },
49
50 #[error("transient error: {0}")]
51 TransientError(String),
52
53 #[error("store error: {0}")]
54 StoreError(String),
55
56 #[error("TIR encode / decode error: {0}")]
57 TirEncodingError(#[from] tx3_tir::encoding::Error),
58
59 #[error("tx was not accepted: {0}")]
60 TxNotAccepted(String),
61
62 #[error("tx script returned failure")]
63 TxScriptFailure(Vec<String>),
64}
65
66#[derive(Debug)]
67pub struct InputNotResolvedError {
68 pub name: String,
69 pub query: CanonicalQuery,
70 pub pool: Vec<UtxoRef>,
71}
72
73impl std::fmt::Display for InputNotResolvedError {
74 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
75 write!(f, "{}", self.name)
76 }
77}
78
79pub enum UtxoPattern<'a> {
80 ByAddress(&'a [u8]),
81 ByAssetPolicy(&'a [u8]),
82 ByAsset(&'a [u8], &'a [u8]),
83}
84
85impl<'a> UtxoPattern<'a> {
86 pub fn by_address(address: &'a [u8]) -> Self {
87 Self::ByAddress(address)
88 }
89
90 pub fn by_asset_policy(policy: &'a [u8]) -> Self {
91 Self::ByAssetPolicy(policy)
92 }
93
94 pub fn by_asset(policy: &'a [u8], name: &'a [u8]) -> Self {
95 Self::ByAsset(policy, name)
96 }
97}
98
99#[trait_variant::make(Send)]
100pub trait UtxoStore {
101 async fn narrow_refs(&self, pattern: UtxoPattern<'_>) -> Result<HashSet<UtxoRef>, Error>;
102 async fn fetch_utxos(&self, refs: HashSet<UtxoRef>) -> Result<UtxoSet, Error>;
103}