@@ -29,13 +29,10 @@ use bdk_sp::{
2929} ;
3030use bdk_sp_oracles:: {
3131 bip157:: {
32- self ,
33- tokio:: { self , select} ,
34- AddrV2 , Builder , Client as KyotoClient , HeaderCheckpoint , IndexedBlock , Info , ServiceFlags ,
35- TrustedPeer , UnboundedReceiver , Warning ,
32+ self , AddrV2 , Builder , Client as KyotoClient , HeaderCheckpoint , IndexedBlock , Info , ServiceFlags , TrustedPeer , UnboundedReceiver , Warning , tokio:: { self , select}
3633 } ,
3734 filters:: kyoto:: { FilterEvent , FilterSubscriber } ,
38- frigate:: { FrigateClient , History , SubscribeRequest , UnsubscribeRequest } ,
35+ frigate:: { DUMMY_COINBASE , FrigateClient , History , SubscribeRequest , UnsubscribeRequest } ,
3936 tweaks:: blindbit:: { BlindbitSubscriber , TweakEvent } ,
4037} ;
4138use bdk_sp_wallet:: {
@@ -167,9 +164,10 @@ pub enum Commands {
167164 ScanFrigate {
168165 #[ clap( flatten) ]
169166 rpc_args : RpcArgs ,
170- /// The scan private key for which outputs will be scanned for.
171167 #[ clap( long) ]
172- start : Option < u32 > ,
168+ height : Option < u32 > ,
169+ #[ clap( long) ]
170+ hash : Option < BlockHash > ,
173171 } ,
174172
175173 Create {
@@ -578,15 +576,33 @@ async fn main() -> anyhow::Result<()> {
578576 ) ;
579577 }
580578 }
581- Commands :: ScanFrigate { rpc_args, start } => {
582- // The implementation done here differ from what mentionned in the section https://github.com/sparrowwallet/frigate/tree/master?tab=readme-ov-file#blockchainsilentpaymentssubscribe
583- // We are doing a one time scanning only. So instead of calling `blockchain.scripthash.subscribe` on each script from the wallet,
584- // we just subscribe and read the scanning result from the stream. On each result received we update the wallet state and once scanning progress reaches 1.0 (100%) we stop.
579+ Commands :: ScanFrigate { rpc_args, height, hash } => {
580+ // The implementation done here differs from what is mentioned in the section
581+ // https://github.com/sparrowwallet/frigate/tree/master?tab=readme-ov-file#blockchainsilentpaymentssubscribe
582+ // This implementation is doing a one time scanning only. So instead of calling
583+ // `blockchain.scripthash.subscribe` on each script from the wallet, we just subscribe
584+ // and read the scanning result from the stream. On each result received we update the
585+ // wallet state and once scanning progress reaches 1.0 (100%) we stop.
586+ let sync_point = if let ( Some ( height) , Some ( hash) ) = ( height, hash) {
587+ HeaderCheckpoint :: new ( height, hash)
588+ } else if wallet. birthday . height <= wallet. chain ( ) . tip ( ) . height ( ) {
589+ let height = wallet. chain ( ) . tip ( ) . height ( ) ;
590+ let hash = wallet. chain ( ) . tip ( ) . hash ( ) ;
591+ HeaderCheckpoint :: new ( height, hash)
592+ } else {
593+ let checkpoint = wallet
594+ . chain ( )
595+ . get ( wallet. birthday . height )
596+ . expect ( "should be something" ) ;
597+ let height = checkpoint. height ( ) ;
598+ let hash = checkpoint. hash ( ) ;
599+ HeaderCheckpoint :: new ( height, hash)
600+ } ;
585601
586602 let mut client = FrigateClient :: connect ( & rpc_args. url )
587603 . await
588604 . unwrap ( )
589- . with_timeout ( tokio:: time:: Duration :: from_secs ( 600 ) ) ;
605+ . with_timeout ( tokio:: time:: Duration :: from_secs ( 60 ) ) ;
590606
591607 let labels = wallet
592608 . indexer ( )
@@ -604,7 +620,7 @@ async fn main() -> anyhow::Result<()> {
604620 let subscribe_params = SubscribeRequest {
605621 scan_priv_key : * wallet. indexer ( ) . scan_sk ( ) ,
606622 spend_pub_key : * wallet. indexer ( ) . spend_pk ( ) ,
607- start_height : start ,
623+ start_height : Some ( sync_point . height ) ,
608624 labels,
609625 } ;
610626
@@ -661,9 +677,8 @@ async fn main() -> anyhow::Result<()> {
661677 raw_blk. push_str ( "00" ) ;
662678
663679 // Push dummy coinbase
664- let dummy_coinbase = "01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff1b03951a0604f15ccf5609013803062b9b5a0100072f425443432f20000000000000000000" ;
665680 let coinbase: Transaction =
666- deserialize ( & Vec :: < u8 > :: from_hex ( dummy_coinbase ) . unwrap ( ) )
681+ deserialize ( & Vec :: < u8 > :: from_hex ( DUMMY_COINBASE ) . unwrap ( ) )
667682 . unwrap ( ) ;
668683 let mut block: Block =
669684 deserialize ( & Vec :: < u8 > :: from_hex ( & raw_blk) . unwrap ( ) ) . unwrap ( ) ;
0 commit comments