@@ -6,8 +6,8 @@ use alloc::vec::Vec;
66use bitcoin:: { OutPoint , Transaction , TxOut } ;
77
88use crate :: {
9- keychain:: DerivationAdditions ,
10- tx_graph:: { Additions , TxGraph } ,
9+ keychain,
10+ tx_graph:: { self , TxGraph } ,
1111 Anchor , Append ,
1212} ;
1313
@@ -46,47 +46,47 @@ impl<A, I> IndexedTxGraph<A, I> {
4646}
4747
4848impl < A : Anchor , I : Indexer > IndexedTxGraph < A , I > {
49- /// Applies the [`IndexedAdditions `] to the [`IndexedTxGraph`].
50- pub fn apply_additions ( & mut self , additions : IndexedAdditions < A , I :: Additions > ) {
51- let IndexedAdditions {
52- graph_additions ,
53- index_additions ,
54- } = additions ;
49+ /// Applies the [`ChangeSet `] to the [`IndexedTxGraph`].
50+ pub fn apply_changeset ( & mut self , changeset : ChangeSet < A , I :: ChangeSet > ) {
51+ let ChangeSet {
52+ graph_changeset ,
53+ index_changeset ,
54+ } = changeset ;
5555
56- self . index . apply_additions ( index_additions ) ;
56+ self . index . apply_changeset ( index_changeset ) ;
5757
58- for tx in & graph_additions . txs {
58+ for tx in & graph_changeset . txs {
5959 self . index . index_tx ( tx) ;
6060 }
61- for ( & outpoint, txout) in & graph_additions . txouts {
61+ for ( & outpoint, txout) in & graph_changeset . txouts {
6262 self . index . index_txout ( outpoint, txout) ;
6363 }
6464
65- self . graph . apply_additions ( graph_additions ) ;
65+ self . graph . apply_changeset ( graph_changeset ) ;
6666 }
6767}
6868
6969impl < A : Anchor , I : Indexer > IndexedTxGraph < A , I >
7070where
71- I :: Additions : Default + Append ,
71+ I :: ChangeSet : Default + Append ,
7272{
7373 /// Apply an `update` directly.
7474 ///
75- /// `update` is a [`TxGraph<A>`] and the resultant changes is returned as [`IndexedAdditions `].
76- pub fn apply_update ( & mut self , update : TxGraph < A > ) -> IndexedAdditions < A , I :: Additions > {
77- let graph_additions = self . graph . apply_update ( update) ;
75+ /// `update` is a [`TxGraph<A>`] and the resultant changes is returned as [`ChangeSet `].
76+ pub fn apply_update ( & mut self , update : TxGraph < A > ) -> ChangeSet < A , I :: ChangeSet > {
77+ let graph_changeset = self . graph . apply_update ( update) ;
7878
79- let mut index_additions = I :: Additions :: default ( ) ;
80- for added_tx in & graph_additions . txs {
81- index_additions . append ( self . index . index_tx ( added_tx) ) ;
79+ let mut index_changeset = I :: ChangeSet :: default ( ) ;
80+ for added_tx in & graph_changeset . txs {
81+ index_changeset . append ( self . index . index_tx ( added_tx) ) ;
8282 }
83- for ( & added_outpoint, added_txout) in & graph_additions . txouts {
84- index_additions . append ( self . index . index_txout ( added_outpoint, added_txout) ) ;
83+ for ( & added_outpoint, added_txout) in & graph_changeset . txouts {
84+ index_changeset . append ( self . index . index_txout ( added_outpoint, added_txout) ) ;
8585 }
8686
87- IndexedAdditions {
88- graph_additions ,
89- index_additions ,
87+ ChangeSet {
88+ graph_changeset ,
89+ index_changeset ,
9090 }
9191 }
9292
9595 & mut self ,
9696 outpoint : OutPoint ,
9797 txout : & TxOut ,
98- ) -> IndexedAdditions < A , I :: Additions > {
98+ ) -> ChangeSet < A , I :: ChangeSet > {
9999 let mut update = TxGraph :: < A > :: default ( ) ;
100100 let _ = update. insert_txout ( outpoint, txout. clone ( ) ) ;
101101 self . apply_update ( update)
@@ -110,7 +110,7 @@ where
110110 tx : & Transaction ,
111111 anchors : impl IntoIterator < Item = A > ,
112112 seen_at : Option < u64 > ,
113- ) -> IndexedAdditions < A , I :: Additions > {
113+ ) -> ChangeSet < A , I :: ChangeSet > {
114114 let txid = tx. txid ( ) ;
115115
116116 let mut update = TxGraph :: < A > :: default ( ) ;
@@ -138,20 +138,20 @@ where
138138 & mut self ,
139139 txs : impl IntoIterator < Item = ( & ' t Transaction , impl IntoIterator < Item = A > ) > ,
140140 seen_at : Option < u64 > ,
141- ) -> IndexedAdditions < A , I :: Additions > {
141+ ) -> ChangeSet < A , I :: ChangeSet > {
142142 // The algorithm below allows for non-topologically ordered transactions by using two loops.
143143 // This is achieved by:
144144 // 1. insert all txs into the index. If they are irrelevant then that's fine it will just
145145 // not store anything about them.
146146 // 2. decide whether to insert them into the graph depending on whether `is_tx_relevant`
147147 // returns true or not. (in a second loop).
148- let mut additions = IndexedAdditions :: < A , I :: Additions > :: default ( ) ;
148+ let mut changeset = ChangeSet :: < A , I :: ChangeSet > :: default ( ) ;
149149 let mut transactions = Vec :: new ( ) ;
150150 for ( tx, anchors) in txs. into_iter ( ) {
151- additions . index_additions . append ( self . index . index_tx ( tx) ) ;
151+ changeset . index_changeset . append ( self . index . index_tx ( tx) ) ;
152152 transactions. push ( ( tx, anchors) ) ;
153153 }
154- additions . append (
154+ changeset . append (
155155 transactions
156156 . into_iter ( )
157157 . filter_map ( |( tx, anchors) | match self . index . is_tx_relevant ( tx) {
@@ -163,7 +163,7 @@ where
163163 acc
164164 } ) ,
165165 ) ;
166- additions
166+ changeset
167167 }
168168}
169169
@@ -181,64 +181,64 @@ where
181181 )
182182) ]
183183#[ must_use]
184- pub struct IndexedAdditions < A , IA > {
185- /// [`TxGraph`] additions .
186- pub graph_additions : Additions < A > ,
187- /// [`Indexer`] additions .
188- pub index_additions : IA ,
184+ pub struct ChangeSet < A , IA > {
185+ /// [`TxGraph`] changeset .
186+ pub graph_changeset : tx_graph :: ChangeSet < A > ,
187+ /// [`Indexer`] changeset .
188+ pub index_changeset : IA ,
189189}
190190
191- impl < A , IA : Default > Default for IndexedAdditions < A , IA > {
191+ impl < A , IA : Default > Default for ChangeSet < A , IA > {
192192 fn default ( ) -> Self {
193193 Self {
194- graph_additions : Default :: default ( ) ,
195- index_additions : Default :: default ( ) ,
194+ graph_changeset : Default :: default ( ) ,
195+ index_changeset : Default :: default ( ) ,
196196 }
197197 }
198198}
199199
200- impl < A : Anchor , IA : Append > Append for IndexedAdditions < A , IA > {
200+ impl < A : Anchor , IA : Append > Append for ChangeSet < A , IA > {
201201 fn append ( & mut self , other : Self ) {
202- self . graph_additions . append ( other. graph_additions ) ;
203- self . index_additions . append ( other. index_additions ) ;
202+ self . graph_changeset . append ( other. graph_changeset ) ;
203+ self . index_changeset . append ( other. index_changeset ) ;
204204 }
205205
206206 fn is_empty ( & self ) -> bool {
207- self . graph_additions . is_empty ( ) && self . index_additions . is_empty ( )
207+ self . graph_changeset . is_empty ( ) && self . index_changeset . is_empty ( )
208208 }
209209}
210210
211- impl < A , IA : Default > From < Additions < A > > for IndexedAdditions < A , IA > {
212- fn from ( graph_additions : Additions < A > ) -> Self {
211+ impl < A , IA : Default > From < tx_graph :: ChangeSet < A > > for ChangeSet < A , IA > {
212+ fn from ( graph_changeset : tx_graph :: ChangeSet < A > ) -> Self {
213213 Self {
214- graph_additions ,
214+ graph_changeset ,
215215 ..Default :: default ( )
216216 }
217217 }
218218}
219219
220- impl < A , K > From < DerivationAdditions < K > > for IndexedAdditions < A , DerivationAdditions < K > > {
221- fn from ( index_additions : DerivationAdditions < K > ) -> Self {
220+ impl < A , K > From < keychain :: ChangeSet < K > > for ChangeSet < A , keychain :: ChangeSet < K > > {
221+ fn from ( index_changeset : keychain :: ChangeSet < K > ) -> Self {
222222 Self {
223- graph_additions : Default :: default ( ) ,
224- index_additions ,
223+ graph_changeset : Default :: default ( ) ,
224+ index_changeset ,
225225 }
226226 }
227227}
228228
229229/// Represents a structure that can index transaction data.
230230pub trait Indexer {
231- /// The resultant "additions " when new transaction data is indexed.
232- type Additions ;
231+ /// The resultant "changeset " when new transaction data is indexed.
232+ type ChangeSet ;
233233
234234 /// Scan and index the given `outpoint` and `txout`.
235- fn index_txout ( & mut self , outpoint : OutPoint , txout : & TxOut ) -> Self :: Additions ;
235+ fn index_txout ( & mut self , outpoint : OutPoint , txout : & TxOut ) -> Self :: ChangeSet ;
236236
237237 /// Scan and index the given transaction.
238- fn index_tx ( & mut self , tx : & Transaction ) -> Self :: Additions ;
238+ fn index_tx ( & mut self , tx : & Transaction ) -> Self :: ChangeSet ;
239239
240- /// Apply additions to itself.
241- fn apply_additions ( & mut self , additions : Self :: Additions ) ;
240+ /// Apply changeset to itself.
241+ fn apply_changeset ( & mut self , changeset : Self :: ChangeSet ) ;
242242
243243 /// Determines whether the transaction should be included in the index.
244244 fn is_tx_relevant ( & self , tx : & Transaction ) -> bool ;
0 commit comments