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

Refactor consensus.rs error mapping #382

Merged
merged 1 commit into from
Feb 25, 2025

Conversation

JoseSK999
Copy link
Contributor

I have created a tx_err macro to succinctly build a TransactionError. This has the benefit of skipping the BlockValidationErrors:: enum prefix when specifying the error, and flexibly taking a third argument for the inner variant value.

Instead of:

return Err(TransactionError {
    txid: transaction.compute_txid(),
    error: BlockValidationErrors::NotEnoughMoney,
}
.into());

We do:

return Err(tx_err!(txid, NotEnoughMoney))?;

The validation methods now directly return TransactionError and use a lazily evaluated closure to compute the txid if there's an error.

The pub mod error line is now before pub mod consensus to make the macro available. Finally changed the "Invalid coinbase txid" error message to "Invalid Coinbase PrevOut".

This reduces the error mapping boilerplate in the most important consensus function.

What is the purpose of this pull request?

  • Bug fix
  • Documentation update
  • New feature
  • Test
  • Other: Refactor and simplification

Which crates are being modified?

  • floresta-chain
  • floresta-cli
  • floresta-common
  • floresta-compact-filters
  • floresta-electrum
  • floresta-watch-only
  • floresta-wire
  • floresta
  • florestad
  • Other: .

I have created a `tx_err` macro to succinctly build a `TransactionError`. This has the benefit of skipping the `BlockValidationErrors::` enum prefix when specifying the error, and flexibly taking a third argument for the inner variant value.

The validation methods now directly return `TransactionError` and use a lazily evaluated closure to compute the `txid` if there's an error.

The `pub mod error` line is now before `pub mod consensus` to make the macro available. Finally changed the "Invalid coinbase txid" error message to "Invalid Coinbase PrevOut".
@Davidson-Souza
Copy link
Collaborator

ACK b82de34

@Davidson-Souza Davidson-Souza merged commit 31f532c into vinteumorg:master Feb 25, 2025
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants