From af8a59834432e6330505a1888d3c58eb307b3b49 Mon Sep 17 00:00:00 2001 From: raphjaph Date: Thu, 19 Dec 2024 18:48:42 -0500 Subject: [PATCH 01/18] Return None if index does not have index --- src/api.rs | 8 ++--- src/index.rs | 55 ++++++++++++++++++------------ src/subcommand/list.rs | 4 +-- src/subcommand/server.rs | 40 +++++++++++++--------- src/subcommand/wallet/addresses.rs | 1 + src/subcommand/wallet/balance.rs | 4 ++- src/subcommand/wallet/outputs.rs | 1 + src/subcommand/wallet/runics.rs | 6 +++- src/subcommand/wallet/split.rs | 1 + src/templates/output.rs | 8 ++--- src/wallet.rs | 15 +++++--- src/wallet/wallet_constructor.rs | 2 +- templates/output.html | 8 ++--- 13 files changed, 94 insertions(+), 59 deletions(-) diff --git a/src/api.rs b/src/api.rs index eae5ac144a..b780c07eb7 100644 --- a/src/api.rs +++ b/src/api.rs @@ -155,9 +155,9 @@ pub struct Inscriptions { pub struct Output { pub address: Option>, pub indexed: bool, - pub inscriptions: Vec, + pub inscriptions: Option>, pub outpoint: OutPoint, - pub runes: BTreeMap, + pub runes: Option>, pub sat_ranges: Option>, pub script_pubkey: ScriptBuf, pub spent: bool, @@ -168,11 +168,11 @@ pub struct Output { impl Output { pub fn new( chain: Chain, - inscriptions: Vec, + inscriptions: Option>, outpoint: OutPoint, tx_out: TxOut, indexed: bool, - runes: BTreeMap, + runes: Option>, sat_ranges: Option>, spent: bool, ) -> Self { diff --git a/src/index.rs b/src/index.rs index 924c795391..ef601e302f 100644 --- a/src/index.rs +++ b/src/index.rs @@ -1019,7 +1019,11 @@ impl Index { pub fn get_rune_balances_for_output( &self, outpoint: OutPoint, - ) -> Result> { + ) -> Result>> { + if !self.index_runes { + return Ok(None); + } + let rtx = self.database.begin_read()?; let outpoint_to_balances = rtx.open_table(OUTPOINT_TO_RUNE_BALANCES)?; @@ -1027,7 +1031,7 @@ impl Index { let id_to_rune_entries = rtx.open_table(RUNE_ID_TO_RUNE_ENTRY)?; let Some(balances) = outpoint_to_balances.get(&outpoint.store())? else { - return Ok(BTreeMap::new()); + return Ok(Some(BTreeMap::new())); }; let balances_buffer = balances.value(); @@ -1050,7 +1054,7 @@ impl Index { ); } - Ok(balances) + Ok(Some(balances)) } pub fn get_rune_balance_map(&self) -> Result>> { @@ -1546,14 +1550,21 @@ impl Index { ) } - pub fn get_inscriptions_for_output(&self, outpoint: OutPoint) -> Result> { - Ok( + pub fn get_inscriptions_for_output( + &self, + outpoint: OutPoint, + ) -> Result>> { + if !self.index_inscriptions { + return Ok(None); + } + + Ok(Some( self .get_inscriptions_on_output_with_satpoints(outpoint)? .iter() .map(|(_satpoint, inscription_id)| *inscription_id) .collect(), - ) + )) } pub fn get_inscriptions_for_outputs( @@ -2292,22 +2303,22 @@ impl Index { let mut runes = BTreeMap::new(); for output in outputs { - let rune_balances = self.get_rune_balances_for_output(*output)?; - - for (spaced_rune, pile) in rune_balances { - runes - .entry(spaced_rune) - .and_modify(|(decimal, _symbol): &mut (Decimal, Option)| { - assert_eq!(decimal.scale, pile.divisibility); - decimal.value += pile.amount; - }) - .or_insert(( - Decimal { - value: pile.amount, - scale: pile.divisibility, - }, - pile.symbol, - )); + if let Some(rune_balances) = self.get_rune_balances_for_output(*output)? { + for (spaced_rune, pile) in rune_balances { + runes + .entry(spaced_rune) + .and_modify(|(decimal, _symbol): &mut (Decimal, Option)| { + assert_eq!(decimal.scale, pile.divisibility); + decimal.value += pile.amount; + }) + .or_insert(( + Decimal { + value: pile.amount, + scale: pile.divisibility, + }, + pile.symbol, + )); + } } } diff --git a/src/subcommand/list.rs b/src/subcommand/list.rs index b790a621e8..d5892e36c1 100644 --- a/src/subcommand/list.rs +++ b/src/subcommand/list.rs @@ -10,8 +10,8 @@ pub(crate) struct List { pub struct Output { pub address: Option>, pub indexed: bool, - pub inscriptions: Vec, - pub runes: BTreeMap, + pub inscriptions: Option>, + pub runes: Option>, pub sat_ranges: Option>, pub script_pubkey: String, pub spent: bool, diff --git a/src/subcommand/server.rs b/src/subcommand/server.rs index 38e501f4ed..1247c394ab 100644 --- a/src/subcommand/server.rs +++ b/src/subcommand/server.rs @@ -759,12 +759,18 @@ impl Server { index .get_inscriptions_on_output_with_satpoints(output)? .is_empty() - && index.get_rune_balances_for_output(output)?.is_empty() + && index + .get_rune_balances_for_output(output)? + .unwrap_or_default() + .is_empty() } OutputType::Inscribed => !index .get_inscriptions_on_output_with_satpoints(output)? .is_empty(), - OutputType::Runic => !index.get_rune_balances_for_output(output)?.is_empty(), + OutputType::Runic => !index + .get_rune_balances_for_output(output)? + .unwrap_or_default() + .is_empty(), }; if include { @@ -3728,21 +3734,23 @@ mod tests { transaction: txid, sat_ranges: None, indexed: true, - inscriptions: Vec::new(), + inscriptions: None, outpoint: output, - runes: vec![( - SpacedRune { - rune: Rune(RUNE), - spacers: 0 - }, - Pile { - amount: 340282366920938463463374607431768211455, - divisibility: 1, - symbol: None, - } - )] - .into_iter() - .collect(), + runes: Some( + vec![( + SpacedRune { + rune: Rune(RUNE), + spacers: 0 + }, + Pile { + amount: 340282366920938463463374607431768211455, + divisibility: 1, + symbol: None, + } + )] + .into_iter() + .collect() + ), spent: false, } ); diff --git a/src/subcommand/wallet/addresses.rs b/src/subcommand/wallet/addresses.rs index f8db7b3a06..36243f2de0 100644 --- a/src/subcommand/wallet/addresses.rs +++ b/src/subcommand/wallet/addresses.rs @@ -26,6 +26,7 @@ pub(crate) fn run(wallet: Wallet) -> SubcommandResult { Some( wallet .get_runes_balances_in_output(output)? + .unwrap_or_default() .iter() .map(|(rune, pile)| { ( diff --git a/src/subcommand/wallet/balance.rs b/src/subcommand/wallet/balance.rs index bda1b72cf5..b7a5445532 100644 --- a/src/subcommand/wallet/balance.rs +++ b/src/subcommand/wallet/balance.rs @@ -26,7 +26,9 @@ pub(crate) fn run(wallet: Wallet) -> SubcommandResult { let mut runic = 0; for (output, txout) in unspent_outputs { - let rune_balances = wallet.get_runes_balances_in_output(output)?; + let rune_balances = wallet + .get_runes_balances_in_output(output)? + .unwrap_or_default(); let is_ordinal = inscription_outputs.contains(output); let is_runic = !rune_balances.is_empty(); diff --git a/src/subcommand/wallet/outputs.rs b/src/subcommand/wallet/outputs.rs index 1bddcaeff1..2cd6f062cf 100644 --- a/src/subcommand/wallet/outputs.rs +++ b/src/subcommand/wallet/outputs.rs @@ -40,6 +40,7 @@ impl Outputs { Some( wallet .get_runes_balances_in_output(output)? + .unwrap_or_default() .iter() .map(|(rune, pile)| { ( diff --git a/src/subcommand/wallet/runics.rs b/src/subcommand/wallet/runics.rs index 12631e0e70..651e4ed5f6 100644 --- a/src/subcommand/wallet/runics.rs +++ b/src/subcommand/wallet/runics.rs @@ -14,7 +14,11 @@ pub(crate) fn run(wallet: Wallet) -> SubcommandResult { .iter() .filter_map(|(output, _)| { if runic_utxos.contains(output) { - let rune_balances = wallet.get_runes_balances_in_output(output).ok()?; + let rune_balances = wallet + .get_runes_balances_in_output(output) + .ok()? + .unwrap_or_default(); + let mut runes = BTreeMap::new(); for (spaced_rune, pile) in rune_balances { diff --git a/src/subcommand/wallet/split.rs b/src/subcommand/wallet/split.rs index 1342a34fea..dd35f348c1 100644 --- a/src/subcommand/wallet/split.rs +++ b/src/subcommand/wallet/split.rs @@ -120,6 +120,7 @@ impl Split { ( output, balance + .unwrap_or_default() .into_iter() .map(|(spaced_rune, pile)| (spaced_rune.rune, pile.amount)) .collect(), diff --git a/src/templates/output.rs b/src/templates/output.rs index 235403cff8..3abd819c39 100644 --- a/src/templates/output.rs +++ b/src/templates/output.rs @@ -3,10 +3,10 @@ use super::*; #[derive(Boilerplate)] pub(crate) struct OutputHtml { pub(crate) chain: Chain, - pub(crate) inscriptions: Vec, + pub(crate) inscriptions: Option>, pub(crate) outpoint: OutPoint, pub(crate) output: TxOut, - pub(crate) runes: BTreeMap, + pub(crate) runes: Option>, pub(crate) sat_ranges: Option>, pub(crate) spent: bool, } @@ -29,10 +29,10 @@ mod tests { assert_regex_match!( OutputHtml { chain: Chain::Mainnet, - inscriptions: Vec::new(), + inscriptions: Some(Vec::new()), outpoint: outpoint(1), output: TxOut { value: Amount::from_sat(3), script_pubkey: ScriptBuf::new_p2pkh(&PubkeyHash::all_zeros()), }, - runes: BTreeMap::new(), + runes: Some(BTreeMap::new()), sat_ranges: Some(vec![(0, 1), (1, 3)]), spent: false, }, diff --git a/src/wallet.rs b/src/wallet.rs index f45fc9dd6a..5de258f498 100644 --- a/src/wallet.rs +++ b/src/wallet.rs @@ -218,7 +218,13 @@ impl Wallet { } pub(crate) fn get_inscriptions_in_output(&self, output: &OutPoint) -> Vec { - self.output_info.get(output).unwrap().inscriptions.clone() + self + .output_info + .get(output) + .unwrap() + .inscriptions + .clone() + .unwrap_or_default() } pub(crate) fn get_parent_info(&self, parents: &[InscriptionId]) -> Result> { @@ -253,8 +259,8 @@ impl Wallet { pub(crate) fn get_runic_outputs(&self) -> Result> { let mut runic_outputs = BTreeSet::new(); - for (output, info) in self.output_info.iter() { - if !info.runes.is_empty() { + for (output, info) in &self.output_info { + if !info.runes.clone().unwrap_or_default().is_empty() { runic_outputs.insert(*output); } } @@ -265,7 +271,7 @@ impl Wallet { pub(crate) fn get_runes_balances_in_output( &self, output: &OutPoint, - ) -> Result> { + ) -> Result>> { Ok( self .output_info @@ -947,6 +953,7 @@ impl Wallet { ( output, balance + .unwrap_or_default() .into_iter() .map(|(spaced_rune, pile)| (spaced_rune.rune, pile.amount)) .collect(), diff --git a/src/wallet/wallet_constructor.rs b/src/wallet/wallet_constructor.rs index b5e43c84fe..fcc0ee70ca 100644 --- a/src/wallet/wallet_constructor.rs +++ b/src/wallet/wallet_constructor.rs @@ -118,7 +118,7 @@ impl WalletConstructor { let inscriptions = output_info .iter() - .flat_map(|(_output, info)| info.inscriptions.clone()) + .flat_map(|(_output, info)| info.inscriptions.clone().unwrap_or_default()) .collect::>(); let (inscriptions, inscription_info) = self.get_inscriptions(&inscriptions)?; diff --git a/templates/output.html b/templates/output.html index 2cd281a162..a67573a125 100644 --- a/templates/output.html +++ b/templates/output.html @@ -1,14 +1,14 @@

Output {{self.outpoint}}

-%% if !self.inscriptions.is_empty() { +%% if let Some(inscriptions) = &self.inscriptions {
inscriptions
-%% for inscription in &self.inscriptions { +%% for inscription in inscriptions { {{Iframe::thumbnail(*inscription)}} %% }
%% } -%% if !self.runes.is_empty() { +%% if let Some(runes) = &self.runes {
runes
@@ -16,7 +16,7 @@

Output {{self.outpoint}}

-%% for (rune, balance) in &self.runes { +%% for (rune, balance) in runes { From 5beb44968959eb4f134ba116769b6a6d1cefc2b4 Mon Sep 17 00:00:00 2001 From: raphjaph Date: Thu, 19 Dec 2024 18:59:39 -0500 Subject: [PATCH 02/18] Amend --- src/index.rs | 15 +++++++++----- src/templates/output.rs | 46 +++++++++++++++++++++-------------------- tests/json_api.rs | 31 +++++++++++++++------------ tests/list.rs | 4 ++-- tests/wallet/send.rs | 6 +++--- 5 files changed, 57 insertions(+), 45 deletions(-) diff --git a/src/index.rs b/src/index.rs index ef601e302f..a3403fc8d2 100644 --- a/src/index.rs +++ b/src/index.rs @@ -3486,7 +3486,8 @@ mod tests { context .index .get_inscriptions_for_output(OutPoint { txid, vout: 0 }) - .unwrap(), + .unwrap() + .unwrap_or_default(), [] ); @@ -3496,7 +3497,8 @@ mod tests { context .index .get_inscriptions_for_output(OutPoint { txid, vout: 0 }) - .unwrap(), + .unwrap() + .unwrap_or_default(), [inscription_id] ); @@ -3511,7 +3513,8 @@ mod tests { context .index .get_inscriptions_for_output(OutPoint { txid, vout: 0 }) - .unwrap(), + .unwrap() + .unwrap_or_default(), [] ); @@ -3522,7 +3525,8 @@ mod tests { txid: send_id, vout: 0, }) - .unwrap(), + .unwrap() + .unwrap_or_default(), [inscription_id] ); } @@ -3552,7 +3556,8 @@ mod tests { txid: first, vout: 0 }) - .unwrap(), + .unwrap() + .unwrap_or_default(), [inscription_id] ); diff --git a/src/templates/output.rs b/src/templates/output.rs index 3abd819c39..23da2b64e9 100644 --- a/src/templates/output.rs +++ b/src/templates/output.rs @@ -60,13 +60,13 @@ mod tests { assert_regex_match!( OutputHtml { chain: Chain::Mainnet, - inscriptions: Vec::new(), + inscriptions: None, outpoint: outpoint(1), output: TxOut { value: Amount::from_sat(1), script_pubkey: script::Builder::new().push_int(0).into_script(), }, - runes: BTreeMap::new(), + runes: None, sat_ranges: None, spent: true, }, @@ -88,10 +88,10 @@ mod tests { assert_regex_match!( OutputHtml { chain: Chain::Mainnet, - inscriptions: Vec::new(), + inscriptions: None, outpoint: outpoint(1), output: TxOut { value: Amount::from_sat(3), script_pubkey: ScriptBuf::new_p2pkh(&PubkeyHash::all_zeros()), }, - runes: BTreeMap::new(), + runes: None, sat_ranges: Some(vec![(0, 1), (1, 3)]), spent: true, }, @@ -119,10 +119,10 @@ mod tests { assert_regex_match!( OutputHtml { chain: Chain::Mainnet, - inscriptions: Vec::new(), + inscriptions: None, outpoint: outpoint(1), output: TxOut { value: Amount::from_sat(3), script_pubkey: ScriptBuf::new_p2pkh(&PubkeyHash::all_zeros()), }, - runes: BTreeMap::new(), + runes: None, sat_ranges: None, spent: false, } @@ -146,13 +146,13 @@ mod tests { assert_regex_match!( OutputHtml { chain: Chain::Mainnet, - inscriptions: vec![inscription_id(1)], + inscriptions: Some(vec![inscription_id(1)]), outpoint: outpoint(1), output: TxOut { value: Amount::from_sat(3), script_pubkey: ScriptBuf::new_p2pkh(&PubkeyHash::all_zeros()), }, - runes: BTreeMap::new(), + runes: None, sat_ranges: None, spent: false, }, @@ -175,25 +175,27 @@ mod tests { assert_regex_match!( OutputHtml { chain: Chain::Mainnet, - inscriptions: Vec::new(), + inscriptions: None, outpoint: outpoint(1), output: TxOut { value: Amount::from_sat(3), script_pubkey: ScriptBuf::new_p2pkh(&PubkeyHash::all_zeros()), }, - runes: vec![( - SpacedRune { - rune: Rune(26), - spacers: 1 - }, - Pile { - amount: 11, - divisibility: 1, - symbol: None, - } - )] - .into_iter() - .collect(), + runes: Some( + vec![( + SpacedRune { + rune: Rune(26), + spacers: 1 + }, + Pile { + amount: 11, + divisibility: 1, + symbol: None, + } + )] + .into_iter() + .collect() + ), sat_ranges: None, spent: false, }, diff --git a/tests/json_api.rs b/tests/json_api.rs index 6ef28b2ae6..5606d7929b 100644 --- a/tests/json_api.rs +++ b/tests/json_api.rs @@ -406,13 +406,13 @@ fn get_output() { .unwrap() ), outpoint: OutPoint { txid, vout: 0 }, - inscriptions: vec![ + inscriptions: Some(vec![ InscriptionId { txid, index: 0 }, InscriptionId { txid, index: 1 }, InscriptionId { txid, index: 2 }, - ], + ]), indexed: true, - runes: BTreeMap::new(), + runes: None, sat_ranges: Some(vec![ (5000000000, 10000000000,), (10000000000, 15000000000,), @@ -809,13 +809,13 @@ fn outputs_address() { cardinals_json, vec![api::Output { address: Some(address.parse().unwrap()), - inscriptions: vec![], + inscriptions: Some(vec![]), outpoint: OutPoint { txid: cardinal_send.txid, vout: 0 }, indexed: true, - runes: BTreeMap::new(), + runes: Some(BTreeMap::new()), sat_ranges: None, script_pubkey: ScriptBuf::from( address @@ -853,13 +853,13 @@ fn outputs_address() { runes_json, vec![api::Output { address: Some(address.parse().unwrap()), - inscriptions: vec![], + inscriptions: Some(vec![]), outpoint: OutPoint { txid: rune_send.txid, vout: 0 }, indexed: true, - runes: expected_runes, + runes: Some(expected_runes), sat_ranges: None, script_pubkey: ScriptBuf::from( address @@ -884,16 +884,16 @@ fn outputs_address() { inscriptions_json, vec![api::Output { address: Some(address.parse().unwrap()), - inscriptions: vec![InscriptionId { + inscriptions: Some(vec![InscriptionId { txid: reveal, index: 0 - },], + },]), outpoint: OutPoint { txid: inscription_send.txid, vout: 0 }, indexed: true, - runes: BTreeMap::new(), + runes: Some(BTreeMap::new()), sat_ranges: None, script_pubkey: ScriptBuf::from( address @@ -924,11 +924,16 @@ fn outputs_address() { .unwrap(); assert_eq!(any.len(), 3); - assert!(any.iter().any(|output| output.runes.len() == 1)); - assert!(any.iter().any(|output| output.inscriptions.len() == 1)); assert!(any .iter() - .any(|output| output.inscriptions.is_empty() && output.runes.is_empty())); + .any(|output| output.runes.clone().unwrap_or_default().len() == 1)); + assert!(any + .iter() + .any(|output| output.inscriptions.clone().unwrap_or_default().len() == 1)); + assert!(any.iter().any( + |output| output.inscriptions.clone().unwrap_or_default().is_empty() + && output.runes.clone().unwrap_or_default().is_empty() + )); assert_eq!(any, default); } diff --git a/tests/list.rs b/tests/list.rs index 58dde2edee..199c5ceb59 100644 --- a/tests/list.rs +++ b/tests/list.rs @@ -17,8 +17,8 @@ fn output_found() { Output { address: None, indexed: true, - inscriptions: vec![], - runes: BTreeMap::new(), + inscriptions: Some(Vec::new()), + runes: None, sat_ranges: Some(vec![Range { end: 50 * COIN_VALUE, name: "nvtdijuwxlp".into(), diff --git a/tests/wallet/send.rs b/tests/wallet/send.rs index 2d843f65b8..48287a728e 100644 --- a/tests/wallet/send.rs +++ b/tests/wallet/send.rs @@ -349,7 +349,7 @@ inscriptions: txid: reveal_txid, vout: 0 }, - inscriptions: vec![ + inscriptions: Some(vec![ InscriptionId { txid: reveal_txid, index: 0 @@ -362,9 +362,9 @@ inscriptions: txid: reveal_txid, index: 2 }, - ], + ]), indexed: true, - runes: BTreeMap::new(), + runes: Some(BTreeMap::new()), sat_ranges: Some(vec![(5_000_000_000, 5_000_030_000)]), script_pubkey: destination.assume_checked_ref().script_pubkey(), spent: false, From fcdfe42fbb54e46ccf6aa36272f630acfa14b762 Mon Sep 17 00:00:00 2001 From: raphjaph Date: Thu, 19 Dec 2024 19:15:33 -0500 Subject: [PATCH 03/18] Amend --- src/subcommand/server.rs | 2 +- templates/output.html | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/subcommand/server.rs b/src/subcommand/server.rs index 1247c394ab..28c0aa38bd 100644 --- a/src/subcommand/server.rs +++ b/src/subcommand/server.rs @@ -3734,7 +3734,7 @@ mod tests { transaction: txid, sat_ranges: None, indexed: true, - inscriptions: None, + inscriptions: Some(Vec::new()), outpoint: output, runes: Some( vec![( diff --git a/templates/output.html b/templates/output.html index a67573a125..7c97557d87 100644 --- a/templates/output.html +++ b/templates/output.html @@ -1,14 +1,16 @@

Output {{self.outpoint}}

-%% if let Some(inscriptions) = &self.inscriptions { +%% let inscriptions = self.inscriptions.clone().unwrap_or_default(); +%% if !inscriptions.is_empty() {
inscriptions
-%% for inscription in inscriptions { +%% for inscription in &inscriptions { {{Iframe::thumbnail(*inscription)}} %% }
%% } -%% if let Some(runes) = &self.runes { +%% let runes = self.runes.clone().unwrap_or_default(); +%% if !runes.is_empty() {
runes
rune balance
{{ rune }} {{ balance }}
@@ -16,7 +18,7 @@

Output {{self.outpoint}}

-%% for (rune, balance) in runes { +%% for (rune, balance) in &runes { From eb491b263079a3362dae461bf1902ed95472c5e7 Mon Sep 17 00:00:00 2001 From: raphjaph Date: Thu, 19 Dec 2024 19:38:13 -0500 Subject: [PATCH 04/18] Amend --- tests/wallet/send.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/wallet/send.rs b/tests/wallet/send.rs index 48287a728e..11e2fc9602 100644 --- a/tests/wallet/send.rs +++ b/tests/wallet/send.rs @@ -364,7 +364,7 @@ inscriptions: }, ]), indexed: true, - runes: Some(BTreeMap::new()), + runes: None, sat_ranges: Some(vec![(5_000_000_000, 5_000_030_000)]), script_pubkey: destination.assume_checked_ref().script_pubkey(), spent: false, From 3d8554baec23e0a593835e0889358fa3218a2781 Mon Sep 17 00:00:00 2001 From: raphjaph Date: Thu, 19 Dec 2024 19:58:29 -0500 Subject: [PATCH 05/18] Fix other spots --- src/api.rs | 4 +- src/index.rs | 87 ++++++++++++++++++++++++---------------- src/subcommand/server.rs | 2 + src/templates/address.rs | 10 ++--- templates/address.html | 10 +++-- 5 files changed, 68 insertions(+), 45 deletions(-) diff --git a/src/api.rs b/src/api.rs index b780c07eb7..5b335c48e0 100644 --- a/src/api.rs +++ b/src/api.rs @@ -229,7 +229,7 @@ pub struct SatInscriptions { #[derive(Debug, PartialEq, Serialize, Deserialize)] pub struct AddressInfo { pub outputs: Vec, - pub inscriptions: Vec, + pub inscriptions: Option>, pub sat_balance: u64, - pub runes_balances: Vec<(SpacedRune, Decimal, Option)>, + pub runes_balances: Option)>>, } diff --git a/src/index.rs b/src/index.rs index 830c8b412b..1b59f97bf2 100644 --- a/src/index.rs +++ b/src/index.rs @@ -1538,7 +1538,11 @@ impl Index { pub fn get_inscriptions_on_output_with_satpoints( &self, outpoint: OutPoint, - ) -> Result> { + ) -> Result>> { + if !self.index_inscriptions { + return Ok(None); + } + let rtx = self.database.begin_read()?; let outpoint_to_utxo_entry = rtx.open_table(OUTPOINT_TO_UTXO_ENTRY)?; let sequence_number_to_inscription_entry = @@ -1562,6 +1566,7 @@ impl Index { Ok(Some( self .get_inscriptions_on_output_with_satpoints(outpoint)? + .unwrap_or_default() .iter() .map(|(_satpoint, inscription_id)| *inscription_id) .collect(), @@ -1571,18 +1576,23 @@ impl Index { pub fn get_inscriptions_for_outputs( &self, outpoints: &Vec, - ) -> Result> { + ) -> Result>> { + if !self.index_inscriptions { + return Ok(None); + } + let mut inscriptions = Vec::new(); for outpoint in outpoints { inscriptions.extend( self .get_inscriptions_on_output_with_satpoints(*outpoint)? + .unwrap_or_default() .iter() .map(|(_satpoint, inscription_id)| *inscription_id), ); } - Ok(inscriptions) + Ok(Some(inscriptions)) } pub fn get_transaction(&self, txid: Txid) -> Result> { @@ -2258,29 +2268,31 @@ impl Index { outpoint_to_utxo_entry: &'a impl ReadableTable<&'static OutPointValue, &'static UtxoEntry>, sequence_number_to_inscription_entry: &'a impl ReadableTable, outpoint: OutPoint, - ) -> Result> { + ) -> Result>> { if !self.index_inscriptions { - return Ok(Vec::new()); + return Ok(None); } let Some(utxo_entry) = outpoint_to_utxo_entry.get(&outpoint.store())? else { - return Ok(Vec::new()); + return Ok(Some(Vec::new())); }; let mut inscriptions = utxo_entry.value().parse(self).parse_inscriptions(); inscriptions.sort_by_key(|(sequence_number, _)| *sequence_number); - inscriptions - .into_iter() - .map(|(sequence_number, offset)| { - let entry = sequence_number_to_inscription_entry - .get(sequence_number)? - .unwrap(); - let satpoint = SatPoint { outpoint, offset }; - Ok((satpoint, InscriptionEntry::load(entry.value()).id)) - }) - .collect::>() + let mut result = Vec::new(); + for (sequence_number, offset) in inscriptions.into_iter() { + let entry = sequence_number_to_inscription_entry + .get(sequence_number)? + .unwrap(); + + let satpoint = SatPoint { outpoint, offset }; + + result.push((satpoint, InscriptionEntry::load(entry.value()).id)) + } + + Ok(Some(result)) } pub fn get_address_info(&self, address: &Address) -> Result> { @@ -2300,35 +2312,37 @@ impl Index { pub(crate) fn get_aggregated_rune_balances_for_outputs( &self, outputs: &Vec, - ) -> Result)>> { + ) -> Result)>>> { let mut runes = BTreeMap::new(); for output in outputs { - if let Some(rune_balances) = self.get_rune_balances_for_output(*output)? { - for (spaced_rune, pile) in rune_balances { - runes - .entry(spaced_rune) - .and_modify(|(decimal, _symbol): &mut (Decimal, Option)| { - assert_eq!(decimal.scale, pile.divisibility); - decimal.value += pile.amount; - }) - .or_insert(( - Decimal { - value: pile.amount, - scale: pile.divisibility, - }, - pile.symbol, - )); - } + let Some(rune_balances) = self.get_rune_balances_for_output(*output)? else { + return Ok(None); + }; + + for (spaced_rune, pile) in rune_balances { + runes + .entry(spaced_rune) + .and_modify(|(decimal, _symbol): &mut (Decimal, Option)| { + assert_eq!(decimal.scale, pile.divisibility); + decimal.value += pile.amount; + }) + .or_insert(( + Decimal { + value: pile.amount, + scale: pile.divisibility, + }, + pile.symbol, + )); } } - Ok( + Ok(Some( runes .into_iter() .map(|(spaced_rune, (decimal, symbol))| (spaced_rune, decimal, symbol)) .collect(), - ) + )) } pub(crate) fn get_sat_balances_for_outputs(&self, outputs: &Vec) -> Result { @@ -4436,6 +4450,7 @@ mod tests { .index .get_inscriptions_on_output_with_satpoints(OutPoint { txid, vout: 0 }) .unwrap() + .unwrap_or_default() .iter() .map(|(_satpoint, inscription_id)| *inscription_id) .collect::>() @@ -4500,6 +4515,7 @@ mod tests { .index .get_inscriptions_on_output_with_satpoints(OutPoint { txid, vout: 0 }) .unwrap() + .unwrap_or_default() ) } } @@ -4549,6 +4565,7 @@ mod tests { vout: 0 }) .unwrap() + .unwrap_or_default() ) } } diff --git a/src/subcommand/server.rs b/src/subcommand/server.rs index 28c0aa38bd..cdbaf763b2 100644 --- a/src/subcommand/server.rs +++ b/src/subcommand/server.rs @@ -758,6 +758,7 @@ impl Server { OutputType::Cardinal => { index .get_inscriptions_on_output_with_satpoints(output)? + .unwrap_or_default() .is_empty() && index .get_rune_balances_for_output(output)? @@ -766,6 +767,7 @@ impl Server { } OutputType::Inscribed => !index .get_inscriptions_on_output_with_satpoints(output)? + .unwrap_or_default() .is_empty(), OutputType::Runic => !index .get_rune_balances_for_output(output)? diff --git a/src/templates/address.rs b/src/templates/address.rs index 6eb8ebe5e0..9b9214ea30 100644 --- a/src/templates/address.rs +++ b/src/templates/address.rs @@ -4,9 +4,9 @@ use super::*; pub(crate) struct AddressHtml { pub(crate) address: Address, pub(crate) outputs: Vec, - pub(crate) inscriptions: Vec, + pub(crate) inscriptions: Option>, pub(crate) sat_balance: u64, - pub(crate) runes_balances: Vec<(SpacedRune, Decimal, Option)>, + pub(crate) runes_balances: Option)>>, } impl PageContent for AddressHtml { @@ -26,9 +26,9 @@ mod tests { .require_network(Network::Bitcoin) .unwrap(), outputs: vec![outpoint(1), outpoint(2)], - inscriptions: vec![inscription_id(1)], + inscriptions: Some(vec![inscription_id(1)]), sat_balance: 99, - runes_balances: vec![ + runes_balances: Some(vec![ ( SpacedRune { rune: Rune::from_str("TEEEEEEEEESTRUNE").unwrap(), @@ -51,7 +51,7 @@ mod tests { }, Some('F'), ), - ], + ]), } } diff --git a/templates/address.html b/templates/address.html index 6b7146ae65..883da13ee8 100644 --- a/templates/address.html +++ b/templates/address.html @@ -2,21 +2,25 @@

Address {{ self.address }}

sat balance
{{ self.sat_balance }}
-%% if !self.inscriptions.is_empty() { +%% let inscriptions = self.inscriptions.clone().unwrap_or_default(); +%% if !inscriptions.is_empty() {
inscriptions
-%% for inscription in &self.inscriptions { +%% for inscription in &inscriptions { {{Iframe::thumbnail(*inscription)}} %% }
%% } +%% let runes_balances = self.runes_balances.clone().unwrap_or_default(); +%% if !runes_balances.is_empty() {
runes balances
-%% for (rune, decimal, symbol) in self.runes_balances.iter() { +%% for (rune, decimal, symbol) in runes_balances.iter() { %% if let Some(symbol) = symbol {
{{ rune }}: {{ decimal }}{{ symbol }}
%% } else {
{{ rune }}: {{ decimal }}ยค
%% } +%% } %% }
outputs
From 9482ec1e19d71ba806aa79fbb785204aff8ca81a Mon Sep 17 00:00:00 2001 From: raphjaph Date: Thu, 19 Dec 2024 20:05:22 -0500 Subject: [PATCH 06/18] Amend --- src/index.rs | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/index.rs b/src/index.rs index 1b59f97bf2..0b8ddfa2a5 100644 --- a/src/index.rs +++ b/src/index.rs @@ -2281,18 +2281,19 @@ impl Index { inscriptions.sort_by_key(|(sequence_number, _)| *sequence_number); - let mut result = Vec::new(); - for (sequence_number, offset) in inscriptions.into_iter() { - let entry = sequence_number_to_inscription_entry - .get(sequence_number)? - .unwrap(); - - let satpoint = SatPoint { outpoint, offset }; + inscriptions + .into_iter() + .map(|(sequence_number, offset)| { + let entry = sequence_number_to_inscription_entry + .get(sequence_number)? + .unwrap(); - result.push((satpoint, InscriptionEntry::load(entry.value()).id)) - } + let satpoint = SatPoint { outpoint, offset }; - Ok(Some(result)) + Ok((satpoint, InscriptionEntry::load(entry.value()).id)) + }) + .collect::>() + .map(Some) } pub fn get_address_info(&self, address: &Address) -> Result> { From 6ce7ba3cd066c2fcafe7e376be567c3251655609 Mon Sep 17 00:00:00 2001 From: raphjaph Date: Thu, 19 Dec 2024 20:08:57 -0500 Subject: [PATCH 07/18] Amend --- src/index.rs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/index.rs b/src/index.rs index 0b8ddfa2a5..467b82f7f3 100644 --- a/src/index.rs +++ b/src/index.rs @@ -1559,14 +1559,12 @@ impl Index { &self, outpoint: OutPoint, ) -> Result>> { - if !self.index_inscriptions { + let Some(inscriptions) = self.get_inscriptions_on_output_with_satpoints(outpoint)? else { return Ok(None); - } + }; Ok(Some( - self - .get_inscriptions_on_output_with_satpoints(outpoint)? - .unwrap_or_default() + inscriptions .iter() .map(|(_satpoint, inscription_id)| *inscription_id) .collect(), From 249d9089b4d9d13ca768b0f2e0196e0d18f47653 Mon Sep 17 00:00:00 2001 From: raphjaph Date: Thu, 19 Dec 2024 20:12:28 -0500 Subject: [PATCH 08/18] Amend --- src/index.rs | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/index.rs b/src/index.rs index 467b82f7f3..b5e035b668 100644 --- a/src/index.rs +++ b/src/index.rs @@ -1575,22 +1575,20 @@ impl Index { &self, outpoints: &Vec, ) -> Result>> { - if !self.index_inscriptions { - return Ok(None); - } - - let mut inscriptions = Vec::new(); + let mut result = Vec::new(); for outpoint in outpoints { - inscriptions.extend( - self - .get_inscriptions_on_output_with_satpoints(*outpoint)? - .unwrap_or_default() + let Some(inscriptions) = self.get_inscriptions_on_output_with_satpoints(*outpoint)? else { + return Ok(None); + }; + + result.extend( + inscriptions .iter() .map(|(_satpoint, inscription_id)| *inscription_id), ); } - Ok(Some(inscriptions)) + Ok(Some(result)) } pub fn get_transaction(&self, txid: Txid) -> Result> { From 7494843021b84f6f60b45d7d1145764ee545973b Mon Sep 17 00:00:00 2001 From: raphjaph Date: Fri, 20 Dec 2024 13:27:30 -0500 Subject: [PATCH 09/18] Amend --- src/subcommand/wallet/addresses.rs | 22 +++++++--------------- src/subcommand/wallet/outputs.rs | 22 +++++++--------------- src/wallet.rs | 10 ++-------- 3 files changed, 16 insertions(+), 38 deletions(-) diff --git a/src/subcommand/wallet/addresses.rs b/src/subcommand/wallet/addresses.rs index 36243f2de0..2119bf3133 100644 --- a/src/subcommand/wallet/addresses.rs +++ b/src/subcommand/wallet/addresses.rs @@ -16,17 +16,12 @@ pub(crate) fn run(wallet: Wallet) -> SubcommandResult { for (output, txout) in wallet.utxos() { let address = wallet.chain().address_from_script(&txout.script_pubkey)?; - let inscriptions = if wallet.has_inscription_index() { - Some(wallet.get_inscriptions_in_output(output)) - } else { - None - }; + let inscriptions = wallet.get_inscriptions_in_output(output); - let runes = if wallet.has_rune_index() { - Some( - wallet - .get_runes_balances_in_output(output)? - .unwrap_or_default() + let runes = wallet + .get_runes_balances_in_output(output)? + .map(|balances| { + balances .iter() .map(|(rune, pile)| { ( @@ -37,11 +32,8 @@ pub(crate) fn run(wallet: Wallet) -> SubcommandResult { }, ) }) - .collect(), - ) - } else { - None - }; + .collect() + }); let output = Output { output: *output, diff --git a/src/subcommand/wallet/outputs.rs b/src/subcommand/wallet/outputs.rs index 2cd6f062cf..1254fc2316 100644 --- a/src/subcommand/wallet/outputs.rs +++ b/src/subcommand/wallet/outputs.rs @@ -30,17 +30,12 @@ impl Outputs { .ok() .map(|address| address.as_unchecked().clone()); - let inscriptions = if wallet.has_inscription_index() { - Some(wallet.get_inscriptions_in_output(output)) - } else { - None - }; + let inscriptions = wallet.get_inscriptions_in_output(output); - let runes = if wallet.has_rune_index() { - Some( - wallet - .get_runes_balances_in_output(output)? - .unwrap_or_default() + let runes = wallet + .get_runes_balances_in_output(output)? + .map(|balances| { + balances .iter() .map(|(rune, pile)| { ( @@ -51,11 +46,8 @@ impl Outputs { }, ) }) - .collect(), - ) - } else { - None - }; + .collect() + }); let sat_ranges = if wallet.has_sat_index() && self.ranges { Some( diff --git a/src/wallet.rs b/src/wallet.rs index 5de258f498..ce2b4cc96b 100644 --- a/src/wallet.rs +++ b/src/wallet.rs @@ -217,14 +217,8 @@ impl Wallet { ) } - pub(crate) fn get_inscriptions_in_output(&self, output: &OutPoint) -> Vec { - self - .output_info - .get(output) - .unwrap() - .inscriptions - .clone() - .unwrap_or_default() + pub(crate) fn get_inscriptions_in_output(&self, output: &OutPoint) -> Option> { + self.output_info.get(output).unwrap().inscriptions.clone() } pub(crate) fn get_parent_info(&self, parents: &[InscriptionId]) -> Result> { From 0e6d04fe38144d2f9cfcd78a2fc2eb23ec768a13 Mon Sep 17 00:00:00 2001 From: raphjaph Date: Fri, 20 Dec 2024 13:28:29 -0500 Subject: [PATCH 10/18] Amend --- src/wallet.rs | 5 ----- src/wallet/wallet_constructor.rs | 1 - 2 files changed, 6 deletions(-) diff --git a/src/wallet.rs b/src/wallet.rs index ce2b4cc96b..931a22f045 100644 --- a/src/wallet.rs +++ b/src/wallet.rs @@ -75,7 +75,6 @@ pub(crate) enum Maturity { pub(crate) struct Wallet { bitcoin_client: Client, database: Database, - has_inscription_index: bool, has_rune_index: bool, has_sat_index: bool, rpc_url: Url, @@ -311,10 +310,6 @@ impl Wallet { ) } - pub(crate) fn has_inscription_index(&self) -> bool { - self.has_inscription_index - } - pub(crate) fn has_sat_index(&self) -> bool { self.has_sat_index } diff --git a/src/wallet/wallet_constructor.rs b/src/wallet/wallet_constructor.rs index fcc0ee70ca..7d6108c565 100644 --- a/src/wallet/wallet_constructor.rs +++ b/src/wallet/wallet_constructor.rs @@ -128,7 +128,6 @@ impl WalletConstructor { Ok(Wallet { bitcoin_client, database, - has_inscription_index: status.inscription_index, has_rune_index: status.rune_index, has_sat_index: status.sat_index, inscription_info, From d6dc51fc6118bbfd9e9e79cd7dfaefc813592559 Mon Sep 17 00:00:00 2001 From: raphjaph Date: Fri, 20 Dec 2024 13:52:32 -0500 Subject: [PATCH 11/18] Amend --- src/subcommand/wallet/batch_command.rs | 2 +- src/subcommand/wallet/burn.rs | 2 +- src/subcommand/wallet/cardinals.rs | 2 +- src/subcommand/wallet/inscribe.rs | 2 +- src/subcommand/wallet/runics.rs | 4 +++- src/subcommand/wallet/split.rs | 1 + src/wallet.rs | 15 ++++++++++----- 7 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/subcommand/wallet/batch_command.rs b/src/subcommand/wallet/batch_command.rs index 43e4c79133..5d6500cb22 100644 --- a/src/subcommand/wallet/batch_command.rs +++ b/src/subcommand/wallet/batch_command.rs @@ -64,7 +64,7 @@ impl Batch { } .inscribe( &locked_utxos.into_keys().collect(), - wallet.get_runic_outputs()?, + wallet.get_runic_outputs()?.unwrap_or_default(), utxos, &wallet, ) diff --git a/src/subcommand/wallet/burn.rs b/src/subcommand/wallet/burn.rs index bdf4e70bc2..93eb804645 100644 --- a/src/subcommand/wallet/burn.rs +++ b/src/subcommand/wallet/burn.rs @@ -144,7 +144,7 @@ impl Burn { script_pubkey: ScriptBuf, burn_amount: Amount, ) -> Result { - let runic_outputs = wallet.get_runic_outputs()?; + let runic_outputs = wallet.get_runic_outputs()?.unwrap_or_default(); ensure!( !runic_outputs.contains(&satpoint.outpoint), diff --git a/src/subcommand/wallet/cardinals.rs b/src/subcommand/wallet/cardinals.rs index bceeba421c..5f061dc607 100644 --- a/src/subcommand/wallet/cardinals.rs +++ b/src/subcommand/wallet/cardinals.rs @@ -15,7 +15,7 @@ pub(crate) fn run(wallet: Wallet) -> SubcommandResult { .map(|satpoint| satpoint.outpoint) .collect::>(); - let runic_utxos = wallet.get_runic_outputs()?; + let runic_utxos = wallet.get_runic_outputs()?.unwrap_or_default(); let cardinal_utxos = unspent_outputs .iter() diff --git a/src/subcommand/wallet/inscribe.rs b/src/subcommand/wallet/inscribe.rs index c71c652318..13a2c332dd 100644 --- a/src/subcommand/wallet/inscribe.rs +++ b/src/subcommand/wallet/inscribe.rs @@ -95,7 +95,7 @@ impl Inscribe { } .inscribe( &wallet.locked_utxos().clone().into_keys().collect(), - wallet.get_runic_outputs()?, + wallet.get_runic_outputs()?.unwrap_or_default(), wallet.utxos(), &wallet, ) diff --git a/src/subcommand/wallet/runics.rs b/src/subcommand/wallet/runics.rs index 651e4ed5f6..689fbb547d 100644 --- a/src/subcommand/wallet/runics.rs +++ b/src/subcommand/wallet/runics.rs @@ -8,7 +8,9 @@ pub struct RunicUtxo { pub(crate) fn run(wallet: Wallet) -> SubcommandResult { let unspent_outputs = wallet.utxos(); - let runic_utxos = wallet.get_runic_outputs()?; + let Some(runic_utxos) = wallet.get_runic_outputs()? else { + bail!("`ord wallet runics` requires index created with `--index-runes`") + }; let runic_utxos = unspent_outputs .iter() diff --git a/src/subcommand/wallet/split.rs b/src/subcommand/wallet/split.rs index dd35f348c1..3e498b3f80 100644 --- a/src/subcommand/wallet/split.rs +++ b/src/subcommand/wallet/split.rs @@ -113,6 +113,7 @@ impl Split { let balances = wallet .get_runic_outputs()? + .unwrap_or_default() .into_iter() .filter(|output| !inscribed_outputs.contains(output)) .map(|output| { diff --git a/src/wallet.rs b/src/wallet.rs index 931a22f045..6dae9a4228 100644 --- a/src/wallet.rs +++ b/src/wallet.rs @@ -180,7 +180,7 @@ impl Wallet { .utxos() .keys() .filter(|utxo| inscriptions.contains(utxo)) - .chain(self.get_runic_outputs()?.iter()) + .chain(self.get_runic_outputs()?.unwrap_or_default().iter()) .cloned() .filter(|utxo| !locked.contains(utxo)) .collect::>(); @@ -250,15 +250,19 @@ impl Wallet { Ok(parent_info) } - pub(crate) fn get_runic_outputs(&self) -> Result> { + pub(crate) fn get_runic_outputs(&self) -> Result>> { let mut runic_outputs = BTreeSet::new(); for (output, info) in &self.output_info { - if !info.runes.clone().unwrap_or_default().is_empty() { + let Some(runes) = &info.runes else { + return Ok(None); + }; + + if !runes.is_empty() { runic_outputs.insert(*output); } } - Ok(runic_outputs) + Ok(Some(runic_outputs)) } pub(crate) fn get_runes_balances_in_output( @@ -874,7 +878,7 @@ impl Wallet { } } - let runic_outputs = self.get_runic_outputs()?; + let runic_outputs = self.get_runic_outputs()?.unwrap_or_default(); ensure!( !runic_outputs.contains(&satpoint.outpoint), @@ -935,6 +939,7 @@ impl Wallet { let balances = self .get_runic_outputs()? + .unwrap_or_default() .into_iter() .filter(|output| !inscribed_outputs.contains(output)) .map(|output| { From 7df50a02e1afacfb353a12354f53744031267876 Mon Sep 17 00:00:00 2001 From: raphjaph Date: Fri, 20 Dec 2024 14:38:56 -0500 Subject: [PATCH 12/18] Amend --- src/subcommand/wallet/runics.rs | 62 +++++++++++++++------------------ 1 file changed, 29 insertions(+), 33 deletions(-) diff --git a/src/subcommand/wallet/runics.rs b/src/subcommand/wallet/runics.rs index 689fbb547d..f1a8480bb9 100644 --- a/src/subcommand/wallet/runics.rs +++ b/src/subcommand/wallet/runics.rs @@ -12,39 +12,35 @@ pub(crate) fn run(wallet: Wallet) -> SubcommandResult { bail!("`ord wallet runics` requires index created with `--index-runes`") }; - let runic_utxos = unspent_outputs - .iter() - .filter_map(|(output, _)| { - if runic_utxos.contains(output) { - let rune_balances = wallet - .get_runes_balances_in_output(output) - .ok()? - .unwrap_or_default(); - - let mut runes = BTreeMap::new(); - - for (spaced_rune, pile) in rune_balances { - runes - .entry(spaced_rune) - .and_modify(|decimal: &mut Decimal| { - assert_eq!(decimal.scale, pile.divisibility); - decimal.value += pile.amount; - }) - .or_insert(Decimal { - value: pile.amount, - scale: pile.divisibility, - }); - } - - Some(RunicUtxo { - output: *output, - runes, - }) - } else { - None + let mut result = Vec::new(); + + for (output, _) in unspent_outputs.iter() { + if runic_utxos.contains(output) { + let rune_balances = wallet + .get_runes_balances_in_output(output)? + .unwrap_or_default(); + + let mut runes = BTreeMap::new(); + + for (spaced_rune, pile) in rune_balances { + runes + .entry(spaced_rune) + .and_modify(|decimal: &mut Decimal| { + assert_eq!(decimal.scale, pile.divisibility); + decimal.value += pile.amount; + }) + .or_insert(Decimal { + value: pile.amount, + scale: pile.divisibility, + }); } - }) - .collect::>(); - Ok(Some(Box::new(runic_utxos))) + result.push(RunicUtxo { + output: *output, + runes, + }); + } + } + + Ok(Some(Box::new(result))) } From be3a880fa5221f9c4179b774d738a6d9636be9db Mon Sep 17 00:00:00 2001 From: raphjaph Date: Fri, 20 Dec 2024 14:39:44 -0500 Subject: [PATCH 13/18] Amend --- src/subcommand/wallet/runics.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/subcommand/wallet/runics.rs b/src/subcommand/wallet/runics.rs index f1a8480bb9..ec5d29b4e8 100644 --- a/src/subcommand/wallet/runics.rs +++ b/src/subcommand/wallet/runics.rs @@ -14,7 +14,7 @@ pub(crate) fn run(wallet: Wallet) -> SubcommandResult { let mut result = Vec::new(); - for (output, _) in unspent_outputs.iter() { + for (output, _) in &unspent_outputs { if runic_utxos.contains(output) { let rune_balances = wallet .get_runes_balances_in_output(output)? From 4cb8ad7c80d2fb7e1feebc07a9c052ef351c3fe1 Mon Sep 17 00:00:00 2001 From: raphjaph Date: Fri, 20 Dec 2024 14:40:10 -0500 Subject: [PATCH 14/18] Amend --- src/subcommand/wallet/runics.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/subcommand/wallet/runics.rs b/src/subcommand/wallet/runics.rs index ec5d29b4e8..5e173bd0d8 100644 --- a/src/subcommand/wallet/runics.rs +++ b/src/subcommand/wallet/runics.rs @@ -14,7 +14,7 @@ pub(crate) fn run(wallet: Wallet) -> SubcommandResult { let mut result = Vec::new(); - for (output, _) in &unspent_outputs { + for (output, _) in unspent_outputs { if runic_utxos.contains(output) { let rune_balances = wallet .get_runes_balances_in_output(output)? From cde9b1532136b3f549e24f30daa707658e6cd21a Mon Sep 17 00:00:00 2001 From: raphjaph Date: Fri, 20 Dec 2024 14:40:58 -0500 Subject: [PATCH 15/18] Amend --- src/subcommand/wallet/runics.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/subcommand/wallet/runics.rs b/src/subcommand/wallet/runics.rs index 5e173bd0d8..2b1702869b 100644 --- a/src/subcommand/wallet/runics.rs +++ b/src/subcommand/wallet/runics.rs @@ -14,7 +14,7 @@ pub(crate) fn run(wallet: Wallet) -> SubcommandResult { let mut result = Vec::new(); - for (output, _) in unspent_outputs { + for output in unspent_outputs.keys() { if runic_utxos.contains(output) { let rune_balances = wallet .get_runes_balances_in_output(output)? From fcb5fc959941bd1decf670703364f759ae877791 Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Fri, 20 Dec 2024 11:46:08 -0800 Subject: [PATCH 16/18] Use if let in address.html --- templates/address.html | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/templates/address.html b/templates/address.html index 883da13ee8..b45df528f5 100644 --- a/templates/address.html +++ b/templates/address.html @@ -2,18 +2,16 @@

Address {{ self.address }}

sat balance
{{ self.sat_balance }}
-%% let inscriptions = self.inscriptions.clone().unwrap_or_default(); -%% if !inscriptions.is_empty() { +%% if let Some(inscriptions) = self.inscriptions.as_ref().filter(|inscriptions| !inscriptions.is_empty()) {
inscriptions
-%% for inscription in &inscriptions { +%% for inscription in inscriptions { {{Iframe::thumbnail(*inscription)}} %% }
%% } -%% let runes_balances = self.runes_balances.clone().unwrap_or_default(); -%% if !runes_balances.is_empty() { -
runes balances
+%% if let Some(runes_balances) = self.runes_balances.as_ref().filter(|runes_balances| !runes_balances.is_empty()) { +
rune balances
%% for (rune, decimal, symbol) in runes_balances.iter() { %% if let Some(symbol) = symbol {
{{ rune }}: {{ decimal }}{{ symbol }}
From 83aab1476bcc0c6d967ad9dff47817eef99ae273 Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Fri, 20 Dec 2024 11:49:18 -0800 Subject: [PATCH 17/18] Tweak --- src/templates/address.rs | 2 +- templates/address.html | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/templates/address.rs b/src/templates/address.rs index 9b9214ea30..685835bb7a 100644 --- a/src/templates/address.rs +++ b/src/templates/address.rs @@ -80,7 +80,7 @@ mod tests { #[test] fn test_runes_balances_rendering() { let address_html = setup(); - let expected_pattern = r#".*
runes balances
\n\s*
TEEEEEEEEESTRUNE: 20000R
\n\s*
ANOTHERTEESTRUNE: 10000F
.*"#; + let expected_pattern = r#".*
rune balances
\n\s*
TEEEEEEEEESTRUNE: 20000R
\n\s*
ANOTHERTEESTRUNE: 10000F
.*"#; assert_regex_match!(address_html, expected_pattern); } diff --git a/templates/address.html b/templates/address.html index b45df528f5..677290a0c2 100644 --- a/templates/address.html +++ b/templates/address.html @@ -12,7 +12,7 @@

Address {{ self.address }}

%% } %% if let Some(runes_balances) = self.runes_balances.as_ref().filter(|runes_balances| !runes_balances.is_empty()) {
rune balances
-%% for (rune, decimal, symbol) in runes_balances.iter() { +%% for (rune, decimal, symbol) in runes_balances { %% if let Some(symbol) = symbol {
{{ rune }}: {{ decimal }}{{ symbol }}
%% } else { From c7cf166d2a01b2f38e2b5f9ab5a5142865e3da22 Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Fri, 20 Dec 2024 11:51:02 -0800 Subject: [PATCH 18/18] Revise --- templates/output.html | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/templates/output.html b/templates/output.html index 7c97557d87..56a640b312 100644 --- a/templates/output.html +++ b/templates/output.html @@ -1,16 +1,14 @@

Output {{self.outpoint}}

-%% let inscriptions = self.inscriptions.clone().unwrap_or_default(); -%% if !inscriptions.is_empty() { +%% if let Some(inscriptions) = self.inscriptions.as_ref().filter(|inscriptions| !inscriptions.is_empty()) {
inscriptions
-%% for inscription in &inscriptions { +%% for inscription in inscriptions { {{Iframe::thumbnail(*inscription)}} %% }
%% } -%% let runes = self.runes.clone().unwrap_or_default(); -%% if !runes.is_empty() { +%% if let Some(runes) = self.runes.as_ref().filter(|runes| !runes.is_empty()) {
runes
rune balance
{{ rune }} {{ balance }}
@@ -18,7 +16,7 @@

Output {{self.outpoint}}

-%% for (rune, balance) in &runes { +%% for (rune, balance) in runes {
rune balance
{{ rune }} {{ balance }}