boha 0.18.1

Crypto bounties, puzzles and challenges data library
Documentation
//! B1000 - Bitcoin Puzzle Transaction (256 puzzles).
//!
//! Each puzzle N has a private key k where: 2^(N-1) <= k < 2^N

#[allow(unused_imports)]
use crate::{
    Address, Author, Chain, Entropy, EntropySource, Error, IntoPuzzleNum, Key, Passphrase, Profile,
    Pubkey, PubkeyFormat, Puzzle, RedeemScript, Result, Seed, Solver, Status, Transaction,
    TransactionType, Wif,
};

include!(concat!(env!("OUT_DIR"), "/b1000_data.rs"));

pub fn author() -> &'static Author {
    &AUTHOR
}

pub fn get(key: impl IntoPuzzleNum) -> Result<&'static Puzzle> {
    let number = key.into_puzzle_num().ok_or(Error::InvalidNumber(0))?;
    if !(1..=256).contains(&number) {
        return Err(Error::InvalidNumber(number));
    }
    PUZZLES
        .iter()
        .find(|p| p.key.and_then(|k| k.bits) == Some(number as u16))
        .ok_or_else(|| Error::NotFound(format!("b1000/{}", number)))
}

pub fn slice() -> &'static [Puzzle] {
    PUZZLES
}

pub fn all() -> impl Iterator<Item = &'static Puzzle> {
    slice().iter()
}

pub fn solved() -> impl Iterator<Item = &'static Puzzle> {
    PUZZLES.iter().filter(|p| p.status == Status::Solved)
}

pub fn unsolved() -> impl Iterator<Item = &'static Puzzle> {
    PUZZLES.iter().filter(|p| p.status == Status::Unsolved)
}

pub fn with_pubkey() -> impl Iterator<Item = &'static Puzzle> {
    PUZZLES.iter().filter(|p| p.pubkey.is_some())
}

pub const fn count() -> usize {
    256
}

pub fn solved_count() -> usize {
    PUZZLES
        .iter()
        .filter(|p| p.status == Status::Solved)
        .count()
}

pub fn unsolved_count() -> usize {
    PUZZLES
        .iter()
        .filter(|p| p.status == Status::Unsolved)
        .count()
}