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

Error interface overhaul #7

Merged
merged 3 commits into from
Jul 3, 2024
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
6 changes: 2 additions & 4 deletions src/ledger/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@ use thiserror::Error;
/// Ledger error types.
#[derive(Error, Debug)]
pub enum LedgerError {
#[error("Ledger returned a general error: {0}")]
General(String),
#[error("Transaction is not OK: {0}")]
#[error("Transaction error: {0}")]
Transaction(String),
#[error("UTXO cannot be spend: {0}")]
#[error("UTXO error: {0}")]
Utxo(String),
}

Expand Down
4 changes: 2 additions & 2 deletions src/ledger/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ impl Ledger {
.iter()
.find(|tx| tx.compute_txid() == txid)
.ok_or(LedgerError::Transaction(format!(
"No transaction is matched with {}",
"No transaction with txid {} found in ledger",
txid
)))?
.to_owned();
Expand All @@ -81,7 +81,7 @@ impl Ledger {

if input_value < output_value {
return Err(LedgerError::Transaction(format!(
"Input value {} is not above or equal of output value {}",
"Input amount is smaller than output amount: {} < {}",
input_value, output_value
)));
}
Expand Down
2 changes: 1 addition & 1 deletion src/ledger/utxo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ impl Ledger {
.output
.get(utxo.vout as usize)
.ok_or(LedgerError::Utxo(format!(
"vout {} couldn't be found in transaction with txid {}",
"Vout {} couldn't be found in transaction with txid {}",
utxo.vout, utxo.txid
)))?;

Expand Down