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,26 +656,34 @@ 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}
@@ -683,17 +692,23 @@ impl BlockSource for UtxoSourceClient {
683692impl UtxoSource for UtxoSourceClient {
684693 fn get_block_hash_by_height < ' a > (
685694 & ' a self , block_height : u32 ,
686- ) -> AsyncBlockSourceResult < ' a , BlockHash > {
687- match self {
688- Self :: Rpc ( client) => client. get_block_hash_by_height ( block_height) ,
689- Self :: Rest ( client) => client. get_block_hash_by_height ( block_height) ,
695+ ) -> impl Future < Output = Result < BlockHash , BlockSourceError > > + ' a {
696+ async move {
697+ match self {
698+ Self :: Rpc ( client) => client. get_block_hash_by_height ( block_height) . await ,
699+ Self :: Rest ( client) => client. get_block_hash_by_height ( block_height) . await ,
700+ }
690701 }
691702 }
692703
693- fn is_output_unspent < ' a > ( & ' a self , outpoint : OutPoint ) -> AsyncBlockSourceResult < ' a , bool > {
694- match self {
695- Self :: Rpc ( client) => client. is_output_unspent ( outpoint) ,
696- Self :: Rest ( client) => client. is_output_unspent ( outpoint) ,
704+ fn is_output_unspent < ' a > (
705+ & ' a self , outpoint : OutPoint ,
706+ ) -> impl Future < Output = Result < bool , BlockSourceError > > + ' a {
707+ async move {
708+ match self {
709+ Self :: Rpc ( client) => client. is_output_unspent ( outpoint) . await ,
710+ Self :: Rest ( client) => client. is_output_unspent ( outpoint) . await ,
711+ }
697712 }
698713 }
699714}
@@ -1246,38 +1261,40 @@ impl BitcoindClient {
12461261impl BlockSource for BitcoindClient {
12471262 fn get_header < ' a > (
12481263 & ' a self , header_hash : & ' a bitcoin:: BlockHash , height_hint : Option < u32 > ,
1249- ) -> AsyncBlockSourceResult < ' a , BlockHeaderData > {
1250- match self {
1251- BitcoindClient :: Rpc { rpc_client, .. } => {
1252- Box :: pin ( async move { rpc_client. get_header ( header_hash, height_hint) . await } )
1253- } ,
1254- BitcoindClient :: Rest { rest_client, .. } => {
1255- Box :: pin ( async move { rest_client. get_header ( header_hash, height_hint) . await } )
1256- } ,
1264+ ) -> impl Future < Output = Result < BlockHeaderData , BlockSourceError > > + ' a {
1265+ async move {
1266+ match self {
1267+ BitcoindClient :: Rpc { rpc_client, .. } => {
1268+ rpc_client. get_header ( header_hash, height_hint) . await
1269+ } ,
1270+ BitcoindClient :: Rest { rest_client, .. } => {
1271+ rest_client. get_header ( header_hash, height_hint) . await
1272+ } ,
1273+ }
12571274 }
12581275 }
12591276
12601277 fn get_block < ' a > (
12611278 & ' a self , header_hash : & ' a bitcoin:: BlockHash ,
1262- ) -> AsyncBlockSourceResult < ' a , BlockData > {
1263- match self {
1264- BitcoindClient :: Rpc { rpc_client , .. } => {
1265- Box :: pin ( async move { rpc_client. get_block ( header_hash) . await } )
1266- } ,
1267- BitcoindClient :: Rest { rest_client, .. } => {
1268- Box :: pin ( async move { rest_client . get_block ( header_hash ) . await } )
1269- } ,
1279+ ) -> impl Future < Output = Result < BlockData , BlockSourceError > > + ' a {
1280+ async move {
1281+ match self {
1282+ BitcoindClient :: Rpc { rpc_client, .. } => rpc_client . get_block ( header_hash) . await ,
1283+ BitcoindClient :: Rest { rest_client , .. } => {
1284+ rest_client. get_block ( header_hash ) . await
1285+ } ,
1286+ }
12701287 }
12711288 }
12721289
1273- fn get_best_block ( & self ) -> AsyncBlockSourceResult < ' _ , ( bitcoin :: BlockHash , Option < u32 > ) > {
1274- match self {
1275- BitcoindClient :: Rpc { rpc_client , .. } => {
1276- Box :: pin ( async move { rpc_client . get_best_block ( ) . await } )
1277- } ,
1278- BitcoindClient :: Rest { rest_client , .. } => {
1279- Box :: pin ( async move { rest_client. get_best_block ( ) . await } )
1280- } ,
1290+ fn get_best_block < ' a > (
1291+ & ' a self ,
1292+ ) -> impl Future < Output = Result < ( bitcoin :: BlockHash , Option < u32 > ) , BlockSourceError > > + ' a {
1293+ async move {
1294+ match self {
1295+ BitcoindClient :: Rpc { rpc_client , .. } => rpc_client . get_best_block ( ) . await ,
1296+ BitcoindClient :: Rest { rest_client, .. } => rest_client . get_best_block ( ) . await ,
1297+ }
12811298 }
12821299 }
12831300}
0 commit comments