11use crate :: codec:: { TAG_NON_ADDR , TAG_OP_RETURN , TAG_SEGWIT } ;
2- use crate :: config:: BitcoinConfig ;
32use crate :: model_v1:: { Address , Block , BlockHash , BlockPointer , Header , Height , InputRef , MerkleRoot , ScriptHash , Timestamp , Transaction , TransactionPointer , TxHash , Utxo , Weight } ;
43use crate :: rest_client:: { BtcCBOR , BtcClient } ;
5- use crate :: ExplorerError ;
4+ use crate :: { BitcoinConfig , ExplorerError } ;
65use async_trait:: async_trait;
6+ use tokio_util:: sync:: CancellationToken ;
77use chain:: api:: { BlockProvider , ChainError } ;
88use chain:: monitor:: BoxWeight ;
99use chain:: settings:: Parallelism ;
@@ -13,6 +13,7 @@ use redbit::info;
1313use redbit:: * ;
1414use serde_json;
1515use std:: { fs, pin:: Pin , sync:: Arc } ;
16+ use chain:: chain_config;
1617use redbit:: redb:: Durability ;
1718
1819pub struct BtcBlockProvider {
@@ -22,7 +23,7 @@ pub struct BtcBlockProvider {
2223
2324impl BtcBlockProvider {
2425 pub fn new ( ) -> Result < Arc < Self > , ExplorerError > {
25- let config = BitcoinConfig :: new ( "config/btc" ) . expect ( "Failed to load Bitcoin configuration" ) ;
26+ let config: BitcoinConfig = chain_config :: load_config ( "config/btc" , "BITCOIN ") . expect ( "Failed to load Bitcoin configuration" ) ;
2627 let client = Arc :: new ( BtcClient :: new ( & config) ?) ;
2728 let fetching_par: Parallelism = config. fetching_parallelism . clone ( ) ;
2829 Ok ( Arc :: new ( BtcBlockProvider { client, fetching_par } ) )
@@ -193,7 +194,7 @@ impl BlockProvider<BtcCBOR, Block> for BtcBlockProvider {
193194 remote_chain_tip_header : Header ,
194195 last_persisted_header : Option < Header > ,
195196 durability : Durability
196- ) -> Pin < Box < dyn Stream < Item = BtcCBOR > + Send + ' static > > {
197+ ) -> ( Pin < Box < dyn Stream < Item = BtcCBOR > + Send + ' static > > , CancellationToken ) {
197198 let height_to_index_from = last_persisted_header. map_or ( 1 , |h| h. height . 0 + 1 ) ;
198199 let heights = height_to_index_from..=remote_chain_tip_header. height . 0 ;
199200 let client = Arc :: clone ( & self . client ) ;
@@ -204,11 +205,12 @@ impl BlockProvider<BtcCBOR, Block> for BtcBlockProvider {
204205 client. get_block_by_height ( Height ( height) ) . await . expect ( "Failed to fetch block by height" )
205206 }
206207 } ) ;
207- match durability {
208+ let stream = match durability {
208209 Durability :: None => s. buffer_unordered ( self . fetching_par . 0 ) . boxed ( ) ,
209210 Durability :: Immediate => s. buffered ( self . fetching_par . 0 ) . boxed ( ) ,
210211 _ => unreachable ! ( "Only None and Immediate durability modes are supported" ) ,
211- }
212+ } ;
213+ ( stream, CancellationToken :: new ( ) )
212214 }
213215}
214216
0 commit comments