Skip to content

Commit

Permalink
quick fix
Browse files Browse the repository at this point in the history
  • Loading branch information
raphjaph committed Jul 15, 2023
1 parent 530e582 commit dcc6a6a
Showing 1 changed file with 46 additions and 12 deletions.
58 changes: 46 additions & 12 deletions src/subcommand/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,16 @@ impl List {
match index.list(self.outpoint)? {
Some(crate::index::List::Unspent(ranges)) => {
let mut outputs = Vec::new();
for (output, start, end, size, offset, 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,
Expand All @@ -48,20 +57,25 @@ impl List {
}
}

fn list(
outpoint: OutPoint,
ranges: Vec<(u64, u64)>,
) -> Vec<(OutPoint, u64, u64, u64, u64, Rarity, String)> {
fn list(outpoint: OutPoint, ranges: Vec<(u64, u64)>) -> Vec<Output> {
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 ret = (outpoint, start, end, size, offset, rarity, name);
let output = Output {
output: outpoint,
start,
end,
size,
offset,
name: Sat(start).name(),
rarity: Sat(start).rarity(),
};

offset += size;
ret

output
})
.collect()
}
Expand All @@ -70,6 +84,26 @@ fn list(
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 =
Expand All @@ -83,7 +117,7 @@ mod tests {
assert_eq!(
list(outpoint, ranges),
vec![
(
output(
OutPoint::from_str("4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b:5")
.unwrap(),
50 * COIN_VALUE,
Expand All @@ -93,7 +127,7 @@ mod tests {
Rarity::Uncommon,
"nvtcsezkbth".to_string()
),
(
output(
OutPoint::from_str("4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b:5")
.unwrap(),
10,
Expand All @@ -103,7 +137,7 @@ mod tests {
Rarity::Common,
"nvtdijuwxlf".to_string()
),
(
output(
OutPoint::from_str("4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b:5")
.unwrap(),
1050000000000000,
Expand Down

0 comments on commit dcc6a6a

Please sign in to comment.