@@ -171,6 +171,15 @@ impl Append for ChangeSet {
171
171
}
172
172
}
173
173
174
+ impl From < keychain:: ChangeSet < KeychainKind > > for ChangeSet {
175
+ fn from ( keychain_changeset : keychain:: ChangeSet < KeychainKind > ) -> Self {
176
+ Self {
177
+ indexed_tx_graph : keychain_changeset. into ( ) ,
178
+ ..Default :: default ( )
179
+ }
180
+ }
181
+ }
182
+
174
183
impl From < local_chain:: ChangeSet > for ChangeSet {
175
184
fn from ( chain : local_chain:: ChangeSet ) -> Self {
176
185
Self {
@@ -813,18 +822,14 @@ impl Wallet {
813
822
/// If writing to persistent storage fails.
814
823
pub fn reveal_next_address ( & mut self , keychain : KeychainKind ) -> anyhow:: Result < AddressInfo > {
815
824
let keychain = self . map_keychain ( keychain) ;
816
- let ( ( index, spk) , index_changeset) = self
817
- . indexed_graph
818
- . index
819
- . reveal_next_spk ( & keychain)
820
- . expect ( "Must exist (we called map_keychain)" ) ;
821
-
825
+ let ( next_spk, index_changeset) = self . indexed_graph . index . reveal_next_spk ( & keychain) ;
826
+ let ( index, spk) = next_spk. expect ( "Must exist (we called map_keychain)" ) ;
822
827
self . persist
823
828
. stage_and_commit ( indexed_tx_graph:: ChangeSet :: from ( index_changeset) . into ( ) ) ?;
824
829
825
830
Ok ( AddressInfo {
826
831
index,
827
- address : Address :: from_script ( spk, self . network ) . expect ( "must have address form" ) ,
832
+ address : Address :: from_script ( & spk, self . network ) . expect ( "must have address form" ) ,
828
833
keychain,
829
834
} )
830
835
}
@@ -845,11 +850,9 @@ impl Wallet {
845
850
index : u32 ,
846
851
) -> anyhow:: Result < impl Iterator < Item = AddressInfo > + ' _ > {
847
852
let keychain = self . map_keychain ( keychain) ;
848
- let ( spk_iter, index_changeset) = self
849
- . indexed_graph
850
- . index
851
- . reveal_to_target ( & keychain, index)
852
- . expect ( "must exist (we called map_keychain)" ) ;
853
+ let ( spk_iter, index_changeset) =
854
+ self . indexed_graph . index . reveal_to_target ( & keychain, index) ;
855
+ let spk_iter = spk_iter. expect ( "Must exist (we called map_keychain)" ) ;
853
856
854
857
self . persist
855
858
. stage_and_commit ( indexed_tx_graph:: ChangeSet :: from ( index_changeset) . into ( ) ) ?;
@@ -872,18 +875,15 @@ impl Wallet {
872
875
/// If writing to persistent storage fails.
873
876
pub fn next_unused_address ( & mut self , keychain : KeychainKind ) -> anyhow:: Result < AddressInfo > {
874
877
let keychain = self . map_keychain ( keychain) ;
875
- let ( ( index, spk) , index_changeset) = self
876
- . indexed_graph
877
- . index
878
- . next_unused_spk ( & keychain)
879
- . expect ( "must exist (we called map_keychain)" ) ;
878
+ let ( next_spk, index_changeset) = self . indexed_graph . index . next_unused_spk ( & keychain) ;
879
+ let ( index, spk) = next_spk. expect ( "Must exist (we called map_keychain)" ) ;
880
880
881
881
self . persist
882
882
. stage_and_commit ( indexed_tx_graph:: ChangeSet :: from ( index_changeset) . into ( ) ) ?;
883
883
884
884
Ok ( AddressInfo {
885
885
index,
886
- address : Address :: from_script ( spk, self . network ) . expect ( "must have address form" ) ,
886
+ address : Address :: from_script ( & spk, self . network ) . expect ( "must have address form" ) ,
887
887
keychain,
888
888
} )
889
889
}
@@ -1038,7 +1038,7 @@ impl Wallet {
1038
1038
/// [`commit`]: Self::commit
1039
1039
pub fn insert_txout ( & mut self , outpoint : OutPoint , txout : TxOut ) {
1040
1040
let additions = self . indexed_graph . insert_txout ( outpoint, txout) ;
1041
- self . persist . stage ( ChangeSet :: from ( additions) ) ;
1041
+ self . persist . stage ( additions. into ( ) ) ;
1042
1042
}
1043
1043
1044
1044
/// Calculates the fee of a given transaction. Returns 0 if `tx` is a coinbase transaction.
@@ -1607,17 +1607,11 @@ impl Wallet {
1607
1607
Some ( ref drain_recipient) => drain_recipient. clone ( ) ,
1608
1608
None => {
1609
1609
let change_keychain = self . map_keychain ( KeychainKind :: Internal ) ;
1610
- let ( ( index, spk) , index_changeset) = self
1611
- . indexed_graph
1612
- . index
1613
- . next_unused_spk ( & change_keychain)
1614
- . expect ( "Keychain exists (we called map_keychain)" ) ;
1615
- let spk = spk. into ( ) ;
1610
+ let ( next_spk, index_changeset) =
1611
+ self . indexed_graph . index . next_unused_spk ( & change_keychain) ;
1612
+ let ( index, spk) = next_spk. expect ( "Keychain exists (we called map_keychain)" ) ;
1616
1613
self . indexed_graph . index . mark_used ( change_keychain, index) ;
1617
- self . persist
1618
- . stage ( ChangeSet :: from ( indexed_tx_graph:: ChangeSet :: from (
1619
- index_changeset,
1620
- ) ) ) ;
1614
+ self . persist . stage ( index_changeset. into ( ) ) ;
1621
1615
self . persist . commit ( ) . map_err ( CreateTxError :: Persist ) ?;
1622
1616
spk
1623
1617
}
@@ -2432,21 +2426,19 @@ impl Wallet {
2432
2426
/// [`commit`]: Self::commit
2433
2427
pub fn apply_update ( & mut self , update : impl Into < Update > ) -> Result < ( ) , CannotConnectError > {
2434
2428
let update = update. into ( ) ;
2435
- let mut changeset = match update. chain {
2436
- Some ( chain_update) => ChangeSet :: from ( self . chain . apply_update ( chain_update) ?) ,
2437
- None => ChangeSet :: default ( ) ,
2438
- } ;
2429
+ let mut changeset = ChangeSet :: default ( ) ;
2439
2430
2440
- let ( _, index_changeset) = self
2441
- . indexed_graph
2442
- . index
2443
- . reveal_to_target_multi ( & update. last_active_indices ) ;
2444
- changeset. append ( ChangeSet :: from ( indexed_tx_graph:: ChangeSet :: from (
2445
- index_changeset,
2446
- ) ) ) ;
2447
- changeset. append ( ChangeSet :: from (
2448
- self . indexed_graph . apply_update ( update. graph ) ,
2449
- ) ) ;
2431
+ if let Some ( chain_update) = update. chain {
2432
+ changeset. append ( self . chain . apply_update ( chain_update) ?. into ( ) ) ;
2433
+ }
2434
+ changeset. append ( {
2435
+ let ( _, index_changeset) = self
2436
+ . indexed_graph
2437
+ . index
2438
+ . reveal_to_target_multi ( & update. last_active_indices ) ;
2439
+ index_changeset. into ( )
2440
+ } ) ;
2441
+ changeset. append ( self . indexed_graph . apply_update ( update. graph ) . into ( ) ) ;
2450
2442
self . persist . stage ( changeset) ;
2451
2443
Ok ( ( ) )
2452
2444
}
@@ -2552,7 +2544,7 @@ impl Wallet {
2552
2544
let indexed_graph_changeset = self
2553
2545
. indexed_graph
2554
2546
. batch_insert_relevant_unconfirmed ( unconfirmed_txs) ;
2555
- self . persist . stage ( ChangeSet :: from ( indexed_graph_changeset) ) ;
2547
+ self . persist . stage ( indexed_graph_changeset. into ( ) ) ;
2556
2548
}
2557
2549
}
2558
2550
0 commit comments