1- use std:: { fs:: File , io:: Write , sync :: Arc } ;
1+ use std:: { fs:: File , io:: Write , path :: PathBuf , str :: FromStr } ;
22
33use hintfile:: write_compact_size;
44use kernel:: { ChainType , ChainstateManager , ChainstateManagerOptions , ContextBuilder , KernelError } ;
55
6- const CHAIN_TYPE : ChainType = ChainType :: SIGNET ;
6+ configure_me :: include_config! ( ) ;
77
8- fn main ( ) {
9- let mut file = File :: create ( "./bitcoin.hints" ) . unwrap ( ) ;
8+ fn chain_type_from_string ( network : String ) -> ChainType {
9+ match network. to_lowercase ( ) . as_ref ( ) {
10+ "bitcoin" => ChainType :: MAINNET ,
11+ "signet" => ChainType :: SIGNET ,
12+ _ => panic ! ( "supported chains are `bitcoin` or `signet`" ) ,
13+ }
14+ }
1015
11- let mut args = std:: env:: args ( ) ;
12- let _ = args. next ( ) ;
13- let data_dir = args. next ( ) . expect ( "Usage: <path_to_bitcoin_dir>" ) ;
14- let mut blocks_dir = data_dir. clone ( ) ;
15- blocks_dir. push_str ( "/blocks" ) ;
16+ fn main ( ) {
17+ let ( config, _) = Config :: including_optional_config_files :: < & [ & str ] > ( & [ ] ) . unwrap_or_exit ( ) ;
18+ let chain_type = chain_type_from_string ( config. network ) ;
19+ let hintfile_path = PathBuf :: from_str ( & config. name ) . unwrap ( ) ;
20+ let bitcoind = PathBuf :: from_str ( & config. bitcoin_dir ) . unwrap ( ) ;
21+ let blocks_dir = bitcoind. join ( "blocks" ) ;
22+ let mut file = File :: create ( hintfile_path) . unwrap ( ) ;
1623 println ! ( "Initializing" ) ;
1724 let ctx = ContextBuilder :: new ( )
18- . chain_type ( CHAIN_TYPE )
25+ . chain_type ( chain_type )
1926 . build ( )
2027 . unwrap ( ) ;
21- let options = ChainstateManagerOptions :: new ( & ctx, & data_dir, & blocks_dir) . unwrap ( ) ;
22- let _context = Arc :: new ( ctx) ;
28+ let options = ChainstateManagerOptions :: new (
29+ & ctx,
30+ bitcoind. to_str ( ) . unwrap ( ) ,
31+ blocks_dir. to_str ( ) . unwrap ( ) ,
32+ )
33+ . unwrap ( ) ;
2334 let chainman = ChainstateManager :: new ( options) . unwrap ( ) ;
2435 println ! ( "Chain state initialized" ) ;
2536 // Writing the chain tip allows the client to know where to stop
@@ -39,6 +50,7 @@ fn main() {
3950 if chainman. have_coin ( & transaction, vout) {
4051 println ! ( "Found coin at offset {curr}" ) ;
4152 block_unspents. push ( curr) ;
53+ curr = 0 ;
4254 }
4355 curr += 1 ;
4456 }
0 commit comments