Skip to content

Commit

Permalink
Make TransactionBuilder::new( take the fee Amount
Browse files Browse the repository at this point in the history
this cleans up the constructor
  • Loading branch information
cbeck88 committed Apr 26, 2022
1 parent e43d042 commit 71cd422
Show file tree
Hide file tree
Showing 10 changed files with 152 additions and 109 deletions.
5 changes: 3 additions & 2 deletions android-bindings/src/bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1603,12 +1603,13 @@ pub unsafe extern "C" fn Java_com_mobilecoin_lib_TransactionBuilder_init_1jni(
// FIXME #1595: The token id should be a parameter and not hard coded to Mob
// here
let token_id = Mob::ID;
let fee_amount = Amount::new(Mob::MINIMUM_FEE, token_id);
let tx_builder = TransactionBuilder::new_with_box(
block_version,
token_id,
fee_amount,
fog_resolver.clone(),
memo_builder_box,
);
)?;

Ok(env.set_rust_field(obj, RUST_OBJ_FIELD, tx_builder)?)
})
Expand Down
5 changes: 3 additions & 2 deletions api/src/convert/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,11 @@ mod tests {

let mut transaction_builder = TransactionBuilder::new(
block_version,
Mob::ID,
Amount::new(Mob::MINIMUM_FEE, Mob::ID),
MockFogResolver::default(),
EmptyMemoBuilder::default(),
);
)
.unwrap();

let ring: Vec<TxOut> = minted_outputs.clone();
let public_key = RistrettoPublic::try_from(&minted_outputs[0].public_key).unwrap();
Expand Down
40 changes: 24 additions & 16 deletions consensus/service/src/validators.rs
Original file line number Diff line number Diff line change
Expand Up @@ -575,10 +575,11 @@ mod combine_tests {

let mut transaction_builder = TransactionBuilder::new(
block_version,
Mob::ID,
Amount::new(Mob::MINIMUM_FEE, Mob::ID),
MockFogResolver::default(),
EmptyMemoBuilder::default(),
);
)
.unwrap();
transaction_builder.add_input(input_credentials);
transaction_builder.set_fee(0).unwrap();
transaction_builder
Expand Down Expand Up @@ -634,10 +635,11 @@ mod combine_tests {

let mut transaction_builder = TransactionBuilder::new(
block_version,
Mob::ID,
Amount::new(Mob::MINIMUM_FEE, Mob::ID),
MockFogResolver::default(),
EmptyMemoBuilder::default(),
);
)
.unwrap();

// Create InputCredentials to spend the TxOut.
let onetime_private_key = recover_onetime_private_key(
Expand Down Expand Up @@ -739,10 +741,11 @@ mod combine_tests {

let mut transaction_builder = TransactionBuilder::new(
block_version,
Mob::ID,
Amount::new(Mob::MINIMUM_FEE, Mob::ID),
MockFogResolver::default(),
EmptyMemoBuilder::default(),
);
)
.unwrap();
transaction_builder.add_input(input_credentials);
transaction_builder.set_fee(0).unwrap();
transaction_builder
Expand Down Expand Up @@ -780,10 +783,11 @@ mod combine_tests {

let mut transaction_builder = TransactionBuilder::new(
block_version,
Mob::ID,
Amount::new(Mob::MINIMUM_FEE, Mob::ID),
MockFogResolver::default(),
EmptyMemoBuilder::default(),
);
)
.unwrap();
transaction_builder.add_input(input_credentials);
transaction_builder.set_fee(0).unwrap();
transaction_builder
Expand Down Expand Up @@ -844,10 +848,11 @@ mod combine_tests {

let mut transaction_builder = TransactionBuilder::new(
block_version,
Mob::ID,
Amount::new(Mob::MINIMUM_FEE, Mob::ID),
MockFogResolver::default(),
EmptyMemoBuilder::default(),
);
)
.unwrap();
transaction_builder.add_input(input_credentials);
transaction_builder.set_fee(0).unwrap();
transaction_builder
Expand Down Expand Up @@ -935,10 +940,11 @@ mod combine_tests {

let mut transaction_builder = TransactionBuilder::new(
block_version,
Mob::ID,
Amount::new(Mob::MINIMUM_FEE, Mob::ID),
MockFogResolver::default(),
EmptyMemoBuilder::default(),
);
)
.unwrap();
transaction_builder.add_input(input_credentials);
transaction_builder.set_fee(0).unwrap();
transaction_builder
Expand Down Expand Up @@ -977,10 +983,11 @@ mod combine_tests {

let mut transaction_builder = TransactionBuilder::new(
block_version,
Mob::ID,
Amount::new(Mob::MINIMUM_FEE, Mob::ID),
MockFogResolver::default(),
EmptyMemoBuilder::default(),
);
)
.unwrap();
transaction_builder.add_input(input_credentials);
transaction_builder.set_fee(0).unwrap();
transaction_builder
Expand Down Expand Up @@ -1042,10 +1049,11 @@ mod combine_tests {

let mut transaction_builder = TransactionBuilder::new(
block_version,
Mob::ID,
Amount::new(Mob::MINIMUM_FEE, Mob::ID),
MockFogResolver::default(),
EmptyMemoBuilder::default(),
);
)
.unwrap();
transaction_builder.add_input(input_credentials);
transaction_builder.set_fee(0).unwrap();
transaction_builder
Expand Down
13 changes: 7 additions & 6 deletions fog/distribution/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -715,17 +715,18 @@ fn build_tx(
// Use token id for first spendable tx out
let token_id = spendable_txouts.first().unwrap().amount.token_id;

// FIXME: This needs to be the fee for the current token, not MOB.
// However, bootstrapping non MOB tokens is not supported right now.
let fee_amount = Amount::new(MOB_FEE.load(Ordering::SeqCst), token_id);

// Create tx_builder.
let mut tx_builder = TransactionBuilder::new(
block_version,
token_id,
fee_amount,
fog_resolver,
EmptyMemoBuilder::default(),
);

// FIXME: This needs to be the fee for the current token, not MOB.
// However, bootstrapping non MOB tokens is not supported right now.
tx_builder.set_fee(MOB_FEE.load(Ordering::SeqCst)).unwrap();
)
.unwrap();

// Unzip each vec of tuples into a tuple of vecs.
let mut rings_and_proofs: Vec<(Vec<TxOut>, Vec<TxOutMembershipProof>)> = rings
Expand Down
8 changes: 6 additions & 2 deletions fog/sample-paykit/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -606,9 +606,13 @@ fn build_transaction_helper<T: RngCore + CryptoRng, FPR: FogPubkeyResolver>(
memo_builder.set_sender_credential(SenderMemoCredential::from(source_account_key));
memo_builder.enable_destination_memo();

TransactionBuilder::new(block_version, amount.token_id, fog_resolver, memo_builder)
TransactionBuilder::new(
block_version,
Amount::new(fee, amount.token_id),
fog_resolver,
memo_builder,
)?
};
tx_builder.set_fee(fee)?;

let input_amount = inputs
.iter()
Expand Down
8 changes: 3 additions & 5 deletions libmobilecoin/src/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,14 +378,12 @@ pub extern "C" fn mc_transaction_builder_create(

let mut transaction_builder = TransactionBuilder::new_with_box(
block_version,
token_id,
Amount::new(fee, token_id),
fog_resolver,
memo_builder_box,
);
)
.expect("Could not create transaction builder");

transaction_builder
.set_fee(fee)
.expect("failure not expected");
transaction_builder.set_tombstone_block(tombstone_block);
Some(transaction_builder)
})
Expand Down
11 changes: 5 additions & 6 deletions mobilecoind/src/payments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -869,17 +869,16 @@ impl<T: BlockchainConnection + UserTxConnection + 'static, FPR: FogPubkeyResolve

// TODO: Use RTH memo builder, optionally?

let fee_amount = Amount::new(fee, token_id);

// Create tx_builder.
let mut tx_builder = TransactionBuilder::new(
block_version,
token_id,
fee_amount,
fog_resolver,
EmptyMemoBuilder::default(),
);

tx_builder
.set_fee(fee)
.map_err(|err| Error::TxBuild(format!("Error setting fee: {}", err)))?;
)
.map_err(|err| Error::TxBuild(format!("Error creating transaction builder: {}", err)))?;

// Unzip each vec of tuples into a tuple of vecs.
let mut rings_and_proofs: Vec<(Vec<TxOut>, Vec<TxOutMembershipProof>)> = rings
Expand Down
15 changes: 9 additions & 6 deletions mobilecoind/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2917,10 +2917,11 @@ mod test {
let monitor_id = mobilecoind_db.add_monitor(&data).unwrap();
let mut transaction_builder = TransactionBuilder::new(
BLOCK_VERSION,
Mob::ID,
Amount::new(Mob::MINIMUM_FEE, Mob::ID),
MockFogResolver::default(),
EmptyMemoBuilder::default(),
);
)
.unwrap();
let (tx_out, tx_confirmation) = transaction_builder
.add_output(Amount::new(10, Mob::ID), &receiver.subaddress(0), &mut rng)
.unwrap();
Expand Down Expand Up @@ -5230,10 +5231,11 @@ mod test {

let mut transaction_builder = TransactionBuilder::new(
BLOCK_VERSION,
Mob::ID,
Amount::new(Mob::MINIMUM_FEE, Mob::ID),
MockFogResolver::default(),
EmptyMemoBuilder::default(),
);
)
.unwrap();
let (tx_out, _tx_confirmation) = transaction_builder
.add_output(
Amount::new(10, Mob::ID),
Expand Down Expand Up @@ -5342,10 +5344,11 @@ mod test {

let mut transaction_builder = TransactionBuilder::new(
BLOCK_VERSION,
Mob::ID,
Amount::new(Mob::MINIMUM_FEE, Mob::ID),
MockFogResolver::default(),
EmptyMemoBuilder::default(),
);
)
.unwrap();
let (tx_out, _tx_confirmation) = transaction_builder
.add_output(
Amount::new(10, Mob::ID),
Expand Down
8 changes: 3 additions & 5 deletions transaction/core/test-utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,11 @@ pub fn create_transaction_with_amount_and_comparer<

let mut transaction_builder = TransactionBuilder::new(
block_version,
sender_amount.token_id,
Amount::new(fee, sender_amount.token_id),
MockFogResolver::default(),
EmptyMemoBuilder::default(),
);
)
.unwrap();

// The first transaction in the origin block should contain enough outputs to
// use as mixins.
Expand Down Expand Up @@ -206,9 +207,6 @@ pub fn create_transaction_with_amount_and_comparer<
// Tombstone block
transaction_builder.set_tombstone_block(tombstone_block);

// Fee
transaction_builder.set_fee(fee).unwrap();

// Build and return the transaction
transaction_builder.build_with_sorter::<R, O>(rng).unwrap()
}
Expand Down
Loading

0 comments on commit 71cd422

Please sign in to comment.