pub mod key;
pub mod ecdsa;
pub mod schnorr;
pub mod address;
pub mod amount;
pub mod base58;
pub mod bip32;
pub mod bip143;
pub mod bip152;
pub mod hash;
pub mod merkleblock;
pub mod misc;
pub mod psbt;
pub mod taproot;
pub mod uint;
pub mod bip158;
pub mod sighash;
pub(crate) mod endian;
use crate::prelude::*;
use crate::io;
use core::fmt;
use crate::consensus::encode;
use crate::internal_macros::write_err;
pub trait BitArray {
fn bit(&self, idx: usize) -> bool;
fn bit_slice(&self, start: usize, end: usize) -> Self;
fn mask(&self, n: usize) -> Self;
fn trailing_zeros(&self) -> usize;
fn zero() -> Self;
fn one() -> Self;
}
#[derive(Debug)]
#[non_exhaustive]
pub enum Error {
Encode(encode::Error),
BlockBadProofOfWork,
BlockBadTarget,
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
Error::Encode(ref e) => write_err!(f, "encoding error"; e),
Error::BlockBadProofOfWork => f.write_str("block target correct but not attained"),
Error::BlockBadTarget => f.write_str("block target incorrect"),
}
}
}
#[cfg(feature = "std")]
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
impl std::error::Error for Error {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
use self::Error::*;
match self {
Encode(e) => Some(e),
BlockBadProofOfWork | BlockBadTarget => None
}
}
}
#[doc(hidden)]
impl From<encode::Error> for Error {
fn from(e: encode::Error) -> Error {
Error::Encode(e)
}
}
pub(crate) fn read_to_end<D: io::Read>(mut d: D) -> Result<Vec<u8>, io::Error> {
let mut result = vec![];
let mut buf = [0u8; 64];
loop {
match d.read(&mut buf) {
Ok(0) => break,
Ok(n) => result.extend_from_slice(&buf[0..n]),
Err(ref e) if e.kind() == io::ErrorKind::Interrupted => {},
Err(e) => return Err(e),
};
}
Ok(result)
}