Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added the --all flag on ord wallet sats #3824

Merged
25 changes: 25 additions & 0 deletions src/subcommand/wallet/sats.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use super::*;
use clap::Parser;
raphjaph marked this conversation as resolved.
Show resolved Hide resolved

#[derive(Debug, Parser)]
pub(crate) struct Sats {
Expand All @@ -7,6 +8,11 @@ pub(crate) struct Sats {
help = "Find satoshis listed in first column of tab-separated value file <TSV>."
)]
tsv: Option<PathBuf>,
#[arg(
long,
help = "Display list of all sat ranges in wallet and special sats."
cryptoni9n marked this conversation as resolved.
Show resolved Hide resolved
)]
all: bool,
}

#[derive(Serialize, Deserialize)]
Expand All @@ -32,6 +38,25 @@ impl Sats {

let haystacks = wallet.get_output_sat_ranges()?;

if self.all {
let mut ranges: Vec<(u64, u64)> = haystacks
.iter()
.flat_map(|(_, ranges)| ranges)
.cloned()
.collect();

ranges.sort_by(|a, b| a.0.cmp(&b.0));

let formatted_ranges: Vec<String> = ranges
.iter()
.map(|range| format!("{} - {}", range.0, range.1))
cryptoni9n marked this conversation as resolved.
Show resolved Hide resolved
.collect();

let result = format!("[{}]", formatted_ranges.join(", \n"));

println!("{}", result);
}

if let Some(path) = &self.tsv {
let tsv = fs::read_to_string(path)
.with_context(|| format!("I/O error reading `{}`", path.display()))?;
Expand Down
Loading