dubp_documents_parser/stringified_object/
transaction.rs1use crate::*;
17
18impl FromStringObject for TransactionDocumentV10 {
19 fn from_string_object(
20 stringified: &TransactionDocumentV10Stringified,
21 ) -> Result<Self, TextParseError> {
22 let issuers = stringified
23 .issuers
24 .iter()
25 .map(|s| ed25519::PublicKey::from_base58(s))
26 .collect::<Result<SmallVec<[ed25519::PublicKey; 1]>, BaseConversionError>>()
27 .map_err(|e| TextParseError::BaseConversionError {
28 field: "issuers",
29 error: e,
30 })?;
31
32 let inputs = stringified
33 .inputs
34 .iter()
35 .map(|s| tx_input_v10_from_str(s))
36 .collect::<Result<Vec<TransactionInputV10>, TextParseError>>()?;
37
38 let unlocks = stringified
39 .unlocks
40 .iter()
41 .map(|s| tx_unlock_v10_from_str(s))
42 .collect::<Result<Vec<TransactionInputUnlocksV10>, TextParseError>>()?;
43
44 let outputs = stringified
45 .outputs
46 .iter()
47 .map(|s| tx_output_v10_from_str(s))
48 .collect::<Result<SmallVec<[TransactionOutputV10; 2]>, TextParseError>>()?;
49
50 let signatures = stringified
51 .signatures
52 .iter()
53 .map(|s| ed25519::Signature::from_base64(s))
54 .collect::<Result<SmallVec<[ed25519::Signature; 1]>, BaseConversionError>>()
55 .map_err(|e| TextParseError::BaseConversionError {
56 field: "signatures",
57 error: e,
58 })?;
59
60 Ok(TransactionDocumentV10Builder {
61 currency: &stringified.currency,
62 blockstamp: Blockstamp::from_str(&stringified.blockstamp)
63 .map_err(TextParseError::BlockstampParseError)?,
64 locktime: stringified.locktime,
65 issuers,
66 inputs: &inputs[..],
67 unlocks: &unlocks[..],
68 outputs,
69 comment: &stringified.comment,
70 hash: if let Some(ref hash) = stringified.hash {
71 Some(
72 Hash::from_hex(hash).map_err(|e| TextParseError::BaseConversionError {
73 field: "hash",
74 error: e,
75 })?,
76 )
77 } else {
78 None
79 },
80 }
81 .build_with_signature(signatures))
82 }
83}