dubp_documents/transaction/v10/stringified.rs
1// Copyright (C) 2020 Éloïs SANCHEZ.
2//
3// This program is free software: you can redistribute it and/or modify
4// it under the terms of the GNU Affero General Public License as
5// published by the Free Software Foundation, either version 3 of the
6// License, or (at your option) any later version.
7//
8// This program is distributed in the hope that it will be useful,
9// but WITHOUT ANY WARRANTY; without even the implied warranty of
10// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11// GNU Affero General Public License for more details.
12//
13// You should have received a copy of the GNU Affero General Public License
14// along with this program. If not, see <https://www.gnu.org/licenses/>.
15
16//! Wrappers around transaction document v10 stringified.
17
18use super::*;
19
20#[derive(Clone, Debug, Deserialize, Hash, Serialize, PartialEq, Eq)]
21/// Transaction document stringifed
22pub struct TransactionDocumentV10Stringified {
23 /// Currency.
24 pub currency: String,
25 /// Blockstamp
26 pub blockstamp: String,
27 /// Locktime
28 pub locktime: u64,
29 /// Document issuers.
30 pub issuers: Vec<String>,
31 /// Transaction inputs.
32 pub inputs: Vec<String>,
33 /// Inputs unlocks.
34 pub unlocks: Vec<String>,
35 /// Transaction outputs.
36 pub outputs: Vec<String>,
37 /// Transaction comment
38 pub comment: String,
39 /// Document signatures
40 pub signatures: Vec<String>,
41 /// Transaction hash
42 pub hash: Option<String>,
43}
44
45impl ToStringObject for TransactionDocumentV10 {
46 type StringObject = TransactionDocumentV10Stringified;
47
48 fn to_string_object(&self) -> TransactionDocumentV10Stringified {
49 TransactionDocumentV10Stringified {
50 currency: self.currency.clone(),
51 blockstamp: format!("{}", self.blockstamp),
52 locktime: self.locktime,
53 issuers: self.issuers.iter().map(|p| format!("{}", p)).collect(),
54 inputs: self
55 .inputs
56 .iter()
57 .map(TransactionInputV10::to_string)
58 .collect(),
59 unlocks: self
60 .unlocks
61 .iter()
62 .map(TransactionInputUnlocksV10::to_string)
63 .collect(),
64 outputs: self
65 .outputs
66 .iter()
67 .map(TransactionOutputV10::to_string)
68 .collect(),
69 comment: self.comment.clone(),
70 signatures: self.signatures.iter().map(|s| format!("{}", s)).collect(),
71 hash: if let Some(hash) = self.hash {
72 Some(hash.to_string())
73 } else {
74 Some(self.compute_hash().to_hex())
75 },
76 }
77 }
78}