1use crate::kernel::Settings;
6use crate::model::TxnSet;
7pub use equity_exporter::EquityExporter;
8pub use equity_exporter::EquitySettings;
9use std::io;
10use std::path::Path;
11
12use crate::config::ExportType;
13use crate::tackler;
14pub use identity_exporter::IdentityExporter;
15use tackler_rs::create_output_file;
16
17pub use accounts_exporter::AccountsExporter;
18
19mod accounts_exporter;
20mod equity_exporter;
21mod identity_exporter;
22
23pub trait Export {
24 fn write_export<W: io::Write + ?Sized>(
28 &self,
29 cfg: &Settings,
30 w: &mut W,
31 txns: &TxnSet<'_>,
32 ) -> Result<(), tackler::Error>;
33}
34
35pub fn write_exports<ProgW: io::Write + ?Sized>(
40 output_dir: &Path,
41 output_name: &str,
42 exports: &Vec<ExportType>,
43 txn_set: &TxnSet<'_>,
44 settings: &mut Settings,
45 prog_writer: &mut Option<Box<ProgW>>,
46) -> Result<(), tackler::Error> {
47 for e in exports {
48 match e {
49 ExportType::Equity => {
50 let eq_exporter = EquityExporter {
51 export_settings: EquitySettings::from(settings),
52 };
53
54 let (mut out_writer, path) =
55 create_output_file(output_dir, output_name, "equity", "txn")?;
56 eq_exporter.write_export(settings, &mut out_writer, txn_set)?;
57 if let Some(p) = prog_writer.as_mut() {
58 writeln!(p, "{:>21} : {}", "Equity Export", path)?;
59 }
60 }
61 ExportType::Identity => {
62 let id_exporter = IdentityExporter {};
63
64 let (mut out_writer, path) =
65 create_output_file(output_dir, output_name, "identity", "txn")?;
66 id_exporter.write_export(settings, &mut out_writer, txn_set)?;
67 if let Some(p) = prog_writer.as_mut() {
68 writeln!(p, "{:>21} : {}", "Identity Export", path)?;
69 }
70 }
71 ExportType::Accounts => {
72 let acc_explorer = AccountsExporter {};
73 let (mut out_writer, path) =
74 create_output_file(output_dir, output_name, "accounts", "toml")?;
75 acc_explorer.write_export(settings, &mut out_writer, txn_set)?;
76 if let Some(p) = prog_writer.as_mut() {
77 writeln!(p, "{:>21} : {}", "Accounts Export", path)?;
78 }
79 }
80 }
81 }
82
83 Ok(())
84}