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
use crate::{input::Input, output::Output, Error};
use bee_common::packable::{Packable, Read, Write};
#[derive(Clone, Debug, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct TreasuryTransactionPayload {
input: Input,
output: Output,
}
impl TreasuryTransactionPayload {
pub const KIND: u32 = 4;
pub fn new(input: Input, output: Output) -> Result<Self, Error> {
if !matches!(input, Input::Treasury(_)) {
return Err(Error::InvalidInputKind(input.kind()));
}
if !matches!(output, Output::Treasury(_)) {
return Err(Error::InvalidOutputKind(output.kind()));
}
Ok(Self { input, output })
}
pub fn input(&self) -> &Input {
&self.input
}
pub fn output(&self) -> &Output {
&self.output
}
}
impl Packable for TreasuryTransactionPayload {
type Error = Error;
fn packed_len(&self) -> usize {
self.input.packed_len() + self.output.packed_len()
}
fn pack<W: Write>(&self, writer: &mut W) -> Result<(), Self::Error> {
self.input.pack(writer)?;
self.output.pack(writer)?;
Ok(())
}
fn unpack_inner<R: Read + ?Sized, const CHECK: bool>(reader: &mut R) -> Result<Self, Self::Error> {
let input = Input::unpack_inner::<R, CHECK>(reader)?;
let output = Output::unpack_inner::<R, CHECK>(reader)?;
Self::new(input, output)
}
}