Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing tx-builder-config-builder to take references and not values #269

Merged
merged 2 commits into from
Nov 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions rust/pkg/cardano_serialization_lib.js.flow
Original file line number Diff line number Diff line change
Expand Up @@ -5342,6 +5342,14 @@ declare export class TransactionBuilderConfigBuilder {
*/
fee_algo(fee_algo: LinearFee): TransactionBuilderConfigBuilder;

/**
* @param {BigNum} coins_per_utxo_word
* @returns {TransactionBuilderConfigBuilder}
*/
coins_per_utxo_word(
coins_per_utxo_word: BigNum
): TransactionBuilderConfigBuilder;

/**
* @param {BigNum} pool_deposit
* @returns {TransactionBuilderConfigBuilder}
Expand All @@ -5366,14 +5374,6 @@ declare export class TransactionBuilderConfigBuilder {
*/
max_tx_size(max_tx_size: number): TransactionBuilderConfigBuilder;

/**
* @param {BigNum} coins_per_utxo_word
* @returns {TransactionBuilderConfigBuilder}
*/
coins_per_utxo_word(
coins_per_utxo_word: BigNum
): TransactionBuilderConfigBuilder;

/**
* @param {boolean} prefer_pure_change
* @returns {TransactionBuilderConfigBuilder}
Expand Down
54 changes: 27 additions & 27 deletions rust/src/tx_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,18 +190,23 @@ impl TransactionBuilderConfigBuilder {
}
}

pub fn fee_algo(mut self, fee_algo: fees::LinearFee) -> Self {
self.fee_algo = Some(fee_algo);
pub fn fee_algo(mut self, fee_algo: &fees::LinearFee) -> Self {
self.fee_algo = Some(fee_algo.clone());
self
}

pub fn pool_deposit(mut self, pool_deposit: BigNum) -> Self {
self.pool_deposit = Some(pool_deposit);
pub fn coins_per_utxo_word(mut self, coins_per_utxo_word: &Coin) -> Self {
self.coins_per_utxo_word = Some(coins_per_utxo_word.clone());
self
}

pub fn key_deposit(mut self, key_deposit: BigNum) -> Self {
self.key_deposit = Some(key_deposit);
pub fn pool_deposit(mut self, pool_deposit: &BigNum) -> Self {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fairly certain this (BigNum passed by-value) is present in other areas. I know it implements Copy in rust but I'm not sure if that is enough to not cause issues when it goes through the wasm-bindgen boundary.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For me it caused problem when being passed by value - that value then gets very counter-intuitively erased when used from JS. I will double-check then where it's being used by-value, might also need to be fixed if this is something that is used from JS as well.

self.pool_deposit = Some(pool_deposit.clone());
self
}

pub fn key_deposit(mut self, key_deposit: &BigNum) -> Self {
self.key_deposit = Some(key_deposit.clone());
self
}

Expand All @@ -215,11 +220,6 @@ impl TransactionBuilderConfigBuilder {
self
}

pub fn coins_per_utxo_word(mut self, coins_per_utxo_word: Coin) -> Self {
self.coins_per_utxo_word = Some(coins_per_utxo_word);
self
}

pub fn prefer_pure_change(mut self, prefer_pure_change: bool) -> Self {
self.prefer_pure_change = prefer_pure_change;
self
Expand Down Expand Up @@ -1134,12 +1134,12 @@ mod tests {
coins_per_utxo_word: u64,
) -> TransactionBuilder {
let cfg = TransactionBuilderConfigBuilder::new()
.fee_algo(linear_fee.clone())
.pool_deposit(to_bignum(pool_deposit))
.key_deposit(to_bignum(key_deposit))
.fee_algo(linear_fee)
.pool_deposit(&to_bignum(pool_deposit))
.key_deposit(&to_bignum(key_deposit))
.max_value_size(max_val_size)
.max_tx_size(MAX_TX_SIZE)
.coins_per_utxo_word(to_bignum(coins_per_utxo_word))
.coins_per_utxo_word(&to_bignum(coins_per_utxo_word))
.build()
.unwrap();
TransactionBuilder::new(&cfg)
Expand Down Expand Up @@ -1173,12 +1173,12 @@ mod tests {

fn create_tx_builder_with_fee_and_pure_change(linear_fee: &LinearFee) -> TransactionBuilder {
TransactionBuilder::new(&TransactionBuilderConfigBuilder::new()
.fee_algo(linear_fee.clone())
.pool_deposit(to_bignum(1))
.key_deposit(to_bignum(1))
.fee_algo(linear_fee)
.pool_deposit(&to_bignum(1))
.key_deposit(&to_bignum(1))
.max_value_size(MAX_VALUE_SIZE)
.max_tx_size(MAX_TX_SIZE)
.coins_per_utxo_word(to_bignum(1))
.coins_per_utxo_word(&to_bignum(1))
.prefer_pure_change(true)
.build()
.unwrap())
Expand Down Expand Up @@ -2589,12 +2589,12 @@ mod tests {
// we have a = 1 to test increasing fees when more inputs are added
let linear_fee = LinearFee::new(&to_bignum(1), &to_bignum(0));
let cfg = TransactionBuilderConfigBuilder::new()
.fee_algo(linear_fee)
.pool_deposit(to_bignum(0))
.key_deposit(to_bignum(0))
.fee_algo(&linear_fee)
.pool_deposit(&to_bignum(0))
.key_deposit(&to_bignum(0))
.max_value_size(9999)
.max_tx_size(9999)
.coins_per_utxo_word(Coin::zero())
.coins_per_utxo_word(&Coin::zero())
.build()
.unwrap();
let mut tx_builder = TransactionBuilder::new(&cfg);
Expand All @@ -2616,12 +2616,12 @@ mod tests {
// we have a = 1 to test increasing fees when more inputs are added
let linear_fee = LinearFee::new(&to_bignum(1), &to_bignum(0));
let cfg = TransactionBuilderConfigBuilder::new()
.fee_algo(linear_fee)
.pool_deposit(to_bignum(0))
.key_deposit(to_bignum(0))
.fee_algo(&linear_fee)
.pool_deposit(&to_bignum(0))
.key_deposit(&to_bignum(0))
.max_value_size(9999)
.max_tx_size(9999)
.coins_per_utxo_word(Coin::zero())
.coins_per_utxo_word(&Coin::zero())
.build()
.unwrap();
let mut tx_builder = TransactionBuilder::new(&cfg);
Expand Down