From 8549c2bba1631caf754866a9c4766518fd02172c Mon Sep 17 00:00:00 2001 From: raphjaph Date: Fri, 25 Nov 2022 17:51:29 +0100 Subject: [PATCH 1/4] ord wallet list -> ord list-ranges --- src/subcommand.rs | 4 +- src/subcommand/wallet.rs | 2 - src/subcommand/wallet/list.rs | 76 ----------------------------------- tests/list.rs | 4 +- tests/wallet.rs | 16 -------- 5 files changed, 4 insertions(+), 98 deletions(-) delete mode 100644 src/subcommand/wallet/list.rs diff --git a/src/subcommand.rs b/src/subcommand.rs index c7d474186c..a2a2b284d4 100644 --- a/src/subcommand.rs +++ b/src/subcommand.rs @@ -18,7 +18,7 @@ pub(crate) enum Subcommand { Find(find::Find), Index, Info, - List(list::List), + ListRanges(list::List), Parse(parse::Parse), Range(range::Range), Server(server::Server), @@ -35,7 +35,7 @@ impl Subcommand { Self::Find(find) => find.run(options), Self::Index => index::run(options), Self::Info => info::run(options), - Self::List(list) => list.run(options), + Self::ListRanges(list) => list.run(options), Self::Parse(parse) => parse.run(), Self::Range(range) => range.run(), Self::Server(server) => { diff --git a/src/subcommand/wallet.rs b/src/subcommand/wallet.rs index 8b44659053..063fa2ebc2 100644 --- a/src/subcommand/wallet.rs +++ b/src/subcommand/wallet.rs @@ -42,7 +42,6 @@ fn get_change_addresses(options: &Options, n: usize) -> Result> { pub(crate) enum Wallet { Identify(identify::Identify), Inscribe(inscribe::Inscribe), - List, Send(send::Send), } @@ -51,7 +50,6 @@ impl Wallet { match self { Self::Identify(identify) => identify.run(options), Self::Inscribe(inscribe) => inscribe.run(options), - Self::List => list::run(options), Self::Send(send) => send.run(options), } } diff --git a/src/subcommand/wallet/list.rs b/src/subcommand/wallet/list.rs deleted file mode 100644 index cf86412af1..0000000000 --- a/src/subcommand/wallet/list.rs +++ /dev/null @@ -1,76 +0,0 @@ -use super::*; - -pub(crate) fn run(options: Options) -> Result { - let index = Index::open(&options)?; - index.update()?; - - let utxos = list_unspent(&options, &index)?; - - for (output, start, size, rarity, name) in list(utxos) { - println!("{output}\t{start}\t{size}\t{rarity}\t{name}"); - } - - Ok(()) -} - -fn list(utxos: Vec<(OutPoint, Vec<(u64, u64)>)>) -> Vec<(OutPoint, u64, u64, Rarity, String)> { - utxos - .into_iter() - .flat_map(|(output, ordinal_ranges)| { - ordinal_ranges.into_iter().map(move |(start, end)| { - let ordinal = Ordinal(start); - let rarity = ordinal.rarity(); - let name = ordinal.name(); - let size = end - start; - (output, start, size, rarity, name) - }) - }) - .collect() -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn list_ranges() { - let utxos = vec![ - ( - OutPoint::from_str("4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b:5") - .unwrap(), - vec![(50 * COIN_VALUE, 55 * COIN_VALUE)], - ), - ( - OutPoint::null(), - vec![(10, 100), (1050000000000000, 1150000000000000)], - ), - ]; - assert_eq!( - list(utxos), - vec![ - ( - OutPoint::from_str("4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b:5") - .unwrap(), - 50 * COIN_VALUE, - 5 * COIN_VALUE, - Rarity::Uncommon, - "nvtcsezkbth".to_string() - ), - ( - OutPoint::null(), - 10, - 90, - Rarity::Common, - "nvtdijuwxlf".to_string() - ), - ( - OutPoint::null(), - 1050000000000000, - 100000000000000, - Rarity::Epic, - "gkjbdrhkfqf".to_string() - ) - ] - ) - } -} diff --git a/tests/list.rs b/tests/list.rs index 1176423857..b8f16233d5 100644 --- a/tests/list.rs +++ b/tests/list.rs @@ -4,7 +4,7 @@ use super::*; fn output_found() { let rpc_server = test_bitcoincore_rpc::spawn(); CommandBuilder::new( - "--index-ordinals list 4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b:0", + "--index-ordinals list-ranges 4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b:0", ) .rpc_server(&rpc_server) .expected_stdout("[0,5000000000)\n") @@ -15,7 +15,7 @@ fn output_found() { fn output_not_found() { let rpc_server = test_bitcoincore_rpc::spawn(); CommandBuilder::new( - "--index-ordinals list 0000000000000000000000000000000000000000000000000000000000000000:0", + "--index-ordinals list-ranges 0000000000000000000000000000000000000000000000000000000000000000:0", ) .rpc_server(&rpc_server) .expected_exit_code(1) diff --git a/tests/wallet.rs b/tests/wallet.rs index 2204190826..6e397ef507 100644 --- a/tests/wallet.rs +++ b/tests/wallet.rs @@ -55,22 +55,6 @@ fn identify_from_tsv_file_not_found() { .run(); } -#[test] -fn list() { - let rpc_server = test_bitcoincore_rpc::spawn(); - let second_coinbase = rpc_server.mine_blocks(1)[0].txdata[0].txid(); - - CommandBuilder::new("--index-ordinals wallet list") - .rpc_server(&rpc_server) - .expected_stdout(format!( - "{}\t{}\t{}\tuncommon\tnvtcsezkbth\n", - OutPoint::new(second_coinbase, 0), - 50 * COIN_VALUE, - 50 * COIN_VALUE, - )) - .run(); -} - #[test] fn send_works_on_signet() { let rpc_server = test_bitcoincore_rpc::spawn_with(Network::Signet, "ord"); From 167221f5583e7f6b586ce9f3f734e7a90b0b1c06 Mon Sep 17 00:00:00 2001 From: raphjaph Date: Fri, 25 Nov 2022 17:56:33 +0100 Subject: [PATCH 2/4] placate clippy --- src/subcommand/wallet.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/subcommand/wallet.rs b/src/subcommand/wallet.rs index 063fa2ebc2..5944485b64 100644 --- a/src/subcommand/wallet.rs +++ b/src/subcommand/wallet.rs @@ -2,7 +2,6 @@ use {super::*, transaction_builder::TransactionBuilder}; mod identify; mod inscribe; -mod list; mod send; mod transaction_builder; From c2d1a66271561114ed7f883807c5a2156b11a5eb Mon Sep 17 00:00:00 2001 From: raphjaph Date: Fri, 25 Nov 2022 20:09:32 +0100 Subject: [PATCH 3/4] better output --- src/subcommand/list.rs | 7 ++++++- tests/list.rs | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/subcommand/list.rs b/src/subcommand/list.rs index 795a7eecbb..8d9ff09546 100644 --- a/src/subcommand/list.rs +++ b/src/subcommand/list.rs @@ -15,7 +15,12 @@ impl List { match index.list(self.outpoint)? { Some(crate::index::List::Unspent(ranges)) => { for (start, end) in ranges { - println!("[{start},{end})"); + let size = end - start; + let output = self.outpoint; + let rarity = Ordinal(start).rarity(); + let name = Ordinal(start).name(); + + println!("{output}\t{start}\t{size}\t{rarity}\t{name}"); } Ok(()) } diff --git a/tests/list.rs b/tests/list.rs index b8f16233d5..92562f2436 100644 --- a/tests/list.rs +++ b/tests/list.rs @@ -7,7 +7,7 @@ fn output_found() { "--index-ordinals list-ranges 4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b:0", ) .rpc_server(&rpc_server) - .expected_stdout("[0,5000000000)\n") + .expected_stdout("4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b:0\t0\t5000000000\tmythic\tnvtdijuwxlp\n") .run(); } From 8b8919d4d91f7cb1564a1fcaea1adebcf7e7f802 Mon Sep 17 00:00:00 2001 From: raphjaph Date: Fri, 25 Nov 2022 20:38:12 +0100 Subject: [PATCH 4/4] added test --- src/subcommand/list.rs | 67 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 61 insertions(+), 6 deletions(-) diff --git a/src/subcommand/list.rs b/src/subcommand/list.rs index 8d9ff09546..75d2c2f85e 100644 --- a/src/subcommand/list.rs +++ b/src/subcommand/list.rs @@ -14,14 +14,10 @@ impl List { match index.list(self.outpoint)? { Some(crate::index::List::Unspent(ranges)) => { - for (start, end) in ranges { - let size = end - start; - let output = self.outpoint; - let rarity = Ordinal(start).rarity(); - let name = Ordinal(start).name(); - + for (output, start, size, rarity, name) in list(self.outpoint, ranges) { println!("{output}\t{start}\t{size}\t{rarity}\t{name}"); } + Ok(()) } Some(crate::index::List::Spent) => Err(anyhow!("output spent.")), @@ -29,3 +25,62 @@ impl List { } } } + +fn list(outpoint: OutPoint, ranges: Vec<(u64, u64)>) -> Vec<(OutPoint, u64, u64, Rarity, String)> { + ranges + .into_iter() + .map(|(start, end)| { + let size = end - start; + let rarity = Ordinal(start).rarity(); + let name = Ordinal(start).name(); + + (outpoint, start, size, rarity, name) + }) + .collect() +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn list_ranges() { + let outpoint = + OutPoint::from_str("4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b:5") + .unwrap(); + let ranges = vec![ + (50 * COIN_VALUE, 55 * COIN_VALUE), + (10, 100), + (1050000000000000, 1150000000000000), + ]; + assert_eq!( + list(outpoint, ranges), + vec![ + ( + OutPoint::from_str("4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b:5") + .unwrap(), + 50 * COIN_VALUE, + 5 * COIN_VALUE, + Rarity::Uncommon, + "nvtcsezkbth".to_string() + ), + ( + OutPoint::from_str("4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b:5") + .unwrap(), + 10, + 90, + Rarity::Common, + "nvtdijuwxlf".to_string() + ), + ( + OutPoint::from_str("4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b:5") + .unwrap(), + 1050000000000000, + 100000000000000, + Rarity::Epic, + "gkjbdrhkfqf".to_string() + ) + ] + ) + } +}