From 7d92337b932fdcfec7008da8ed81f2b4b6e7a069 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BF=97=E5=AE=87?= Date: Mon, 10 Apr 2023 16:51:16 +0800 Subject: [PATCH] [bdk_chain_redesign] Remove `IndexedTxGraph::last_height` It is better to have this external to this structure. --- crates/chain/src/indexed_tx_graph.rs | 58 ---------------------------- 1 file changed, 58 deletions(-) diff --git a/crates/chain/src/indexed_tx_graph.rs b/crates/chain/src/indexed_tx_graph.rs index 2de8114a..574afc1b 100644 --- a/crates/chain/src/indexed_tx_graph.rs +++ b/crates/chain/src/indexed_tx_graph.rs @@ -36,8 +36,6 @@ pub struct IndexedAdditions { pub graph_additions: Additions, /// [`TxIndex`] additions. pub index_additions: IA, - /// Last block height witnessed (if any). - pub last_height: Option, } impl Default for IndexedAdditions { @@ -45,7 +43,6 @@ impl Default for IndexedAdditions { Self { graph_additions: Default::default(), index_additions: Default::default(), - last_height: None, } } } @@ -54,13 +51,6 @@ impl Append for IndexedAdditions { fn append(&mut self, other: Self) { self.graph_additions.append(other.graph_additions); self.index_additions.append(other.index_additions); - if self.last_height < other.last_height { - self.last_height = Some( - other - .last_height - .expect("must exist as it is larger than self.last_height"), - ); - } } } @@ -68,7 +58,6 @@ pub struct IndexedTxGraph { /// Transaction index. pub index: I, graph: TxGraph, - last_height: u32, } impl Default for IndexedTxGraph { @@ -76,7 +65,6 @@ impl Default for IndexedTxGraph { Self { graph: Default::default(), index: Default::default(), - last_height: u32::MIN, } } } @@ -92,7 +80,6 @@ impl IndexedTxGraph { let IndexedAdditions { graph_additions, index_additions, - last_height, } = additions; self.index.apply_additions(index_additions); @@ -105,30 +92,6 @@ impl IndexedTxGraph { } self.graph.apply_additions(graph_additions); - - if let Some(height) = last_height { - self.last_height = height; - } - } - - fn insert_height_internal(&mut self, tip: u32) -> Option { - if self.last_height < tip { - self.last_height = tip; - Some(tip) - } else { - None - } - } - - /// Insert a block height that the chain source has scanned up to. - pub fn insert_height(&mut self, tip: u32) -> IndexedAdditions - where - I::Additions: Default, - { - IndexedAdditions { - last_height: self.insert_height_internal(tip), - ..Default::default() - } } /// Insert a `txout` that exists in `outpoint` with the given `observation`. @@ -138,13 +101,6 @@ impl IndexedTxGraph { txout: &TxOut, observation: ObservedAs, ) -> IndexedAdditions { - let last_height = match &observation { - ObservedAs::Confirmed(anchor) => { - self.insert_height_internal(anchor.anchor_block().height) - } - ObservedAs::Unconfirmed(_) => None, - }; - IndexedAdditions { graph_additions: { let mut graph_additions = self.graph.insert_txout(outpoint, txout.clone()); @@ -159,7 +115,6 @@ impl IndexedTxGraph { graph_additions }, index_additions: ::index_txout(&mut self.index, outpoint, txout), - last_height, } } @@ -170,13 +125,6 @@ impl IndexedTxGraph { ) -> IndexedAdditions { let txid = tx.txid(); - let last_height = match &observation { - ObservedAs::Confirmed(anchor) => { - self.insert_height_internal(anchor.anchor_block().height) - } - ObservedAs::Unconfirmed(_) => None, - }; - IndexedAdditions { graph_additions: { let mut graph_additions = self.graph.insert_tx(tx.clone()); @@ -187,7 +135,6 @@ impl IndexedTxGraph { graph_additions }, index_additions: ::index_tx(&mut self.index, tx), - last_height, } } @@ -213,11 +160,6 @@ impl IndexedTxGraph { }) } - /// Get the last block height that we are synced up to. - pub fn last_height(&self) -> u32 { - self.last_height - } - // [TODO] Have to methods, one for relevant-only, and one for any. Have one in `TxGraph`. pub fn try_list_chain_txs<'a, C>( &'a self,