Skip to content

Commit

Permalink
fix(rpc): estimate fee should throw an error if any txn fails (#286)
Browse files Browse the repository at this point in the history
Co-authored-by: Trantorian1 <114066155+Trantorian1@users.noreply.github.com>
  • Loading branch information
apoorvsadana and Trantorian1 authored Oct 8, 2024
1 parent 9414233 commit 945a721
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Next release

- fix: estimate_fee should through an error if any txn fails
- fix: rejected transaction block production panic
- fix(sync): pending block retrying mechanism
- feat(cli): Environment variables can be used to specify Madara parameters
Expand Down
15 changes: 13 additions & 2 deletions crates/client/rpc/src/versions/v0_7_1/methods/read/estimate_fee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,19 @@ pub async fn estimate_fee(

let execution_results = exec_context.re_execute_transactions([], transactions, true, validate)?;

let fee_estimates =
execution_results.iter().map(|result| exec_context.execution_result_to_fee_estimate(result)).collect();
let fee_estimates = execution_results.iter().enumerate().try_fold(
Vec::with_capacity(execution_results.len()),
|mut acc, (index, result)| {
if result.execution_info.is_reverted() {
return Err(StarknetRpcApiError::TxnExecutionError {
tx_index: index,
error: result.execution_info.revert_error.clone().unwrap_or_default(),
});
}
acc.push(exec_context.execution_result_to_fee_estimate(result));
Ok(acc)
},
)?;

Ok(fee_estimates)
}

0 comments on commit 945a721

Please sign in to comment.