@@ -52,10 +52,7 @@ const WALLET_SPACE_MAGIC: &[u8; 12] = b"WALLET_SPACE";
52
52
const WALLET_COIN_MAGIC : & [ u8 ; 12 ] = b"WALLET_COINS" ;
53
53
54
54
pub struct SpacesWallet {
55
- pub name : String ,
56
- pub data_dir : PathBuf ,
57
- pub start_block : u32 ,
58
- pub network : Network ,
55
+ pub config : WalletConfig ,
59
56
pub coins : bdk_wallet:: wallet:: Wallet ,
60
57
pub spaces : bdk_wallet:: wallet:: Wallet ,
61
58
pub coins_db : bdk_file_store:: Store < ChangeSet > ,
@@ -169,12 +166,12 @@ impl WalletExport {
169
166
170
167
impl SpacesWallet {
171
168
pub fn name ( & self ) -> & str {
172
- & self . name
169
+ & self . config . name
173
170
}
174
171
175
172
pub fn new ( config : WalletConfig ) -> anyhow:: Result < Self > {
176
173
if !config. data_dir . exists ( ) {
177
- std :: fs:: create_dir_all ( config. data_dir . clone ( ) ) ?;
174
+ fs:: create_dir_all ( config. data_dir . clone ( ) ) ?;
178
175
}
179
176
180
177
let spaces_path = config. data_dir . join ( "spaces.db" ) ;
@@ -212,10 +209,7 @@ impl SpacesWallet {
212
209
) ?;
213
210
214
211
let wallet = Self {
215
- name : config. name ,
216
- start_block : config. start_block ,
217
- data_dir : config. data_dir ,
218
- network : config. network ,
212
+ config,
219
213
coins : coins_wallet,
220
214
spaces : spaces_wallet,
221
215
coins_db,
@@ -226,6 +220,15 @@ impl SpacesWallet {
226
220
Ok ( wallet)
227
221
}
228
222
223
+ pub fn rebuild ( self ) -> anyhow:: Result < Self > {
224
+ let config = self . config ;
225
+ drop ( self . spaces_db ) ;
226
+ drop ( self . coins_db ) ;
227
+ fs:: remove_file ( config. data_dir . join ( "spaces.db" ) ) ?;
228
+ fs:: remove_file ( config. data_dir . join ( "coins.db" ) ) ?;
229
+ Ok ( SpacesWallet :: new ( config) ?)
230
+ }
231
+
229
232
pub fn get_info ( & self ) -> WalletInfo {
230
233
let mut descriptors = Vec :: with_capacity ( 4 ) ;
231
234
@@ -263,8 +266,8 @@ impl SpacesWallet {
263
266
} ) ;
264
267
265
268
WalletInfo {
266
- label : self . name . clone ( ) ,
267
- start_block : self . start_block ,
269
+ label : self . config . name . clone ( ) ,
270
+ start_block : self . config . start_block ,
268
271
tip : self . coins . local_chain ( ) . tip ( ) . height ( ) ,
269
272
descriptors,
270
273
}
@@ -297,8 +300,8 @@ impl SpacesWallet {
297
300
WalletExport {
298
301
descriptor,
299
302
spaces_descriptor,
300
- block_height : self . start_block ,
301
- label : self . name . clone ( ) ,
303
+ block_height : self . config . start_block ,
304
+ label : self . config . name . clone ( ) ,
302
305
}
303
306
}
304
307
@@ -603,14 +606,14 @@ impl SpacesWallet {
603
606
}
604
607
605
608
fn get_signing_info ( & self , script : & ScriptBuf ) -> Option < Vec < u8 > > {
606
- let script_info_dir = self . data_dir . join ( "script_solutions" ) ;
609
+ let script_info_dir = self . config . data_dir . join ( "script_solutions" ) ;
607
610
let filename = hex:: encode ( script. as_bytes ( ) ) ;
608
611
let file_path = script_info_dir. join ( filename) ;
609
612
std:: fs:: read ( file_path) . ok ( )
610
613
}
611
614
612
615
fn save_signing_info ( & self , script : ScriptBuf , raw : Vec < u8 > ) -> anyhow:: Result < ( ) > {
613
- let script_info_dir = self . data_dir . join ( "script_solutions" ) ;
616
+ let script_info_dir = self . config . data_dir . join ( "script_solutions" ) ;
614
617
std:: fs:: create_dir_all ( & script_info_dir)
615
618
. context ( "could not create script_info directory" ) ?;
616
619
let filename = hex:: encode ( script. as_bytes ( ) ) ;
@@ -620,7 +623,7 @@ impl SpacesWallet {
620
623
}
621
624
622
625
fn clear_unused_signing_info ( & self ) {
623
- let script_info_dir = self . data_dir . join ( "script_solutions" ) ;
626
+ let script_info_dir = self . config . data_dir . join ( "script_solutions" ) ;
624
627
let one_week_ago = SystemTime :: now ( ) - Duration :: from_secs ( 7 * 24 * 60 * 60 ) ;
625
628
626
629
let entries = match fs:: read_dir ( & script_info_dir) {
0 commit comments