Skip to content
Open
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
13 changes: 13 additions & 0 deletions crates/floresta-chain/src/extensions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

use core::cmp::min;
use core::error::Error;
use core::fmt;
use core::fmt::Display;
use core::fmt::Formatter;
use core::ops::Add;

use bitcoin::block::Header;
Expand Down Expand Up @@ -85,6 +88,16 @@ pub enum HeaderExtError {
ChainWorkOverflow,
}

impl Display for HeaderExtError {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
match self {
HeaderExtError::Chain(e) => write!(f, "Chain error: {e}"),
HeaderExtError::BlockNotFound => write!(f, "Block not found"),
HeaderExtError::ChainWorkOverflow => write!(f, "Chain work overflow"),
}
}
}

impl HeaderExt for Header {
fn calculate_median_time_past(
&self,
Expand Down
14 changes: 14 additions & 0 deletions crates/floresta-chain/src/pruned_utreexo/chain_state_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
//! - Assumed valid blocks for validation optimization
//! - UTREEXO accumulator state
//! - Current chain tip and header
use core::fmt;
use core::fmt::Display;
use core::fmt::Formatter;

use bitcoin::block::Header as BlockHeader;
use bitcoin::BlockHash;
Expand Down Expand Up @@ -42,6 +45,17 @@ pub enum BlockchainBuilderError {
Database(Box<dyn DatabaseError>),
}

impl Display for BlockchainBuilderError {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
match self {
BlockchainBuilderError::MissingChainstore => write!(f, "Missing chainstore"),
BlockchainBuilderError::MissingChainParams => write!(f, "Missing chain parameters"),
BlockchainBuilderError::IncompleteTip => write!(f, "Incomplete tip"),
BlockchainBuilderError::Database(e) => write!(f, "Database error: {e:?}"),
}
}
}

#[derive(Clone, Debug, Default)]
/// A builder for configuring and creating a `ChainState`.
///
Expand Down
21 changes: 21 additions & 0 deletions crates/floresta-chain/src/pruned_utreexo/flat_chain_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@

extern crate std;

use core::fmt;
use core::fmt::Display;
use core::fmt::Formatter;
use core::mem::size_of;
use core::num::NonZeroUsize;
use std::fs::DirBuilder;
Expand Down Expand Up @@ -384,6 +387,24 @@ pub enum FlatChainstoreError {
InvalidValidationIndex,
}

impl Display for FlatChainstoreError {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
match self {
FlatChainstoreError::Io(e) => write!(f, "I/O error: {e}"),
FlatChainstoreError::BlockNotFound => write!(f, "Block not found"),
FlatChainstoreError::IndexIsFull => write!(f, "Index is full"),
FlatChainstoreError::DbTooNew(v) => write!(f, "Database too new: {v}"),
FlatChainstoreError::Poisoned => write!(f, "Poisoned"),
FlatChainstoreError::InvalidMagic(m) => write!(f, "Invalid magic: {m}"),
FlatChainstoreError::AccumulatorTooBig => write!(f, "Accumulator too big"),
FlatChainstoreError::IndexTooBig => write!(f, "Index too big"),
FlatChainstoreError::InvalidMetadataPointer => write!(f, "Invalid metadata pointer"),
FlatChainstoreError::DbCorrupted => write!(f, "Database corrupted"),
FlatChainstoreError::InvalidValidationIndex => write!(f, "Invalid validation index"),
}
}
}

/// Need this to use [FlatChainstoreError] as a [DatabaseError] in [ChainStore]
impl DatabaseError for FlatChainstoreError {}

Expand Down
10 changes: 10 additions & 0 deletions crates/floresta-chain/src/pruned_utreexo/udata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,16 @@ pub mod proof_util {
NotPushBytes,
}

impl Display for LeafErrorKind {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
match self {
LeafErrorKind::EmptyStack => write!(f, "Empty stack"),
LeafErrorKind::InvalidInstruction(e) => write!(f, "Invalid instruction: {e}"),
LeafErrorKind::NotPushBytes => write!(f, "Not push bytes"),
}
}
}

/// Error while reconstructing a leaf's scriptPubKey, returned by `process_proof`.
///
/// This error is triggered if the input lacks the hashed data required by the
Expand Down
20 changes: 20 additions & 0 deletions crates/floresta-node/src/slip132.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
//! Bitcoin SLIP-132 standard implementation for parsing custom xpub/xpriv key
//! formats

use core::fmt;
use core::fmt::Debug;
use core::fmt::Display;
use core::fmt::Formatter;

use bitcoin::base58;
use bitcoin::bip32;
Expand Down Expand Up @@ -110,6 +113,23 @@ pub enum Error {
InternalFailure,
}

impl Display for Error {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
match self {
Error::Base58(e) => write!(f, "Base58 error: {e}"),
Error::Hex(e) => write!(f, "Hex error: {e}"),
Error::CannotDeriveFromHardenedKey => write!(f, "Cannot derive from hardened key"),
Error::InvalidChildNumber(n) => write!(f, "Invalid child number: {n}"),
Error::InvalidChildNumberFormat => write!(f, "Invalid child number format"),
Error::InvalidDerivationPathFormat => write!(f, "Invalid derivation path format"),
Error::UnknownVersion(v) => write!(f, "Unknown version: {v:?}"),
Error::WrongExtendedKeyLength(l) => write!(f, "Wrong extended key length: {l}"),
Error::UnknownSlip32Prefix => write!(f, "Unknown SLIP32 prefix"),
Error::InternalFailure => write!(f, "Internal failure"),
}
}
}

impl From<bip32::Error> for Error {
fn from(err: bip32::Error) -> Self {
match err {
Expand Down
12 changes: 12 additions & 0 deletions crates/floresta-watch-only/src/memory_database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
//! It's not meant to use in production, but for the integrated testing framework
//!
//! For actual databases that can be used for production code, see [KvDatabase](crate::kv_database::KvDatabase).
use core::fmt;
use core::fmt::Display;
use core::fmt::Formatter;

use bitcoin::hashes::sha256;
use bitcoin::Txid;
use floresta_common::prelude::sync::RwLock;
Expand Down Expand Up @@ -34,6 +38,14 @@ pub struct MemoryDatabase {

type Result<T> = floresta_common::prelude::Result<T, MemoryDatabaseError>;

impl Display for MemoryDatabaseError {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
match self {
MemoryDatabaseError::PoisonedLock => write!(f, "Poisoned lock"),
}
}
}

impl MemoryDatabase {
fn get_inner(&self) -> Result<sync::RwLockReadGuard<'_, Inner>> {
self.inner
Expand Down
Loading