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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
mod treasury;
mod utxo;
use core::ops::RangeInclusive;
use derive_more::From;
pub use self::{treasury::TreasuryInput, utxo::UtxoInput};
use crate::Error;
pub const INPUT_COUNT_MAX: u16 = 128;
pub const INPUT_COUNT_RANGE: RangeInclusive<u16> = 1..=INPUT_COUNT_MAX;
pub const INPUT_INDEX_MAX: u16 = INPUT_COUNT_MAX - 1;
pub const INPUT_INDEX_RANGE: RangeInclusive<u16> = 0..=INPUT_INDEX_MAX;
#[derive(Clone, Debug, Eq, PartialEq, Hash, Ord, PartialOrd, From, packable::Packable)]
#[cfg_attr(
feature = "serde",
derive(serde::Serialize, serde::Deserialize),
serde(tag = "type", content = "data")
)]
#[packable(unpack_error = Error)]
#[packable(tag_type = u8, with_error = Error::InvalidInputKind)]
pub enum Input {
#[packable(tag = UtxoInput::KIND)]
Utxo(UtxoInput),
#[packable(tag = TreasuryInput::KIND)]
Treasury(TreasuryInput),
}
impl Input {
pub fn kind(&self) -> u8 {
match self {
Self::Utxo(_) => UtxoInput::KIND,
Self::Treasury(_) => TreasuryInput::KIND,
}
}
}
#[cfg(feature = "dto")]
#[allow(missing_docs)]
pub mod dto {
use serde::{Deserialize, Serialize};
use super::*;
pub use super::{treasury::dto::TreasuryInputDto, utxo::dto::UtxoInputDto};
use crate::error::dto::DtoError;
#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
#[serde(untagged)]
pub enum InputDto {
Utxo(UtxoInputDto),
Treasury(TreasuryInputDto),
}
impl From<&Input> for InputDto {
fn from(value: &Input) -> Self {
match value {
Input::Utxo(u) => InputDto::Utxo(u.into()),
Input::Treasury(t) => InputDto::Treasury(t.into()),
}
}
}
impl TryFrom<&InputDto> for Input {
type Error = DtoError;
fn try_from(value: &InputDto) -> Result<Self, Self::Error> {
match value {
InputDto::Utxo(u) => Ok(Input::Utxo(u.try_into()?)),
InputDto::Treasury(t) => Ok(Input::Treasury(t.try_into()?)),
}
}
}
}