66// accordance with one or both of these licenses.
77
88use std:: collections:: { HashMap , VecDeque } ;
9+ use std:: future:: Future ;
910use std:: sync:: atomic:: { AtomicU64 , Ordering } ;
1011use std:: sync:: { Arc , Mutex , RwLock } ;
1112use std:: time:: { Duration , Instant , SystemTime , UNIX_EPOCH } ;
@@ -23,7 +24,7 @@ use lightning_block_sync::poll::{ChainPoller, ChainTip, ValidatedBlockHeader};
2324use lightning_block_sync:: rest:: RestClient ;
2425use lightning_block_sync:: rpc:: { RpcClient , RpcError } ;
2526use lightning_block_sync:: {
26- AsyncBlockSourceResult , BlockData , BlockHeaderData , BlockSource , BlockSourceErrorKind , Cache ,
27+ BlockData , BlockHeaderData , BlockSource , BlockSourceError , BlockSourceErrorKind , Cache ,
2728 SpvClient ,
2829} ;
2930use serde:: Serialize ;
@@ -655,44 +656,58 @@ impl std::ops::Deref for UtxoSourceClient {
655656impl BlockSource for UtxoSourceClient {
656657 fn get_header < ' a > (
657658 & ' a self , header_hash : & ' a BlockHash , height_hint : Option < u32 > ,
658- ) -> AsyncBlockSourceResult < ' a , BlockHeaderData > {
659- match self {
660- Self :: Rpc ( client) => client. get_header ( header_hash, height_hint) ,
661- Self :: Rest ( client) => client. get_header ( header_hash, height_hint) ,
659+ ) -> impl Future < Output = Result < BlockHeaderData , BlockSourceError > > + ' a {
660+ async move {
661+ match self {
662+ Self :: Rpc ( client) => client. get_header ( header_hash, height_hint) . await ,
663+ Self :: Rest ( client) => client. get_header ( header_hash, height_hint) . await ,
664+ }
662665 }
663666 }
664667
665668 fn get_block < ' a > (
666669 & ' a self , header_hash : & ' a BlockHash ,
667- ) -> AsyncBlockSourceResult < ' a , BlockData > {
668- match self {
669- Self :: Rpc ( client) => client. get_block ( header_hash) ,
670- Self :: Rest ( client) => client. get_block ( header_hash) ,
670+ ) -> impl Future < Output = Result < BlockData , BlockSourceError > > + ' a {
671+ async move {
672+ match self {
673+ Self :: Rpc ( client) => client. get_block ( header_hash) . await ,
674+ Self :: Rest ( client) => client. get_block ( header_hash) . await ,
675+ }
671676 }
672677 }
673678
674- fn get_best_block ( & self ) -> AsyncBlockSourceResult < ' _ , ( BlockHash , Option < u32 > ) > {
675- match self {
676- Self :: Rpc ( client) => client. get_best_block ( ) ,
677- Self :: Rest ( client) => client. get_best_block ( ) ,
679+ fn get_best_block < ' a > (
680+ & ' a self ,
681+ ) -> impl Future < Output = Result < ( BlockHash , Option < u32 > ) , BlockSourceError > > + ' a {
682+ async move {
683+ match self {
684+ Self :: Rpc ( client) => client. get_best_block ( ) . await ,
685+ Self :: Rest ( client) => client. get_best_block ( ) . await ,
686+ }
678687 }
679688 }
680689}
681690
682691impl UtxoSource for UtxoSourceClient {
683692 fn get_block_hash_by_height < ' a > (
684693 & ' a self , block_height : u32 ,
685- ) -> AsyncBlockSourceResult < ' a , BlockHash > {
686- match self {
687- Self :: Rpc ( client) => client. get_block_hash_by_height ( block_height) ,
688- Self :: Rest ( client) => client. get_block_hash_by_height ( block_height) ,
694+ ) -> impl Future < Output = Result < BlockHash , BlockSourceError > > + ' a {
695+ async move {
696+ match self {
697+ Self :: Rpc ( client) => client. get_block_hash_by_height ( block_height) . await ,
698+ Self :: Rest ( client) => client. get_block_hash_by_height ( block_height) . await ,
699+ }
689700 }
690701 }
691702
692- fn is_output_unspent < ' a > ( & ' a self , outpoint : OutPoint ) -> AsyncBlockSourceResult < ' a , bool > {
693- match self {
694- Self :: Rpc ( client) => client. is_output_unspent ( outpoint) ,
695- Self :: Rest ( client) => client. is_output_unspent ( outpoint) ,
703+ fn is_output_unspent < ' a > (
704+ & ' a self , outpoint : OutPoint ,
705+ ) -> impl Future < Output = Result < bool , BlockSourceError > > + ' a {
706+ async move {
707+ match self {
708+ Self :: Rpc ( client) => client. is_output_unspent ( outpoint) . await ,
709+ Self :: Rest ( client) => client. is_output_unspent ( outpoint) . await ,
710+ }
696711 }
697712 }
698713}
@@ -1245,38 +1260,40 @@ impl BitcoindClient {
12451260impl BlockSource for BitcoindClient {
12461261 fn get_header < ' a > (
12471262 & ' a self , header_hash : & ' a bitcoin:: BlockHash , height_hint : Option < u32 > ,
1248- ) -> AsyncBlockSourceResult < ' a , BlockHeaderData > {
1249- match self {
1250- BitcoindClient :: Rpc { rpc_client, .. } => {
1251- Box :: pin ( async move { rpc_client. get_header ( header_hash, height_hint) . await } )
1252- } ,
1253- BitcoindClient :: Rest { rest_client, .. } => {
1254- Box :: pin ( async move { rest_client. get_header ( header_hash, height_hint) . await } )
1255- } ,
1263+ ) -> impl Future < Output = Result < BlockHeaderData , BlockSourceError > > + ' a {
1264+ async move {
1265+ match self {
1266+ BitcoindClient :: Rpc { rpc_client, .. } => {
1267+ rpc_client. get_header ( header_hash, height_hint) . await
1268+ } ,
1269+ BitcoindClient :: Rest { rest_client, .. } => {
1270+ rest_client. get_header ( header_hash, height_hint) . await
1271+ } ,
1272+ }
12561273 }
12571274 }
12581275
12591276 fn get_block < ' a > (
12601277 & ' a self , header_hash : & ' a bitcoin:: BlockHash ,
1261- ) -> AsyncBlockSourceResult < ' a , BlockData > {
1262- match self {
1263- BitcoindClient :: Rpc { rpc_client , .. } => {
1264- Box :: pin ( async move { rpc_client. get_block ( header_hash) . await } )
1265- } ,
1266- BitcoindClient :: Rest { rest_client, .. } => {
1267- Box :: pin ( async move { rest_client . get_block ( header_hash ) . await } )
1268- } ,
1278+ ) -> impl Future < Output = Result < BlockData , BlockSourceError > > + ' a {
1279+ async move {
1280+ match self {
1281+ BitcoindClient :: Rpc { rpc_client, .. } => rpc_client . get_block ( header_hash) . await ,
1282+ BitcoindClient :: Rest { rest_client , .. } => {
1283+ rest_client. get_block ( header_hash ) . await
1284+ } ,
1285+ }
12691286 }
12701287 }
12711288
1272- fn get_best_block ( & self ) -> AsyncBlockSourceResult < ' _ , ( bitcoin :: BlockHash , Option < u32 > ) > {
1273- match self {
1274- BitcoindClient :: Rpc { rpc_client , .. } => {
1275- Box :: pin ( async move { rpc_client . get_best_block ( ) . await } )
1276- } ,
1277- BitcoindClient :: Rest { rest_client , .. } => {
1278- Box :: pin ( async move { rest_client. get_best_block ( ) . await } )
1279- } ,
1289+ fn get_best_block < ' a > (
1290+ & ' a self ,
1291+ ) -> impl Future < Output = Result < ( bitcoin :: BlockHash , Option < u32 > ) , BlockSourceError > > + ' a {
1292+ async move {
1293+ match self {
1294+ BitcoindClient :: Rpc { rpc_client , .. } => rpc_client . get_best_block ( ) . await ,
1295+ BitcoindClient :: Rest { rest_client, .. } => rest_client . get_best_block ( ) . await ,
1296+ }
12801297 }
12811298 }
12821299}
0 commit comments