electrs_client 0.2.9

A client for electrs
Documentation
use hex::FromHexError;
use nintypes::common::hash::HashError;
use reqwest::StatusCode;

use crate::{cache::CacheError, BlockHeight, REORG_CACHE_SIZE};

pub type ClientResult<T> = Result<T, ClientError>;

#[derive(Debug, thiserror::Error)]
pub enum ClientError {
    // lib errors
    #[error("failed to load forom env: {0}")]
    Envy(#[from] envy::Error),
    #[error("fetched zero blocks")]
    NoBlocksFetched,
    #[error("postcard: {0}")]
    Postcard(#[from] postcard::Error),
    #[error("json: {0}")]
    Json(#[from] serde_json::Error),
    #[error("io: {0}")]
    Cache(#[from] CacheError),
    #[error("reqwest: {0}")]
    Reqwest(#[from] reqwest::Error),
    #[error("hash: {0}")]
    Hash(#[from] HashError),
    #[error("fromhex: {0}")]
    FromHex(#[from] FromHexError),

    // custom errors
    #[error("cache not inited, before trying to use cashe functions make sure that you set path to cashe in config to Some")]
    CacheNotInited,
    #[error("metas hash chain invalid (i.e. prev_hash not equal hash in block)")]
    ReceivedHashChainInvalid,
    #[error("metas heights contain gaps")]
    ReceivedHeightContainsGaps,
    #[error("metas not sorted")]
    NotSorted,
    #[error("cache not marked as processed and consists of {0} blocks when maximum size is {REORG_CACHE_SIZE}")]
    CacheNotProcessed(usize),
    #[error("failed to decompress brotli: {0}")]
    BrotliDecompress(#[from] BrotliDecompress),
    #[error("Block not found {0}")]
    BlockNotFound(u32),
    #[error("Remove cache not following with add new block")]
    RemoveCacheNotFollowingWithAddNewBlock,

    // blocks provider problems
    #[error("UNAUTHORIZED REQUEST to blocks PROVIDER: {0}")]
    RequestUnauthorized(String),
    #[error("REQUEST NOT SUCCESFULL with STATUS CODE: {0} and response: {1}")]
    RequestUnsucces(StatusCode, String),
    #[error("PROVIDER send cache with gaps at height: {0}")]
    CacheWithGapsFromProvider(BlockHeight),
}

#[derive(Debug, thiserror::Error)]
pub enum BrotliDecompress {
    #[error("Io: {0}")]
    Io(#[from] std::io::Error),
}