vanityaddr: Remove indicatif dependency.

This commit is contained in:
parazyd
2023-07-08 18:01:23 +02:00
parent 3b9c016ef6
commit 363a6cd998
5 changed files with 64 additions and 201 deletions

187
Cargo.lock generated
View File

@@ -852,12 +852,6 @@ dependencies = [
"serde_json",
]
[[package]]
name = "cassowary"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "df8670b8c7b9dae1793364eafadf7239c40d669904660c5960d74cfd80b46a53"
[[package]]
name = "cc"
version = "1.0.79"
@@ -1092,19 +1086,6 @@ dependencies = [
"toml 0.5.11",
]
[[package]]
name = "console"
version = "0.15.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c926e00cc70edefdc64d3a5ff31cc65bb97a3460097762bd23afb4d8145fccf8"
dependencies = [
"encode_unicode 0.3.6",
"lazy_static",
"libc",
"unicode-width",
"windows-sys 0.45.0",
]
[[package]]
name = "const-cstr"
version = "0.3.0"
@@ -1399,31 +1380,6 @@ dependencies = [
"cfg-if",
]
[[package]]
name = "crossterm"
version = "0.25.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e64e6c0fbe2c17357405f7c758c1ef960fce08bdfb2c03d88d2a18d7e09c4b67"
dependencies = [
"bitflags 1.3.2",
"crossterm_winapi",
"libc",
"mio",
"parking_lot 0.12.1",
"signal-hook",
"signal-hook-mio",
"winapi",
]
[[package]]
name = "crossterm_winapi"
version = "0.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "acdd7c62a3665c7f6830a51635d9ac9b23ed385797f70a83bb8bafe9c572ab2b"
dependencies = [
"winapi",
]
[[package]]
name = "crunchy"
version = "0.2.2"
@@ -1579,7 +1535,6 @@ dependencies = [
"futures",
"halo2_gadgets",
"halo2_proofs",
"indicatif",
"itertools 0.10.5",
"lazy_static",
"libc",
@@ -2294,29 +2249,6 @@ dependencies = [
"libloading 0.8.0",
]
[[package]]
name = "dnetview"
version = "0.4.1"
dependencies = [
"async-channel",
"async-std",
"clap 4.3.10",
"darkfi",
"easy-parallel",
"hex",
"libsqlite3-sys",
"log",
"rand 0.8.5",
"serde",
"serde_json",
"simplelog",
"smol",
"termion 2.0.1",
"thiserror",
"tui",
"url",
]
[[package]]
name = "downcast-rs"
version = "1.2.0"
@@ -2482,12 +2414,6 @@ dependencies = [
"zeroize",
]
[[package]]
name = "encode_unicode"
version = "0.3.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a357d28ed41a50f9c765dbfe56cbc04a64e53e5fc58ba79fbc34c10ef3df831f"
[[package]]
name = "encode_unicode"
version = "1.0.0"
@@ -3352,19 +3278,6 @@ dependencies = [
"hashbrown 0.14.0",
]
[[package]]
name = "indicatif"
version = "0.17.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ff8cc23a7393a397ed1d7f56e6365cba772aba9f9912ab968b03043c395d057"
dependencies = [
"console",
"instant",
"number_prefix",
"portable-atomic",
"unicode-width",
]
[[package]]
name = "indoc"
version = "1.0.9"
@@ -3755,18 +3668,6 @@ dependencies = [
"simd-adler32",
]
[[package]]
name = "mio"
version = "0.8.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "927a765cd3fc26206e66b296465fa9d3e5ab003e651c1b3c060e7956d96b19d2"
dependencies = [
"libc",
"log",
"wasi 0.11.0+wasi-snapshot-preview1",
"windows-sys 0.48.0",
]
[[package]]
name = "more-asserts"
version = "0.2.2"
@@ -3997,18 +3898,6 @@ dependencies = [
"libc",
]
[[package]]
name = "number_prefix"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "830b246a0e5f20af87141b25c173cd1b609bd7779a4617d6ec582abaf90870f3"
[[package]]
name = "numtoa"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b8f8bdf33df195859076e54ab11ee78a1b208382d3a26ec40d142ffc1ecc49ef"
[[package]]
name = "object"
version = "0.31.1"
@@ -4486,12 +4375,6 @@ dependencies = [
"universal-hash",
]
[[package]]
name = "portable-atomic"
version = "1.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "767eb9f07d4a5ebcb39bbf2d452058a93c011373abf6832e24194a1c3f004794"
[[package]]
name = "postage"
version = "0.5.0"
@@ -4520,7 +4403,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eea25e07510aa6ab6547308ebe3c036016d162b8da920dbb079e3ba8acf3d95a"
dependencies = [
"csv",
"encode_unicode 1.0.0",
"encode_unicode",
"is-terminal",
"lazy_static",
"term",
@@ -4840,15 +4723,6 @@ dependencies = [
"bitflags 1.3.2",
]
[[package]]
name = "redox_termios"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8440d8acb4fd3d277125b4bd01a6f38aee8d814b3b5fc09b3f2b825d37d3fe8f"
dependencies = [
"redox_syscall 0.2.16",
]
[[package]]
name = "redox_users"
version = "0.4.3"
@@ -5455,17 +5329,6 @@ dependencies = [
"signal-hook",
]
[[package]]
name = "signal-hook-mio"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "29ad2e15f37ec9a6cc544097b78a1ec90001e9f71b81338ca39f430adaca99af"
dependencies = [
"libc",
"mio",
"signal-hook",
]
[[package]]
name = "signal-hook-registry"
version = "1.4.1"
@@ -5976,30 +5839,6 @@ dependencies = [
"winapi-util",
]
[[package]]
name = "termion"
version = "1.5.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "077185e2eac69c3f8379a4298e1e07cd36beb962290d4a51199acf0fdc10607e"
dependencies = [
"libc",
"numtoa",
"redox_syscall 0.2.16",
"redox_termios",
]
[[package]]
name = "termion"
version = "2.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "659c1f379f3408c7e5e84c7d0da6d93404e3800b6b9d063ba24436419302ec90"
dependencies = [
"libc",
"numtoa",
"redox_syscall 0.2.16",
"redox_termios",
]
[[package]]
name = "textwrap"
version = "0.11.0"
@@ -6869,20 +6708,6 @@ version = "0.17.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "375812fa44dab6df41c195cd2f7fecb488f6c09fbaafb62807488cefab642bff"
[[package]]
name = "tui"
version = "0.19.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ccdd26cbd674007e649a272da4475fb666d3aa0ad0531da7136db6fab0e5bad1"
dependencies = [
"bitflags 1.3.2",
"cassowary",
"crossterm",
"termion 1.5.6",
"unicode-segmentation",
"unicode-width",
]
[[package]]
name = "typed-index-collections"
version = "3.1.0"
@@ -7048,7 +6873,6 @@ dependencies = [
"ctrlc",
"darkfi",
"darkfi-sdk",
"indicatif",
"rand 0.8.5",
"rayon",
]
@@ -7499,15 +7323,6 @@ dependencies = [
"windows_x86_64_msvc 0.33.0",
]
[[package]]
name = "windows-sys"
version = "0.45.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0"
dependencies = [
"windows-targets 0.42.2",
]
[[package]]
name = "windows-sys"
version = "0.48.0"

View File

@@ -106,7 +106,6 @@ url = {version = "2.4.0", features = ["serde"], optional = true}
# Misc
# TODO: Implement something simple and kill these deps
indicatif = {version = "0.17.5", optional = true}
simplelog = {version = "0.12.1", optional = true}
# Crypto

View File

@@ -12,8 +12,7 @@ edition = "2021"
bs58 = "0.5.0"
clap = {version = "4.3.3", features = ["derive"]}
ctrlc = "3.4.0"
darkfi = {path = "../../"}
darkfi = {path = "../../", features = ["util"]}
darkfi-sdk = {path = "../../src/sdk"}
indicatif = "0.17.5"
rand = "0.8.5"
rayon = "1.7.0"

View File

@@ -16,11 +16,14 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
use std::{process::exit, sync::mpsc::channel};
use std::{
process::exit,
sync::{mpsc::channel, Arc},
};
use clap::Parser;
use darkfi::util::cli::ProgressInc;
use darkfi_sdk::crypto::{ContractId, PublicKey, SecretKey, TokenId};
use indicatif::{ProgressBar, ProgressStyle};
use rand::rngs::OsRng;
use rayon::prelude::*;
@@ -175,16 +178,20 @@ fn main() {
.expect("Error setting SIGINT handler");
// Something fancy
let progress = Arc::new(ProgressInc::new());
/*
let progress = ProgressBar::new_spinner();
let template =
ProgressStyle::default_bar().template("[{elapsed_precise}] {pos} attempts").unwrap();
progress.set_style(template);
*/
// Fire off the threadpool
let progress_ = progress.clone();
rayon_pool.spawn(move || {
if args.token_id {
let tid = rayon::iter::repeat(DrkToken::new)
.inspect(|_| progress.inc(1))
.inspect(|_| progress_.inc(1))
.map(|create| create())
.find_any(|token_id| token_id.starts_with_any(&args.prefix, args.case_sensitive))
.expect("Failed to find a token ID match");
@@ -192,8 +199,8 @@ fn main() {
// The above will keep running until it finds a match or until the
// program terminates. Only if a match is found shall the following
// code be executed and the program exit successfully:
let attempts = progress.position();
progress.finish_and_clear();
let attempts = progress_.position();
progress_.finish_and_clear();
println!(
"{{\"token_id\":\"{}\",\"attempts\":{},\"secret\":\"{}\"}}",
@@ -201,13 +208,13 @@ fn main() {
);
} else if args.address {
let addr = rayon::iter::repeat(DrkAddr::new)
.inspect(|_| progress.inc(1))
.inspect(|_| progress_.inc(1))
.map(|create| create())
.find_any(|address| address.starts_with_any(&args.prefix, args.case_sensitive))
.expect("Failed to find an address match");
let attempts = progress.position();
progress.finish_and_clear();
let attempts = progress_.position();
progress_.finish_and_clear();
println!(
"{{\"address\":\"{}\",\"attempts\":{},\"secret\":\"{}\"}}",
@@ -215,15 +222,15 @@ fn main() {
);
} else if args.contract_id {
let cid = rayon::iter::repeat(DrkContract::new)
.inspect(|_| progress.inc(1))
.inspect(|_| progress_.inc(1))
.map(|create| create())
.find_any(|contract_id| {
contract_id.starts_with_any(&args.prefix, args.case_sensitive)
})
.expect("Failed to find a contract ID match");
let attempts = progress.position();
progress.finish_and_clear();
let attempts = progress_.position();
progress_.finish_and_clear();
println!(
"{{\"contract_id\":\"{}\",\"attempts\":{},\"secret\":\"{}\"}}",
@@ -236,6 +243,7 @@ fn main() {
// This now blocks and lets our threadpool execute in the background.
rx.recv().expect("Could not receive from channel");
eprintln!("\rCaught SIGINT, exiting...");
progress.finish_and_clear();
eprintln!("\r\x1b[2KCaught SIGINT, exiting...");
exit(127);
}

View File

@@ -22,6 +22,8 @@ use std::{
marker::PhantomData,
path::{Path, PathBuf},
str,
sync::{Arc, Mutex},
time::Instant,
};
use serde::{de::DeserializeOwned, Serialize};
@@ -305,3 +307,43 @@ pub fn fg_green(message: &str) -> String {
pub fn fg_reset() -> String {
"\x1b[0m".to_string()
}
pub struct ProgressInc {
position: Arc<Mutex<u64>>,
timer: Arc<Mutex<Option<Instant>>>,
}
impl ProgressInc {
pub fn new() -> Self {
eprint!("\x1b[?25l");
Self { position: Arc::new(Mutex::new(0)), timer: Arc::new(Mutex::new(None)) }
}
pub fn inc(&self, n: u64) {
let mut position = self.position.lock().unwrap();
if *position == 0 {
*self.timer.lock().unwrap() = Some(Instant::now());
}
*position += n;
let binding = self.timer.lock().unwrap();
let Some(elapsed) = binding.as_ref() else {
return
};
let elapsed = elapsed.elapsed();
let pos = *position;
eprint!("\r[{elapsed:?}] {pos} attempts");
}
pub fn position(&self) -> u64 {
*self.position.lock().unwrap()
}
pub fn finish_and_clear(&self) {
*self.timer.lock().unwrap() = None;
eprint!("\r\x1b[2K\x1b[?25h");
}
}