ergo_lib/chain/transaction/
data_input.rs1use ergotree_ir::chain::ergo_box::BoxId;
4use ergotree_ir::serialization::sigma_byte_reader::SigmaByteRead;
5use ergotree_ir::serialization::sigma_byte_writer::SigmaByteWrite;
6use ergotree_ir::serialization::SigmaParsingError;
7use ergotree_ir::serialization::SigmaSerializable;
8use ergotree_ir::serialization::SigmaSerializeResult;
9#[cfg(feature = "json")]
10use serde::{Deserialize, Serialize};
11
12#[derive(PartialEq, Eq, Debug, Clone)]
14#[cfg_attr(feature = "arbitrary", derive(proptest_derive::Arbitrary))]
15#[cfg_attr(feature = "json", derive(Serialize, Deserialize))]
16pub struct DataInput {
17 #[cfg_attr(feature = "json", serde(rename = "boxId", alias = "id"))]
19 pub box_id: BoxId,
20}
21
22impl From<BoxId> for DataInput {
23 fn from(box_id: BoxId) -> Self {
24 DataInput { box_id }
25 }
26}
27
28impl SigmaSerializable for DataInput {
29 fn sigma_serialize<W: SigmaByteWrite>(&self, w: &mut W) -> SigmaSerializeResult {
30 self.box_id.sigma_serialize(w)?;
31 Ok(())
32 }
33 fn sigma_parse<R: SigmaByteRead>(r: &mut R) -> Result<Self, SigmaParsingError> {
34 let box_id = BoxId::sigma_parse(r)?;
35 Ok(DataInput { box_id })
36 }
37}
38
39#[cfg(test)]
40#[allow(clippy::panic)]
41mod tests {
42 use ergotree_ir::serialization::sigma_serialize_roundtrip;
43
44 use super::*;
45 use proptest::prelude::*;
46
47 proptest! {
48
49 #[test]
50 fn data_input_roundtrip(v in any::<DataInput>()) {
51 prop_assert_eq![sigma_serialize_roundtrip(&v), v];
52 }
53 }
54}