pub mod privkey;
pub mod address;
pub mod base58;
pub mod bip32;
pub mod bip143;
pub mod contracthash;
pub mod decimal;
pub mod hash;
pub mod misc;
pub mod uint;
use std::{error, fmt};
use secp256k1;
use network;
use consensus::encode;
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)]
pub enum Error {
Secp256k1(secp256k1::Error),
Encode(encode::Error),
Network(network::Error),
SpvBadProofOfWork,
SpvBadTarget,
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
Error::Secp256k1(ref e) => fmt::Display::fmt(e, f),
Error::Encode(ref e) => fmt::Display::fmt(e, f),
Error::Network(ref e) => fmt::Display::fmt(e, f),
Error::SpvBadProofOfWork | Error::SpvBadTarget => f.write_str(error::Error::description(self)),
}
}
}
impl error::Error for Error {
fn cause(&self) -> Option<&error::Error> {
match *self {
Error::Secp256k1(ref e) => Some(e),
Error::Encode(ref e) => Some(e),
Error::Network(ref e) => Some(e),
Error::SpvBadProofOfWork | Error::SpvBadTarget => None
}
}
fn description(&self) -> &str {
match *self {
Error::Secp256k1(ref e) => e.description(),
Error::Encode(ref e) => e.description(),
Error::Network(ref e) => e.description(),
Error::SpvBadProofOfWork => "target correct but not attained",
Error::SpvBadTarget => "target incorrect",
}
}
}
#[doc(hidden)]
impl From<secp256k1::Error> for Error {
fn from(e: secp256k1::Error) -> Error {
Error::Secp256k1(e)
}
}
#[doc(hidden)]
impl From<encode::Error> for Error {
fn from(e: encode::Error) -> Error {
Error::Encode(e)
}
}
#[doc(hidden)]
impl From<network::Error> for Error {
fn from(e: network::Error) -> Error {
Error::Network(e)
}
}