feat: update btc-address

This commit is contained in:
2022-05-02 19:01:30 +08:00
parent fc2a5217b3
commit 6517457d0d

View File

@@ -1,14 +1,34 @@
use std::{ thread, sync::{ Arc, Mutex } };
use rand::rngs::OsRng;
use secp256k1::{ Secp256k1, key::PublicKey };
use sha2::Sha256;
use ripemd160::Ripemd160;
use digest::{ Input, FixedOutput };
use std::{sync::{Arc, Mutex}, thread};
const PREFIX: &[&str] = &["1Hatter"];
use digest::{FixedOutput, Input};
use rand::rngs::OsRng;
use ripemd160::Ripemd160;
use secp256k1::{key::PublicKey, Secp256k1};
use sha2::Sha256;
fn main() {
println!("Prefix: {:?}", PREFIX);
let args = std::env::args();
if args.len() <= 1 {
println!("[ERROR] Need at least one argument, e.g. 1Hatter 1UTF8 ...");
return;
}
let continue_on_found = std::env::var("CONTINUE_ON_FOUND")
.map(|c| c.to_lowercase())
.map(|c| c == "1" || c == "true" || c == "yes" || c == "on")
.unwrap_or_else(|_| false);
let prefixes: Vec<String> = args.skip(1).collect();
println!("Prefixes: {:?}", prefixes);
if continue_on_found {
println!("CONTINUE_ON_FOUND is ON");
} else {
println!("CONTINUE_ON_FOUND is OFF");
}
let loop_count = std::env::var("LOOP_COUNT")
.map(|c| c.parse::<u64>())
.unwrap_or_else(|_| Ok(10_000_000_u64))
.unwrap_or_else(|_| 10_000_000_u64);
println!("LOOP_COUNT={}", loop_count);
let num_of_vcpus = num_cpus::get();
let num_of_phycpus = num_cpus::get_physical();
@@ -19,8 +39,9 @@ fn main() {
for ind in 0..num_of_phycpus {
println!("- Running task {} of {}", ind, num_of_phycpus);
let the_stop_flag = Arc::clone(&stop_flag);
let prefixes = prefixes.clone();
let child = thread::spawn(move || {
run_one_task(ind, the_stop_flag);
run_one_task(prefixes, continue_on_found, loop_count, ind, the_stop_flag);
});
handles.push(child);
}
@@ -30,11 +51,11 @@ fn main() {
println!("Finished!");
}
fn run_one_task(ind: usize, the_stop_flag: Arc<Mutex<bool>>) {
fn run_one_task(prefixes: Vec<String>, continue_on_found: bool, loop_count: u64, ind: usize, the_stop_flag: Arc<Mutex<bool>>) {
let secp = Secp256k1::new();
let mut rng = OsRng::new().expect("OsRng");
for i in 0..10_000_000 {
for i in 0..loop_count {
let (secret_key, public_key) = secp.generate_keypair(&mut rng);
let s = make_btc_address(&public_key);
@@ -47,12 +68,13 @@ fn run_one_task(ind: usize, the_stop_flag: Arc<Mutex<bool>>) {
println!("> {} - {}", ind, i);
}
}
if PREFIX.iter().any(|p| s.starts_with(p)) {
println!("{}", s);
println!("{}", secret_key);
if prefixes.iter().any(|p| s.starts_with(p)) {
println!(">> {}\n{}", s, secret_key);
*the_stop_flag.lock().unwrap() = true;
break;
if !continue_on_found {
*the_stop_flag.lock().unwrap() = true;
break;
}
}
}
}