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