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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
mod simple;
pub use simple::*;
use crate::chain::ergo_box::BoxValueError;
use crate::chain::ergo_box::ErgoBoxAssetsData;
use crate::chain::{
ergo_box::{BoxValue, ErgoBoxAssets},
token::Token,
};
use thiserror::Error;
#[derive(PartialEq, Eq, Debug, Clone)]
pub struct BoxSelection<T: ErgoBoxAssets> {
pub boxes: Vec<T>,
pub change_boxes: Vec<ErgoBoxAssetsData>,
}
pub trait BoxSelector<T: ErgoBoxAssets> {
fn select(
&self,
inputs: Vec<T>,
target_balance: BoxValue,
target_tokens: &[Token],
) -> Result<BoxSelection<T>, BoxSelectorError>;
}
#[derive(Error, PartialEq, Eq, Debug, Clone)]
pub enum BoxSelectorError {
#[error("Not enough coins({0} nanoERGs are missing)")]
NotEnoughCoins(u64),
#[error("Not enough tokens, missing {0:?}")]
NotEnoughTokens(Vec<Token>),
#[error("BoxValue out of bounds")]
BoxValueError(BoxValueError),
}
impl From<BoxValueError> for BoxSelectorError {
fn from(e: BoxValueError) -> Self {
BoxSelectorError::BoxValueError(e)
}
}