whisky_csl/tx_builder/
buildable.rs1use whisky_common::{TxBuildable, *};
2
3use super::WhiskyCSL;
4
5impl TxBuildable for WhiskyCSL {
6 fn reset_builder(&mut self) -> &mut Self {
7 self.core.reset_after_build();
8 self
9 }
10
11 fn set_protocol_params(&mut self, protocol_params: Protocol) -> &mut Self {
12 self.core.protocol_params = protocol_params.clone();
13 self
14 }
15
16 fn set_tx_builder_body(&mut self, tx_builder_body: TxBuilderBody) -> &mut Self {
17 self.tx_builder_body = tx_builder_body.clone();
18 self
19 }
20
21 fn serialize_tx_body(&mut self) -> Result<String, WError> {
34 if self.tx_builder_body.change_address.is_empty() {
35 return Err(WError::new(
36 "serialize_tx_body",
37 "change address cannot be empty",
38 ));
39 }
40 self.add_all_inputs()?
41 .add_all_outputs()?
42 .add_all_collaterals()?
43 .add_all_reference_inputs()?
44 .add_all_withdrawals()?
45 .add_all_mints()?
46 .add_all_certificates()?
47 .add_all_votes()?
48 .add_validity_range()?
49 .add_all_required_signature()?
50 .add_all_metadata()?
51 .add_script_hash()?
52 .set_fee_if_needed()?
53 .add_change_utxo()?;
54
55 self.core.build_tx(true)
56 }
57
58 fn unbalanced_serialize_tx_body(&mut self) -> Result<String, WError> {
59 if self.tx_builder_body.change_address.is_empty() {
60 return Err(WError::new(
61 "serialize_tx_body",
62 "change address cannot be empty",
63 ));
64 }
65 self.add_all_inputs()?
66 .add_all_outputs()?
67 .add_all_collaterals()?
68 .add_all_reference_inputs()?
69 .add_all_withdrawals()?
70 .add_all_mints()?
71 .add_all_certificates()?
72 .add_all_votes()?
73 .add_validity_range()?
74 .add_all_required_signature()?
75 .add_all_metadata()?
76 .add_script_hash()?
77 .set_fee_if_needed()?;
78
79 self.core.build_tx(false)
80 }
81
82 fn complete_signing(&mut self) -> Result<String, WError> {
90 let signing_keys = self.tx_builder_body.signing_key.clone();
91 self.add_all_signing_keys(
92 &signing_keys
93 .iter()
94 .map(|s| s.as_str())
95 .collect::<Vec<&str>>(),
96 )?;
97 Ok(self.core.tx_hex.to_string())
98 }
99
100 fn tx_hex(&mut self) -> String {
101 self.core.tx_hex.clone()
102 }
103}