Skip to content

Commit

Permalink
Suppress printing sat_ranges by default (ordinals#3867)
Browse files Browse the repository at this point in the history
  • Loading branch information
cryptoni9n authored Aug 5, 2024
1 parent ba9d8c3 commit b5c7bbe
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
17 changes: 10 additions & 7 deletions src/subcommand/wallet/outputs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,24 @@ pub(crate) struct Outputs {
pub struct Output {
pub output: OutPoint,
pub amount: u64,
pub sat_ranges: Vec<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub sat_ranges: Option<Vec<String>>,
}

impl Outputs {
pub(crate) fn run(&self, wallet: Wallet) -> SubcommandResult {
let mut outputs = Vec::new();
for (output, txout) in wallet.utxos() {
let sat_ranges = if wallet.has_sat_index() && self.ranges {
wallet
.get_output_sat_ranges(output)?
.into_iter()
.map(|(start, end)| format!("{start}-{end}"))
.collect()
Some(
wallet
.get_output_sat_ranges(output)?
.into_iter()
.map(|(start, end)| format!("{start}-{end}"))
.collect(),
)
} else {
Vec::new()
None
};

outputs.push(Output {
Expand Down
8 changes: 7 additions & 1 deletion tests/wallet/outputs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ fn outputs() {

assert_eq!(output[0].output, outpoint);
assert_eq!(output[0].amount, amount);
assert!(output[0].sat_ranges.is_none());
}

#[test]
Expand All @@ -42,6 +43,7 @@ fn outputs_includes_locked_outputs() {

assert_eq!(output[0].output, outpoint);
assert_eq!(output[0].amount, amount);
assert!(output[0].sat_ranges.is_none());
}

#[test]
Expand All @@ -65,6 +67,7 @@ fn outputs_includes_unbound_outputs() {

assert_eq!(output[0].output, outpoint);
assert_eq!(output[0].amount, amount);
assert!(output[0].sat_ranges.is_none());
}

#[test]
Expand All @@ -86,5 +89,8 @@ fn outputs_includes_sat_ranges() {

assert_eq!(output[0].output, outpoint);
assert_eq!(output[0].amount, amount);
assert_eq!(output[0].sat_ranges, vec!["5000000000-5001000000"]);
assert_eq!(
output[0].sat_ranges,
Some(vec!["5000000000-5001000000".to_string()])
);
}

0 comments on commit b5c7bbe

Please sign in to comment.