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(String, CanonicalQuery, Vec<UtxoRef>),
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
66pub enum UtxoPattern<'a> {
67 ByAddress(&'a [u8]),
68 ByAssetPolicy(&'a [u8]),
69 ByAsset(&'a [u8], &'a [u8]),
70}
71
72impl<'a> UtxoPattern<'a> {
73 pub fn by_address(address: &'a [u8]) -> Self {
74 Self::ByAddress(address)
75 }
76
77 pub fn by_asset_policy(policy: &'a [u8]) -> Self {
78 Self::ByAssetPolicy(policy)
79 }
80
81 pub fn by_asset(policy: &'a [u8], name: &'a [u8]) -> Self {
82 Self::ByAsset(policy, name)
83 }
84}
85
86#[trait_variant::make(Send)]
87pub trait UtxoStore {
88 async fn narrow_refs(&self, pattern: UtxoPattern<'_>) -> Result<HashSet<UtxoRef>, Error>;
89 async fn fetch_utxos(&self, refs: HashSet<UtxoRef>) -> Result<UtxoSet, Error>;
90}