### Boha CLI Usage Examples Source: https://github.com/oritwoen/boha/blob/main/README.md Demonstrates various commands for the Boha CLI, including fetching statistics, listing puzzles (with filters for unsolved and public keys), showing puzzle details, retrieving key ranges, checking balances, and specifying output formats like JSON, YAML, and CSV. ```bash # Statistics boha stats # List puzzles boha list boha list b1000 boha list b1000 --unsolved boha list b1000 --with-pubkey # Show puzzle details boha show b1000/90 boha show gsmg boha show hash_collision/sha256 # Get key range boha range 90 # Check balance (requires --features balance) boha balance b1000/71 # Output formats (default: table) boha -o json stats boha -o yaml show b1000/90 boha -o csv list b1000 > puzzles.csv boha -o jsonl list b1000 --unsolved | jq . ``` -------------------------------- ### Boha Rust Library - Async Balance Fetching Source: https://github.com/oritwoen/boha/blob/main/README.md Demonstrates asynchronous balance fetching using the Boha library. This requires the 'balance' feature to be enabled. It shows how to get puzzle details and then fetch the confirmed and total Bitcoin balance for a given address. ```rust use boha::{b1000, balance}; #[tokio::main] async fn main() { let puzzle = b1000::get(71).unwrap(); let bal = balance::fetch(puzzle.address.value).await.unwrap(); println!("Confirmed: {} sats", bal.confirmed); println!("Total: {:.8} BTC", bal.total_btc()); } ``` -------------------------------- ### Install Boha CLI with cargo Source: https://github.com/oritwoen/boha/blob/main/README.md Installs the Boha CLI tool from crates.io, enabling command-line access to puzzle data. The 'cli' feature is required for the command-line interface, and 'balance' enables blockchain balance fetching. ```bash cargo install boha --features cli,balance ``` -------------------------------- ### Fetch Live Balance Data Asynchronously with Rust Source: https://context7.com/oritwoen/boha/llms.txt This example shows how to query blockchain APIs to fetch current puzzle balances in real-time using asynchronous Rust. It covers checking a single Bitcoin address balance and fetching multiple balances concurrently. It requires the 'tokio' runtime and the 'boha' crate. An API key for Ethereum is needed for Ethereum balance checks. ```rust use boha::{b1000, balance, Chain}; #[tokio::main] async fn main() -> Result<(), Box> { // Check single Bitcoin address balance let puzzle = b1000::get(71).unwrap(); let bal = balance::fetch(puzzle.address.value, Chain::Bitcoin).await?; println!("Puzzle 71 Balance:"); println!(" Confirmed: {} satoshis", bal.confirmed); println!(" Confirmed: {:.8} BTC", bal.confirmed_btc()); println!(" Unconfirmed: {} satoshis", bal.unconfirmed); println!(" Total: {:.8} BTC", bal.total_btc()); // Fetch multiple balances concurrently let addresses = vec![ ("1BgGZ9tcN4rm9KBzDn7KprQz87SZ26SAMH", Chain::Bitcoin), ("1CUNEBjYrCn2y1SdiUMohaKUi4wpP326Lb", Chain::Bitcoin), ("19ZewH8Kk1PDbSNdJ97FP4EiCjTRaZMZQA", Chain::Bitcoin), ]; let results = balance::fetch_many(&addresses).await; println!("\nBatch balance check:"); for (i, result) in results.iter().enumerate() { match result { Ok(bal) => println!(" Address {}: {:.8} BTC", i + 1, bal.total_btc()), Err(e) => println!(" Address {}: Error - {}", i + 1, e), } } // Ethereum balance (requires ETHERSCAN_API_KEY env var) // let eth_addr = "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045"; // let eth_bal = balance::fetch(eth_addr, Chain::Ethereum).await?; // println!("ETH Balance: {:.8} ETH", eth_bal.confirmed_eth()); Ok(()) } ``` -------------------------------- ### Boha Rust Library - Basic Puzzle Interaction Source: https://github.com/oritwoen/boha/blob/main/README.md Shows how to use the Boha Rust library to retrieve puzzle data, such as details for 'b1000' puzzles, including address, HASH160, start date, key range, and claim transaction ID. It also demonstrates filtering for unsolved puzzles with public keys. ```rust use boha::{b1000, gsmg, hash_collision, zden, Status}; let p90 = b1000::get(90).unwrap(); println!("Address: {}", p90.address.value); println!("HASH160: {}", p90.address.hash160.unwrap()); println!("Funded: {}", p90.start_date.unwrap_or("unknown")); let range = p90.key_range().unwrap(); println!("Range: 0x{:x} - 0x{:x}", range.start(), range.end()); if let Some(txid) = p90.claim_txid() { println!("Claimed in: {}", txid); println!("Explorer: {}", p90.chain.tx_explorer_url(txid)); } let unsolved: Vec<_> = b1000::all() .filter(|p| p.status == Status::Unsolved) .filter(|p| p.pubkey.is_some()) .collect(); let gsmg_puzzle = gsmg::get(); let sha256 = hash_collision::get("sha256").unwrap(); let level1 = zden::get("Level 1").unwrap(); let puzzle = boha::get("b1000/90").unwrap(); let puzzle = boha::get("gsmg").unwrap(); let puzzle = boha::get("zden/Level 1").unwrap(); ``` -------------------------------- ### Get Aggregate Statistics with Rust Source: https://context7.com/oritwoen/boha/llms.txt This code snippet demonstrates how to compute aggregate statistics across all puzzle collections using the 'boha' crate. It prints total counts, solved/unsolved numbers, claimed/swept counts, puzzles with public keys, and prize amounts broken down by chain. It also shows how to iterate through puzzles of a specific chain. ```rust use boha; fn main() { let stats = boha::stats(); println!("Total puzzles: {}", stats.total); println!("Solved: {}", stats.solved); println!("Unsolved: {}", stats.unsolved); println!("Claimed: {}", stats.claimed); println!("Swept: {}", stats.swept); println!("With public key: {}", stats.with_pubkey); println!("\nTotal prizes by chain:"); for (chain, amount) in &stats.total_prize { println!(" {}: {} {}", chain.name(), amount, chain.symbol()); } println!("\nUnsolved prizes by chain:"); for (chain, amount) in &stats.unsolved_prize { println!(" {}: {} {}", chain.name(), amount, chain.symbol()); } // Iterate all puzzles across collections let bitcoin_puzzles = boha::all() .filter(|p| p.chain == boha::Chain::Bitcoin) .count(); println!("\nBitcoin puzzles: {}", bitcoin_puzzles); } ``` -------------------------------- ### Build, Test, Format, and Lint with Cargo Source: https://github.com/oritwoen/boha/blob/main/CONTRIBUTING.md This snippet demonstrates the core development commands using Cargo, Rust's build system and package manager. These commands are essential for building the project, running tests, ensuring code formatting, and checking for common errors and style issues. ```bash cargo build cargo test cargo fmt cargo clippy ``` -------------------------------- ### Rust CLI Binary Entry Point Source: https://github.com/oritwoen/boha/blob/main/AGENTS.md The entry point for the BOHA CLI binary, enabled by the 'cli' feature. It utilizes clap derive macros for command-line argument parsing and integrates with libraries like 'tabled' and 'owo-colors' for formatted output. ```rust // CLI binary (--features cli) - NOT main.rs use clap::Parser; #[derive(Parser, Debug)] #[command(author, version, about, long_about = None)] struct Args { // ... command definitions ... } fn main() { let args = Args::parse(); // ... command execution logic ... } ``` -------------------------------- ### Bash Command for Building Release Binary Source: https://github.com/oritwoen/boha/blob/main/AGENTS.md A bash command using `just` to build a release version of the BOHA project, specifically enabling the 'cli' and 'balance' features. This prepares a production-ready binary with full functionality. ```bash # just build cargo build --release --features cli,balance ``` -------------------------------- ### Bash Command for BOHA CLI Show Puzzle Details Source: https://github.com/oritwoen/boha/blob/main/AGENTS.md Illustrates how to invoke the BOHA CLI to display detailed information about a specific puzzle, identified by its collection and identifier (e.g., 'b1000/90'). The 'cli' feature must be enabled. ```bash # cargo run --features cli -- show b1000/90 cargo run --features cli -- show b1000/90 ``` -------------------------------- ### Bash Command for BOHA CLI Stats Source: https://github.com/oritwoen/boha/blob/main/AGENTS.md Demonstrates how to run the BOHA CLI with the 'cli' feature enabled to display overall statistics about the puzzle data. This involves using `cargo run` with feature flags. ```bash # cargo run --features cli -- stats cargo run --features cli -- stats ``` -------------------------------- ### Bash Command for Running Clippy Source: https://github.com/oritwoen/boha/blob/main/AGENTS.md A bash command using `just` to run `clippy`, Rust's linter, on the entire project with all features enabled. It enforces coding standards and warns about potential issues, with a focus on treating warnings as errors. ```bash # just clippy cargo clippy --all-features -- -D warnings ``` -------------------------------- ### Bash Command for Running Tests Source: https://github.com/oritwoen/boha/blob/main/AGENTS.md A bash command using the `just` utility to execute all tests within the BOHA project, including those that leverage all available features. This is part of the project's testing and quality assurance workflow. ```bash # just test cargo test --all-features ``` -------------------------------- ### Rust Async Balance Fetching Source: https://github.com/oritwoen/boha/blob/main/AGENTS.md Implements asynchronous fetching of cryptocurrency balances, enabled by the 'balance' feature. This functionality relies on the 'reqwest' and 'tokio' crates to interact with external APIs, such as mempool.space. ```rust // Async balance fetch (--features balance) use reqwest::Client; use tokio; async fn fetch_balance(address: &str) -> Result { let client = Client::new(); let url = format!("https://mempool.space/api/address/{}", address); let response = client.get(&url).send().await?; let body = response.text().await?; Ok(body) } ``` -------------------------------- ### Bash Command for BOHA CLI List Unsolved Puzzles Source: https://github.com/oritwoen/boha/blob/main/AGENTS.md Shows how to use the BOHA CLI to list unsolved puzzles from a specific collection, like 'b1000'. This command requires the 'cli' feature to be enabled. ```bash # cargo run --features cli -- list b1000 --unsolved cargo run --features cli -- list b1000 --unsolved ``` -------------------------------- ### Bash Command for Releasing the Project Source: https://github.com/oritwoen/boha/blob/main/AGENTS.md A bash command utilizing `just` to automate the full release process for the BOHA project, typically involving versioning and packaging. This command ensures a consistent and repeatable release workflow. ```bash # just release X.Y.Z # ... release script logic ... echo "Release process initiated for version X.Y.Z" ``` -------------------------------- ### Add Boha as a Library Dependency Source: https://github.com/oritwoen/boha/blob/main/README.md Adds the Boha library to a Rust project's Cargo.toml file. The 'balance' feature can be enabled to include blockchain balance fetching functionality. ```toml # Basic usage [dependencies] boha = "0.1" # With balance fetching enabled [dependencies] boha = { version = "0.1", features = ["balance"] } ``` -------------------------------- ### Filter and Iterate Collections with Rust Source: https://context7.com/oritwoen/boha/llms.txt This snippet demonstrates how to query puzzles using iterators with filtering by status and properties. It showcases finding unsolved puzzles with public keys, listing solved puzzles with solve times, counting unsolved hash collision bounties, and accessing transaction history. Dependencies include the 'boha' crate. ```rust use boha::{b1000, hash_collision, Status}; fn main() { // Find all unsolved B1000 puzzles with exposed public keys let targets: Vec<_> = b1000::all() .filter(|p| p.status == Status::Unsolved) .filter(|p| p.has_pubkey()) .collect(); println!("Unsolved B1000 puzzles with public keys: {}", targets.len()); for puzzle in targets { println!(" Puzzle {}: {}", puzzle.name(), puzzle.address.value); if let Some(pubkey) = puzzle.pubkey_str() { println!(" Pubkey: {}...", &pubkey[..20]); } } // List solved puzzles with solve times println!("\nRecent solves:"); for puzzle in b1000::solved().take(5) { if let Some(formatted_time) = puzzle.solve_time_formatted() { println!(" {}: solved in {}", puzzle.id, formatted_time); } } // Count unsolved hash collision bounties let unsolved_count = hash_collision::unsolved().count(); println!("\nUnsolved hash collisions: {}", unsolved_count); // Access transaction history let p90 = b1000::get(90).unwrap(); println!("\nPuzzle 90 has {} transactions:", p90.transaction_count()); for tx in p90.transactions { println!(" {:?}: {:?}", tx.tx_type, tx.txid); } } ``` -------------------------------- ### Rust Scripts for Data Generation Source: https://github.com/oritwoen/boha/blob/main/AGENTS.md Utility scripts located in `scripts/src/bin/` within a separate Cargo project. These scripts are used for generating cryptographic hashes like h160 and script hashes, which are essential for puzzle data validation and creation. ```rust // scripts/src/bin/generate_h160 fn main() { // Example: Generating an h160 hash let data_to_hash = b"some data"; let h160_hash = bitcoin_hashes::sha256::Hash::hash(data_to_hash).into_inner(); let h160_hex = hex::encode(h160_hash); println!("H160: {}", h160_hex); } // scripts/src/bin/generate_script_hash // ... similar logic for script hashes ... // scripts/src/bin/generate_solve_time // ... logic for generating solve times ... ``` -------------------------------- ### Rust Codegen for Puzzle Data (build.rs) Source: https://github.com/oritwoen/boha/blob/main/AGENTS.md A build script (`build.rs`) that reads puzzle data from TOML files in the `data/` directory and generates Rust code. This code, typically a static array of `Puzzle` structs, is then included in the library, ensuring data is embedded at compile time. ```rust // build.rs - TOML→Rust codegen at compile time use std::env; use std::fs::File; use std::io::Write; use std::path::Path; fn main() { let out_dir = env::var("OUT_DIR").unwrap(); let dest_path = Path::new(&out_dir).join("b1000_data.rs"); let mut f = File::create(&dest_path).unwrap(); writeln!(f, "static PUZZLES: Vec = vec![").unwrap(); // Logic to read b1000.toml and generate Rust code for puzzles // ... parsing TOML data ... // ... generating struct instances ... writeln!(f, "];").unwrap(); println!("cargo:rerun-if-changed=data/b1000.toml"); } ``` -------------------------------- ### Calculate Private Key Search Ranges - Rust Source: https://context7.com/oritwoen/boha/llms.txt This Rust code snippet demonstrates how to calculate private key search ranges for Bitcoin puzzles using the Boha library. It shows how to obtain ranges for keys up to 128 bits using `u128` and for larger keys (129-256 bits) using `BigUint`. The code also accesses raw key information and bit constraints for brute-force searching. ```rust use boha::b1000; fn main() { let p71 = b1000::get(71).unwrap(); // For keys up to 128 bits, use u128 if let Some(range) = p71.key_range() { println!("Puzzle 71 search range (u128):"); println!(" Start: 0x{:x}", range.start()); println!(" End: 0x{:x}", range.end()); println!(" Size: 2^70 keys"); } // For larger keys (129-256 bits), use BigUint let p256 = b1000::get(256).unwrap(); if let Some((start, end)) = p256.key_range_big() { println!("\nPuzzle 256 search range (BigUint):"); println!(" Start: 0x{:x}", start); println!(" End: 0x{:x}", end); println!(" Bits: 256"); } // Access raw key information if let Some(key) = p71.key { if let Some(bits) = key.bits { println!("\nKey constraint: 2^{} <= k < 2^{}", bits - 1, bits); println!("Approximate keys to search: 2^{}", bits - 1); } } } ``` -------------------------------- ### Access Collection-Specific Puzzles - Rust Source: https://context7.com/oritwoen/boha/llms.txt This Rust code demonstrates accessing puzzles from specific collections using type-safe functions provided by the Boha library. It illustrates retrieving puzzle details like HASH160, public keys, claim transaction IDs, and explorer URLs. It also shows how to access redeem scripts for P2SH addresses and retrieve chain information for Zden puzzles. ```rust use boha::{b1000, gsmg, hash_collision, zden, Status}; fn main() { // Bitcoin Puzzle Transaction #90 let p90 = b1000::get(90).unwrap(); println!("Puzzle 90 address: {}", p90.address.value); if let Some(hash160) = p90.address.hash160 { println!("HASH160: {}", hash160); } if let Some(pubkey) = p90.pubkey { println!("Public key exposed: {}", pubkey.key); println!("Format: {:?}", pubkey.format); } // Check if solved and get claim transaction if let Some(txid) = p90.claim_txid() { println!("Claimed in transaction: {}", txid); println!("Explorer URL: {}", p90.chain.tx_explorer_url(txid)); } // GSMG puzzle let gsmg_puzzle = gsmg::get(); println!("\nGSMG Prize: {} BTC", gsmg_puzzle.prize.unwrap_or(0.0)); // Hash collision bounties let sha256_puzzle = hash_collision::get("sha256").unwrap(); if let Some(redeem_script) = sha256_puzzle.address.redeem_script { println!("\nP2SH Redeem Script: {}", redeem_script.script); println!("Script Hash: {}", redeem_script.hash); } // Zden visual puzzles let zden_level5 = zden::get("Level 5").unwrap(); println!("\nZden Level 5 chain: {:?}", zden_level5.chain); } ``` -------------------------------- ### Retrieve Specific Puzzle by Generic ID - Rust Source: https://context7.com/oritwoen/boha/llms.txt This Rust code snippet demonstrates how to retrieve specific cryptocurrency puzzles using a generic `boha::get()` function. It takes a collection and identifier string as input and returns puzzle details such as address, status, and prize. It supports various puzzle types like Bitcoin Puzzle Transactions, GSMG.IO puzzles, hash collision bounties, and Zden's visual puzzles. ```rust use boha; fn main() { // Bitcoin Puzzle Transaction - puzzle 90 let p90 = boha::get("b1000/90").unwrap(); println!("Address: {}", p90.address.value); println!("Status: {:?}", p90.status); println!("Prize: {} BTC", p90.prize.unwrap_or(0.0)); // GSMG.IO 5 BTC puzzle let gsmg = boha::get("gsmg").unwrap(); println!("GSMG Address: {}", gsmg.address.value); // Peter Todd's hash collision bounties let sha256 = boha::get("hash_collision/sha256").unwrap(); println!("SHA-256 bounty: {}", sha256.address.value); // Zden's visual puzzles let level1 = boha::get("zden/Level 1").unwrap(); println!("Zden Level 1: {}", level1.address.value); } ``` -------------------------------- ### Rust Library Core Functions Source: https://github.com/oritwoen/boha/blob/main/AGENTS.md Core functions for the BOHA Rust library, providing access to puzzle data. These functions include retrieving a specific puzzle by ID, iterating over all puzzles, and calculating aggregate statistics. They are designed for static data access, avoiding heap allocation. ```rust /// Library entry: get(), all(), stats() // Universal puzzle lookup by ID pub fn get(id: &str) -> Option<&'static Puzzle> { // ... implementation details ... } // Iterator over all puzzles pub fn all() -> impl Iterator { // ... implementation details ... } // Aggregate statistics pub fn stats() -> Stats { // ... implementation details ... } ``` -------------------------------- ### Rust Structs and Enums for Puzzle Data Source: https://github.com/oritwoen/boha/blob/main/AGENTS.md Defines the core data structures and enumerations used in the BOHA project to represent puzzles, addresses, statuses, key sources, and blockchain chains. These are fundamental for organizing and accessing puzzle-related information. ```rust // Puzzle, Address, Status, Chain, KeySource #[derive(Debug, Clone, PartialEq)] pub struct Puzzle { // ... fields ... } #[derive(Debug, Clone, PartialEq)] pub struct Address { // ... fields ... } #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum Status { // ... variants ... } #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum KeySource { // ... variants ... } #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum Chain { // ... variants ... } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.