@@ -2,7 +2,6 @@ use super::*;
22use super :: fees;
33use super :: utils;
44use std:: collections:: { BTreeMap , BTreeSet } ;
5- use derive_builder:: Builder ;
65
76// comes from witsVKeyNeeded in the Ledger spec
87fn witness_keys_for_cert ( cert_enum : & Certificate , keys : & mut BTreeSet < Ed25519KeyHash > ) {
@@ -154,18 +153,110 @@ pub enum CoinSelectionStrategyCIP2 {
154153}
155154
156155#[ wasm_bindgen]
157- #[ derive( Clone , Builder , Debug ) ]
156+ #[ derive( Clone , Debug ) ]
158157pub struct TransactionBuilderConfig {
159158 fee_algo : fees:: LinearFee ,
160159 pool_deposit : BigNum , // protocol parameter
161160 key_deposit : BigNum , // protocol parameter
162161 max_value_size : u32 , // protocol parameter
163162 max_tx_size : u32 , // protocol parameter
164163 coins_per_utxo_word : Coin , // protocol parameter
165- #[ builder( default = "false" ) ]
166164 prefer_pure_change : bool ,
167165}
168166
167+ #[ wasm_bindgen]
168+ #[ derive( Clone , Debug ) ]
169+ pub struct TransactionBuilderConfigBuilder {
170+ fee_algo : Option < fees:: LinearFee > ,
171+ pool_deposit : Option < BigNum > , // protocol parameter
172+ key_deposit : Option < BigNum > , // protocol parameter
173+ max_value_size : Option < u32 > , // protocol parameter
174+ max_tx_size : Option < u32 > , // protocol parameter
175+ coins_per_utxo_word : Option < Coin > , // protocol parameter
176+ prefer_pure_change : bool ,
177+ }
178+
179+ impl Default for TransactionBuilderConfigBuilder {
180+ fn default ( ) -> Self {
181+ Self {
182+ fee_algo : None ,
183+ pool_deposit : None ,
184+ key_deposit : None ,
185+ max_value_size : None ,
186+ max_tx_size : None ,
187+ coins_per_utxo_word : None ,
188+ prefer_pure_change : false ,
189+ }
190+ }
191+ }
192+
193+ impl TransactionBuilderConfigBuilder {
194+ pub fn fee_algo ( & mut self , fee_algo : fees:: LinearFee ) -> & mut Self {
195+ self . fee_algo = Some ( fee_algo) ;
196+ self
197+ }
198+
199+ pub fn pool_deposit ( & mut self , pool_deposit : BigNum ) -> & mut Self {
200+ self . pool_deposit = Some ( pool_deposit) ;
201+ self
202+ }
203+
204+ pub fn key_deposit ( & mut self , key_deposit : BigNum ) -> & mut Self {
205+ self . key_deposit = Some ( key_deposit) ;
206+ self
207+ }
208+
209+ pub fn max_value_size ( & mut self , max_value_size : u32 ) -> & mut Self {
210+ self . max_value_size = Some ( max_value_size) ;
211+ self
212+ }
213+
214+ pub fn max_tx_size ( & mut self , max_tx_size : u32 ) -> & mut Self {
215+ self . max_tx_size = Some ( max_tx_size) ;
216+ self
217+ }
218+
219+ pub fn coins_per_utxo_word ( & mut self , coins_per_utxo_word : Coin ) -> & mut Self {
220+ self . coins_per_utxo_word = Some ( coins_per_utxo_word) ;
221+ self
222+ }
223+
224+ pub fn prefer_pure_change ( & mut self , prefer_pure_change : bool ) -> & mut Self {
225+ self . prefer_pure_change = prefer_pure_change;
226+ self
227+ }
228+
229+ pub fn build ( & self ) -> Result < TransactionBuilderConfig , JsError > {
230+ Ok ( TransactionBuilderConfig {
231+ fee_algo : match self . fee_algo {
232+ Some ( ref fee_algo) => fee_algo. clone ( ) ,
233+ None => return Err ( JsError :: from_str ( "uninitialized field: fee_algo" ) ) ,
234+ } ,
235+ pool_deposit : match self . pool_deposit {
236+ Some ( ref pool_deposit) => pool_deposit. clone ( ) ,
237+ None => return Err ( JsError :: from_str ( "uninitialized field: pool_deposit" ) ) ,
238+ } ,
239+ key_deposit : match self . key_deposit {
240+ Some ( ref key_deposit) => key_deposit. clone ( ) ,
241+ None => return Err ( JsError :: from_str ( "uninitialized field: key_deposit" ) ) ,
242+ } ,
243+ max_value_size : match self . max_value_size {
244+ Some ( max_value_size) => max_value_size,
245+ None => return Err ( JsError :: from_str ( "uninitialized field: max_value_size" ) ) ,
246+ } ,
247+ max_tx_size : match self . max_tx_size {
248+ Some ( max_tx_size) => max_tx_size,
249+ None => return Err ( JsError :: from_str ( "uninitialized field: max_tx_size" ) ) ,
250+ } ,
251+ coins_per_utxo_word : match self . coins_per_utxo_word {
252+ Some ( ref coins_per_utxo_word) => coins_per_utxo_word. clone ( ) ,
253+ None => return Err ( JsError :: from_str ( "uninitialized field: coins_per_utxo_word" ) ) ,
254+ } ,
255+ prefer_pure_change : self . prefer_pure_change ,
256+ } )
257+ }
258+ }
259+
169260#[ wasm_bindgen]
170261#[ derive( Clone , Debug ) ]
171262pub struct TransactionBuilder {
0 commit comments