From 5a0acf24b21e7ac4d91bd699340e7997b6ec4ecb Mon Sep 17 00:00:00 2001 From: gmart7t2 <49558347+gmart7t2@users.noreply.github.com> Date: Sat, 15 Jul 2023 19:44:49 -0300 Subject: [PATCH] Modify `ord list` output to include the end of each range (#1998) --- src/subcommand/list.rs | 65 ++++++++++++++++++++++++++++++++++++------ tests/list.rs | 2 ++ 2 files changed, 59 insertions(+), 8 deletions(-) diff --git a/src/subcommand/list.rs b/src/subcommand/list.rs index b1193638fe..4ec93b14b0 100644 --- a/src/subcommand/list.rs +++ b/src/subcommand/list.rs @@ -10,7 +10,9 @@ pub(crate) struct List { pub struct Output { pub output: OutPoint, pub start: u64, + pub end: u64, pub size: u64, + pub offset: u64, pub rarity: Rarity, pub name: String, } @@ -24,11 +26,22 @@ impl List { match index.list(self.outpoint)? { Some(crate::index::List::Unspent(ranges)) => { let mut outputs = Vec::new(); - for (output, start, size, rarity, name) in list(self.outpoint, ranges) { + for Output { + output, + start, + end, + size, + offset, + rarity, + name, + } in list(self.outpoint, ranges) + { outputs.push(Output { output, start, + end, size, + offset, rarity, name, }); @@ -44,15 +57,25 @@ impl List { } } -fn list(outpoint: OutPoint, ranges: Vec<(u64, u64)>) -> Vec<(OutPoint, u64, u64, Rarity, String)> { +fn list(outpoint: OutPoint, ranges: Vec<(u64, u64)>) -> Vec { + let mut offset = 0; ranges .into_iter() .map(|(start, end)| { let size = end - start; - let rarity = Sat(start).rarity(); - let name = Sat(start).name(); + let output = Output { + output: outpoint, + start, + end, + size, + offset, + name: Sat(start).name(), + rarity: Sat(start).rarity(), + }; - (outpoint, start, size, rarity, name) + offset += size; + + output }) .collect() } @@ -61,6 +84,26 @@ fn list(outpoint: OutPoint, ranges: Vec<(u64, u64)>) -> Vec<(OutPoint, u64, u64, mod tests { use super::*; + fn output( + output: OutPoint, + start: u64, + end: u64, + size: u64, + offset: u64, + rarity: Rarity, + name: String, + ) -> Output { + Output { + output, + start, + end, + size, + offset, + name, + rarity, + } + } + #[test] fn list_ranges() { let outpoint = @@ -74,27 +117,33 @@ mod tests { assert_eq!( list(outpoint, ranges), vec![ - ( + output( OutPoint::from_str("4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b:5") .unwrap(), 50 * COIN_VALUE, + 55 * COIN_VALUE, 5 * COIN_VALUE, + 0, Rarity::Uncommon, "nvtcsezkbth".to_string() ), - ( + output( OutPoint::from_str("4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b:5") .unwrap(), 10, + 100, 90, + 5 * COIN_VALUE, Rarity::Common, "nvtdijuwxlf".to_string() ), - ( + output( OutPoint::from_str("4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b:5") .unwrap(), 1050000000000000, + 1150000000000000, 100000000000000, + 5 * COIN_VALUE + 90, Rarity::Epic, "gkjbdrhkfqf".to_string() ) diff --git a/tests/list.rs b/tests/list.rs index bb54633bb3..8b82267d3b 100644 --- a/tests/list.rs +++ b/tests/list.rs @@ -16,7 +16,9 @@ fn output_found() { .parse() .unwrap(), start: 0, + end: 50 * COIN_VALUE, size: 50 * COIN_VALUE, + offset: 0, rarity: "mythic".parse().unwrap(), name: "nvtdijuwxlp".into(), }]