cardano_serialization_lib/serialization/
tx_input.rs1use crate::*;
2
3impl cbor_event::se::Serialize for TransactionInput {
4 fn serialize<'se, W: Write>(
5 &self,
6 serializer: &'se mut Serializer<W>,
7 ) -> cbor_event::Result<&'se mut Serializer<W>> {
8 serializer.write_array(cbor_event::Len::Len(2))?;
9 self.transaction_id.serialize(serializer)?;
10 self.index.serialize(serializer)?;
11 Ok(serializer)
12 }
13}
14
15impl Deserialize for TransactionInput {
16 fn deserialize<R: BufRead + Seek>(raw: &mut Deserializer<R>) -> Result<Self, DeserializeError> {
17 (|| -> Result<_, DeserializeError> {
18 let len = raw.array()?;
19 let ret = Self::deserialize_as_embedded_group(raw, len);
20 match len {
21 cbor_event::Len::Len(_) =>
22 {
24 ()
25 }
26 cbor_event::Len::Indefinite => match raw.special()? {
27 CBORSpecial::Break =>
28 {
30 ()
31 }
32 _ => return Err(DeserializeFailure::EndingBreakMissing.into()),
33 },
34 }
35 ret
36 })()
37 .map_err(|e| e.annotate("TransactionInput"))
38 }
39}
40
41impl DeserializeEmbeddedGroup for TransactionInput {
42 fn deserialize_as_embedded_group<R: BufRead + Seek>(
43 raw: &mut Deserializer<R>,
44 _: cbor_event::Len,
45 ) -> Result<Self, DeserializeError> {
46 let transaction_id =
47 (|| -> Result<_, DeserializeError> { Ok(TransactionHash::deserialize(raw)?) })()
48 .map_err(|e| e.annotate("transaction_id"))?;
49 let index = (|| -> Result<_, DeserializeError> { Ok(u32::deserialize(raw)?) })()
50 .map_err(|e| e.annotate("index"))?;
51 Ok(TransactionInput {
52 transaction_id,
53 index,
54 })
55 }
56}