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
use crate::*;
impl FromStringObject for TransactionDocumentV10 {
fn from_string_object(
stringified: &TransactionDocumentV10Stringified,
) -> Result<Self, TextParseError> {
let issuers = stringified
.issuers
.iter()
.map(|s| ed25519::PublicKey::from_base58(s))
.collect::<Result<SmallVec<[ed25519::PublicKey; 1]>, BaseConversionError>>()
.map_err(|e| TextParseError::BaseConversionError {
field: "issuers",
error: e,
})?;
let inputs = stringified
.inputs
.iter()
.map(|s| tx_input_v10_from_str(s))
.collect::<Result<Vec<TransactionInputV10>, TextParseError>>()?;
let unlocks = stringified
.unlocks
.iter()
.map(|s| tx_unlock_v10_from_str(s))
.collect::<Result<Vec<TransactionInputUnlocksV10>, TextParseError>>()?;
let outputs = stringified
.outputs
.iter()
.map(|s| tx_output_v10_from_str(s))
.collect::<Result<SmallVec<[TransactionOutputV10; 2]>, TextParseError>>()?;
let signatures = stringified
.signatures
.iter()
.map(|s| ed25519::Signature::from_base64(s))
.collect::<Result<SmallVec<[ed25519::Signature; 1]>, BaseConversionError>>()
.map_err(|e| TextParseError::BaseConversionError {
field: "signatures",
error: e,
})?;
Ok(TransactionDocumentV10Builder {
currency: &stringified.currency,
blockstamp: Blockstamp::from_str(&stringified.blockstamp)
.map_err(TextParseError::BlockstampParseError)?,
locktime: stringified.locktime,
issuers,
inputs: &inputs[..],
unlocks: &unlocks[..],
outputs,
comment: &stringified.comment,
hash: if let Some(ref hash) = stringified.hash {
Some(
Hash::from_hex(hash).map_err(|e| TextParseError::BaseConversionError {
field: "hash",
error: e,
})?,
)
} else {
None
},
}
.build_with_signature(signatures))
}
}