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

feat: move errors to build in TransactionRequestBuilder #750

Merged
merged 3 commits into from
Feb 24, 2025
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

* Add check for empty pay to id notes (#714).
* [BREAKING] Refactored authentication out of the `Client` and added new separate authenticators (#718).
* Move error handling to the `TransactionRequestBuilder::build()` (#750).

## 0.7.0 (2025-01-28)

Expand Down
23 changes: 15 additions & 8 deletions bin/miden-cli/src/commands/new_transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@ impl MintCmd {
(&self.note_type).into(),
client.rng(),
)
.and_then(TransactionRequestBuilder::build)
.map_err(|err| {
CliError::Transaction(err.into(), "Failed to build mint transaction".to_string())
})?
.build();
})?;

execute_transaction(
&mut client,
Expand Down Expand Up @@ -150,10 +150,10 @@ impl SendCmd {
(&self.note_type).into(),
client.rng(),
)
.and_then(TransactionRequestBuilder::build)
.map_err(|err| {
CliError::Transaction(err.into(), "Failed to build payment transaction".to_string())
})?
.build();
})?;

execute_transaction(
&mut client,
Expand Down Expand Up @@ -219,10 +219,10 @@ impl SwapCmd {
(&self.note_type).into(),
client.rng(),
)
.and_then(TransactionRequestBuilder::build)
.map_err(|err| {
CliError::Transaction(err.into(), "Failed to build swap transaction".to_string())
})?
.build();
})?;

execute_transaction(
&mut client,
Expand Down Expand Up @@ -312,9 +312,16 @@ impl ConsumeNotesCmd {
));
}

let transaction_request = TransactionRequestBuilder::consume_notes(authenticated_notes)
let transaction_request = TransactionRequestBuilder::new()
.with_authenticated_input_notes(authenticated_notes.into_iter().map(|id| (id, None)))
.with_unauthenticated_input_notes(unauthenticated_notes)
.build();
.build()
.map_err(|err| {
CliError::Transaction(
err.into(),
"Failed to build consume notes transaction".to_string(),
)
})?;

execute_transaction(
&mut client,
Expand Down
4 changes: 2 additions & 2 deletions bin/miden-cli/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -805,8 +805,8 @@ async fn debug_mode_outputs_logs() {
// Send transaction and wait for it to be committed
let transaction_request = TransactionRequestBuilder::new()
.with_own_output_notes(vec![OutputNote::Full(note.clone())])
.unwrap()
.build();
.build()
.unwrap();
execute_tx_and_sync(&mut client, account.id(), transaction_request).await;

// Export the note
Expand Down
29 changes: 17 additions & 12 deletions crates/rust-client/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,8 @@ async fn test_mint_transaction() {
client.rng(),
)
.unwrap()
.build();
.build()
.unwrap();

let transaction = client.new_transaction(faucet.id(), transaction_request).await.unwrap();

Expand All @@ -465,7 +466,8 @@ async fn test_get_output_notes() {
client.rng(),
)
.unwrap()
.build();
.build()
.unwrap();

//Before executing transaction, there are no output notes
assert!(client.get_output_notes(NoteFilter::All).await.unwrap().is_empty());
Expand Down Expand Up @@ -528,8 +530,8 @@ async fn test_transaction_request_expiration() {
)
.unwrap()
.with_expiration_delta(5)
.unwrap()
.build();
.build()
.unwrap();

let transaction = client.new_transaction(faucet.id(), transaction_request).await.unwrap();

Expand Down Expand Up @@ -562,7 +564,8 @@ async fn test_import_processing_note_returns_error() {
client.rng(),
)
.unwrap()
.build();
.build()
.unwrap();

let transaction =
client.new_transaction(faucet.id(), transaction_request.clone()).await.unwrap();
Expand All @@ -572,8 +575,10 @@ async fn test_import_processing_note_returns_error() {
let note = client.get_input_note(note_id).await.unwrap().unwrap();

let input = [(note.try_into().unwrap(), None)];
let consume_note_request =
TransactionRequestBuilder::new().with_unauthenticated_input_notes(input).build();
let consume_note_request = TransactionRequestBuilder::new()
.with_unauthenticated_input_notes(input)
.build()
.unwrap();
let transaction = client
.new_transaction(account.id(), consume_note_request.clone())
.await
Expand Down Expand Up @@ -618,7 +623,7 @@ async fn test_no_nonce_change_transaction_request() {
let tx_script = client.compile_tx_script(vec![], code).unwrap();

let transaction_request =
TransactionRequestBuilder::new().with_custom_script(tx_script).unwrap().build();
TransactionRequestBuilder::new().with_custom_script(tx_script).build().unwrap();

let transaction_execution_result =
client.new_transaction(regular_account.id(), transaction_request).await.unwrap();
Expand Down Expand Up @@ -660,8 +665,8 @@ async fn test_note_without_asset() {
// Create and execute transaction
let transaction_request = TransactionRequestBuilder::new()
.with_own_output_notes(vec![OutputNote::Full(note)])
.unwrap()
.build();
.build()
.unwrap();

let transaction = client.new_transaction(wallet.id(), transaction_request.clone()).await;

Expand All @@ -675,8 +680,8 @@ async fn test_note_without_asset() {

let transaction_request = TransactionRequestBuilder::new()
.with_own_output_notes(vec![OutputNote::Full(note)])
.unwrap()
.build();
.build()
.unwrap();

let error = client.new_transaction(faucet.id(), transaction_request).await.unwrap_err();

Expand Down
5 changes: 3 additions & 2 deletions crates/rust-client/src/transaction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
//! NoteType::Private,
//! client.rng(),
//! )?
//! .build();
//! .build()?;
//!
//! // Execute the transaction. This returns a TransactionResult.
//! let tx_result: TransactionResult = client.new_transaction(sender_id, tx_request).await?;
Expand Down Expand Up @@ -1094,7 +1094,8 @@ mod test {
client.rng(),
)
.unwrap()
.build();
.build()
.unwrap();

let tx_result = client.new_transaction(account.id(), tx_request).await.unwrap();
assert!(tx_result
Expand Down
Loading