Skip to content

Commit 31210ac

Browse files
committed
had to change the config-builder a bit for wasm-bindgen
1 parent 1d23768 commit 31210ac

File tree

2 files changed

+94
-33
lines changed

2 files changed

+94
-33
lines changed

rust/pkg/cardano_serialization_lib.js.flow

Lines changed: 72 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,14 @@ declare export var NetworkIdKind: {|
265265
+Mainnet: 1, // 1
266266
|};
267267

268+
/**
269+
*/
270+
271+
declare export var StakeCredKind: {|
272+
+Key: 0, // 0
273+
+Script: 1, // 1
274+
|};
275+
268276
/**
269277
*/
270278

@@ -293,14 +301,6 @@ declare export var RedeemerTagKind: {|
293301
+Reward: 3, // 3
294302
|};
295303

296-
/**
297-
*/
298-
299-
declare export var CoinSelectionStrategyCIP2: {|
300-
+LargestFirst: 0, // 0
301-
+RandomImprove: 1, // 1
302-
|};
303-
304304
/**
305305
* Used to choosed the schema for a script JSON string
306306
*/
@@ -333,9 +333,9 @@ declare export var MetadataJsonSchema: {|
333333
/**
334334
*/
335335

336-
declare export var StakeCredKind: {|
337-
+Key: 0, // 0
338-
+Script: 1, // 1
336+
declare export var CoinSelectionStrategyCIP2: {|
337+
+LargestFirst: 0, // 0
338+
+RandomImprove: 1, // 1
339339
|};
340340

341341
/**
@@ -5326,6 +5326,67 @@ declare export class TransactionBuilder {
53265326
declare export class TransactionBuilderConfig {
53275327
free(): void;
53285328
}
5329+
/**
5330+
*/
5331+
declare export class TransactionBuilderConfigBuilder {
5332+
free(): void;
5333+
5334+
/**
5335+
* @returns {TransactionBuilderConfigBuilder}
5336+
*/
5337+
static new(): TransactionBuilderConfigBuilder;
5338+
5339+
/**
5340+
* @param {LinearFee} fee_algo
5341+
* @returns {TransactionBuilderConfigBuilder}
5342+
*/
5343+
fee_algo(fee_algo: LinearFee): TransactionBuilderConfigBuilder;
5344+
5345+
/**
5346+
* @param {BigNum} pool_deposit
5347+
* @returns {TransactionBuilderConfigBuilder}
5348+
*/
5349+
pool_deposit(pool_deposit: BigNum): TransactionBuilderConfigBuilder;
5350+
5351+
/**
5352+
* @param {BigNum} key_deposit
5353+
* @returns {TransactionBuilderConfigBuilder}
5354+
*/
5355+
key_deposit(key_deposit: BigNum): TransactionBuilderConfigBuilder;
5356+
5357+
/**
5358+
* @param {number} max_value_size
5359+
* @returns {TransactionBuilderConfigBuilder}
5360+
*/
5361+
max_value_size(max_value_size: number): TransactionBuilderConfigBuilder;
5362+
5363+
/**
5364+
* @param {number} max_tx_size
5365+
* @returns {TransactionBuilderConfigBuilder}
5366+
*/
5367+
max_tx_size(max_tx_size: number): TransactionBuilderConfigBuilder;
5368+
5369+
/**
5370+
* @param {BigNum} coins_per_utxo_word
5371+
* @returns {TransactionBuilderConfigBuilder}
5372+
*/
5373+
coins_per_utxo_word(
5374+
coins_per_utxo_word: BigNum
5375+
): TransactionBuilderConfigBuilder;
5376+
5377+
/**
5378+
* @param {boolean} prefer_pure_change
5379+
* @returns {TransactionBuilderConfigBuilder}
5380+
*/
5381+
prefer_pure_change(
5382+
prefer_pure_change: boolean
5383+
): TransactionBuilderConfigBuilder;
5384+
5385+
/**
5386+
* @returns {TransactionBuilderConfig}
5387+
*/
5388+
build(): TransactionBuilderConfig;
5389+
}
53295390
/**
53305391
*/
53315392
declare export class TransactionHash {

rust/src/tx_builder.rs

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,10 @@ pub struct TransactionBuilderConfigBuilder {
176176
prefer_pure_change: bool,
177177
}
178178

179-
impl Default for TransactionBuilderConfigBuilder {
180-
fn default() -> Self {
179+
#[wasm_bindgen]
180+
impl TransactionBuilderConfigBuilder {
181+
182+
pub fn new() -> Self {
181183
Self {
182184
fee_algo: None,
183185
pool_deposit: None,
@@ -188,42 +190,40 @@ impl Default for TransactionBuilderConfigBuilder {
188190
prefer_pure_change: false,
189191
}
190192
}
191-
}
192193

193-
impl TransactionBuilderConfigBuilder {
194-
pub fn fee_algo(&mut self, fee_algo: fees::LinearFee) -> &mut Self {
194+
pub fn fee_algo(&mut self, fee_algo: fees::LinearFee) -> Self {
195195
self.fee_algo = Some(fee_algo);
196-
self
196+
self.clone()
197197
}
198198

199-
pub fn pool_deposit(&mut self, pool_deposit: BigNum) -> &mut Self {
199+
pub fn pool_deposit(&mut self, pool_deposit: BigNum) -> Self {
200200
self.pool_deposit = Some(pool_deposit);
201-
self
201+
self.clone()
202202
}
203203

204-
pub fn key_deposit(&mut self, key_deposit: BigNum) -> &mut Self {
204+
pub fn key_deposit(&mut self, key_deposit: BigNum) -> Self {
205205
self.key_deposit = Some(key_deposit);
206-
self
206+
self.clone()
207207
}
208208

209-
pub fn max_value_size(&mut self, max_value_size: u32) -> &mut Self {
209+
pub fn max_value_size(&mut self, max_value_size: u32) -> Self {
210210
self.max_value_size = Some(max_value_size);
211-
self
211+
self.clone()
212212
}
213213

214-
pub fn max_tx_size(&mut self, max_tx_size: u32) -> &mut Self {
214+
pub fn max_tx_size(&mut self, max_tx_size: u32) -> Self {
215215
self.max_tx_size = Some(max_tx_size);
216-
self
216+
self.clone()
217217
}
218218

219-
pub fn coins_per_utxo_word(&mut self, coins_per_utxo_word: Coin) -> &mut Self {
219+
pub fn coins_per_utxo_word(&mut self, coins_per_utxo_word: Coin) -> Self {
220220
self.coins_per_utxo_word = Some(coins_per_utxo_word);
221-
self
221+
self.clone()
222222
}
223223

224-
pub fn prefer_pure_change(&mut self, prefer_pure_change: bool) -> &mut Self {
224+
pub fn prefer_pure_change(&mut self, prefer_pure_change: bool) -> Self {
225225
self.prefer_pure_change = prefer_pure_change;
226-
self
226+
self.clone()
227227
}
228228

229229
pub fn build(&self) -> Result<TransactionBuilderConfig, JsError> {
@@ -1090,7 +1090,7 @@ mod tests {
10901090
max_val_size: u32,
10911091
coins_per_utxo_word: u64,
10921092
) -> TransactionBuilder {
1093-
let cfg = TransactionBuilderConfigBuilder::default()
1093+
let cfg = TransactionBuilderConfigBuilder::new()
10941094
.fee_algo(linear_fee.clone())
10951095
.pool_deposit(to_bignum(pool_deposit))
10961096
.key_deposit(to_bignum(key_deposit))
@@ -1129,7 +1129,7 @@ mod tests {
11291129
}
11301130

11311131
fn create_tx_builder_with_fee_and_pure_change(linear_fee: &LinearFee) -> TransactionBuilder {
1132-
TransactionBuilder::new(&TransactionBuilderConfigBuilder::default()
1132+
TransactionBuilder::new(&TransactionBuilderConfigBuilder::new()
11331133
.fee_algo(linear_fee.clone())
11341134
.pool_deposit(to_bignum(1))
11351135
.key_deposit(to_bignum(1))
@@ -2549,7 +2549,7 @@ mod tests {
25492549
fn tx_builder_cip2_random_improve_when_using_all_available_inputs() {
25502550
// we have a = 1 to test increasing fees when more inputs are added
25512551
let linear_fee = LinearFee::new(&to_bignum(1), &to_bignum(0));
2552-
let cfg = TransactionBuilderConfigBuilder::default()
2552+
let cfg = TransactionBuilderConfigBuilder::new()
25532553
.fee_algo(linear_fee)
25542554
.pool_deposit(to_bignum(0))
25552555
.key_deposit(to_bignum(0))
@@ -2576,7 +2576,7 @@ mod tests {
25762576
fn tx_builder_cip2_random_improve_adds_enough_for_fees() {
25772577
// we have a = 1 to test increasing fees when more inputs are added
25782578
let linear_fee = LinearFee::new(&to_bignum(1), &to_bignum(0));
2579-
let cfg = TransactionBuilderConfigBuilder::default()
2579+
let cfg = TransactionBuilderConfigBuilder::new()
25802580
.fee_algo(linear_fee)
25812581
.pool_deposit(to_bignum(0))
25822582
.key_deposit(to_bignum(0))

0 commit comments

Comments
 (0)