#![allow(dead_code)]
use crate::base::sample;
use crate::locale::fetch_locale;
pub fn address() -> String {
fetch_locale("bitcoin.addresses", "en")
.map(|v| sample(&v))
.unwrap_or_else(generate_bitcoin_address)
}
fn generate_bitcoin_address() -> String {
let prefix = sample(&["1", "3", "bc1"]);
let mut address = prefix.to_string();
const CHARS: &[u8] = b"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
let config = crate::config::FakerConfig::current();
let length = if address.starts_with("bc1") {
39 } else {
33
};
for _ in 0..length {
let idx = config.rand_range(0, (CHARS.len() - 1) as u32) as usize;
address.push(CHARS[idx] as char);
}
address
}
const FALLBACK_ADDRESSES: &[&str] = &[
"1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa",
"3J98t1WpEZ73CNmYviecrnyiWrnqRhWNLy",
"bc1qxy2kgdygjrsqtzq2n0yrf2493p83kkfjhx0wlh",
];
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_address() {
let addr = address();
assert!(!addr.is_empty());
assert!(addr.starts_with('1') || addr.starts_with('3') || addr.starts_with("bc1"));
}
}