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 ;
@@ -643,46 +644,56 @@ impl BlockSource for UtxoSourceClient {
643644 & ' a self ,
644645 header_hash : & ' a BlockHash ,
645646 height_hint : Option < u32 > ,
646- ) -> AsyncBlockSourceResult < ' a , BlockHeaderData > {
647- match self {
648- Self :: Rpc ( client) => client. get_header ( header_hash, height_hint) ,
649- Self :: Rest ( client) => client. get_header ( header_hash, height_hint) ,
647+ ) -> impl Future < Output = Result < BlockHeaderData , BlockSourceError > > + ' a {
648+ async move {
649+ match self {
650+ Self :: Rpc ( client) => client. get_header ( header_hash, height_hint) . await ,
651+ Self :: Rest ( client) => client. get_header ( header_hash, height_hint) . await ,
652+ }
650653 }
651654 }
652655
653656 fn get_block < ' a > (
654657 & ' a self ,
655658 header_hash : & ' a BlockHash ,
656- ) -> AsyncBlockSourceResult < ' a , BlockData > {
657- match self {
658- Self :: Rpc ( client) => client. get_block ( header_hash) ,
659- Self :: Rest ( client) => client. get_block ( header_hash) ,
659+ ) -> impl Future < Output = Result < BlockData , BlockSourceError > > + ' a {
660+ async move {
661+ match self {
662+ Self :: Rpc ( client) => client. get_block ( header_hash) . await ,
663+ Self :: Rest ( client) => client. get_block ( header_hash) . await ,
664+ }
660665 }
661666 }
662667
663- fn get_best_block (
664- & self ,
665- ) -> AsyncBlockSourceResult < ' _ , ( BlockHash , Option < u32 > ) > {
666- match self {
667- Self :: Rpc ( client) => client. get_best_block ( ) ,
668- Self :: Rest ( client) => client. get_best_block ( ) ,
668+ fn get_best_block < ' a > (
669+ & ' a self ,
670+ ) -> impl Future < Output = Result < ( BlockHash , Option < u32 > ) , BlockSourceError > > + ' a {
671+ async move {
672+ match self {
673+ Self :: Rpc ( client) => client. get_best_block ( ) . await ,
674+ Self :: Rest ( client) => client. get_best_block ( ) . await ,
675+ }
669676 }
670677 }
671678}
672679
673680
674681impl UtxoSource for UtxoSourceClient {
675- fn get_block_hash_by_height < ' a > ( & ' a self , block_height : u32 ) -> AsyncBlockSourceResult < ' a , BlockHash > {
676- match self {
677- Self :: Rpc ( client) => client. get_block_hash_by_height ( block_height) ,
678- Self :: Rest ( client) => client. get_block_hash_by_height ( block_height) ,
682+ fn get_block_hash_by_height < ' a > ( & ' a self , block_height : u32 ) -> impl Future < Output = Result < BlockHash , BlockSourceError > > + ' a {
683+ async move {
684+ match self {
685+ Self :: Rpc ( client) => client. get_block_hash_by_height ( block_height) . await ,
686+ Self :: Rest ( client) => client. get_block_hash_by_height ( block_height) . await ,
687+ }
679688 }
680689 }
681690
682- fn is_output_unspent < ' a > ( & ' a self , outpoint : OutPoint ) -> AsyncBlockSourceResult < ' a , bool > {
683- match self {
684- Self :: Rpc ( client) => client. is_output_unspent ( outpoint) ,
685- Self :: Rest ( client) => client. is_output_unspent ( outpoint) ,
691+ fn is_output_unspent < ' a > ( & ' a self , outpoint : OutPoint ) -> impl Future < Output = Result < bool , BlockSourceError > > + ' a {
692+ async move {
693+ match self {
694+ Self :: Rpc ( client) => client. is_output_unspent ( outpoint) . await ,
695+ Self :: Rest ( client) => client. is_output_unspent ( outpoint) . await ,
696+ }
686697 }
687698 }
688699}
@@ -1235,38 +1246,44 @@ impl BitcoindClient {
12351246impl BlockSource for BitcoindClient {
12361247 fn get_header < ' a > (
12371248 & ' a self , header_hash : & ' a bitcoin:: BlockHash , height_hint : Option < u32 > ,
1238- ) -> AsyncBlockSourceResult < ' a , BlockHeaderData > {
1239- match self {
1240- BitcoindClient :: Rpc { rpc_client, .. } => {
1241- Box :: pin ( async move { rpc_client. get_header ( header_hash, height_hint) . await } )
1242- } ,
1243- BitcoindClient :: Rest { rest_client, .. } => {
1244- Box :: pin ( async move { rest_client. get_header ( header_hash, height_hint) . await } )
1245- } ,
1249+ ) -> impl Future < Output = Result < BlockHeaderData , BlockSourceError > > + ' a {
1250+ async move {
1251+ match self {
1252+ BitcoindClient :: Rpc { rpc_client, .. } => {
1253+ rpc_client. get_header ( header_hash, height_hint) . await
1254+ } ,
1255+ BitcoindClient :: Rest { rest_client, .. } => {
1256+ rest_client. get_header ( header_hash, height_hint) . await
1257+ } ,
1258+ }
12461259 }
12471260 }
12481261
12491262 fn get_block < ' a > (
12501263 & ' a self , header_hash : & ' a bitcoin:: BlockHash ,
1251- ) -> AsyncBlockSourceResult < ' a , BlockData > {
1252- match self {
1253- BitcoindClient :: Rpc { rpc_client, .. } => {
1254- Box :: pin ( async move { rpc_client. get_block ( header_hash) . await } )
1255- } ,
1256- BitcoindClient :: Rest { rest_client, .. } => {
1257- Box :: pin ( async move { rest_client. get_block ( header_hash) . await } )
1258- } ,
1264+ ) -> impl Future < Output = Result < BlockData , BlockSourceError > > + ' a {
1265+ async move {
1266+ match self {
1267+ BitcoindClient :: Rpc { rpc_client, .. } => {
1268+ rpc_client. get_block ( header_hash) . await
1269+ } ,
1270+ BitcoindClient :: Rest { rest_client, .. } => {
1271+ rest_client. get_block ( header_hash) . await
1272+ } ,
1273+ }
12591274 }
12601275 }
12611276
1262- fn get_best_block ( & self ) -> AsyncBlockSourceResult < ' _ , ( bitcoin:: BlockHash , Option < u32 > ) > {
1263- match self {
1264- BitcoindClient :: Rpc { rpc_client, .. } => {
1265- Box :: pin ( async move { rpc_client. get_best_block ( ) . await } )
1266- } ,
1267- BitcoindClient :: Rest { rest_client, .. } => {
1268- Box :: pin ( async move { rest_client. get_best_block ( ) . await } )
1269- } ,
1277+ fn get_best_block < ' a > ( & ' a self ) -> impl Future < Output = Result < ( bitcoin:: BlockHash , Option < u32 > ) , BlockSourceError > > + ' a {
1278+ async move {
1279+ match self {
1280+ BitcoindClient :: Rpc { rpc_client, .. } => {
1281+ rpc_client. get_best_block ( ) . await
1282+ } ,
1283+ BitcoindClient :: Rest { rest_client, .. } => {
1284+ rest_client. get_best_block ( ) . await
1285+ } ,
1286+ }
12701287 }
12711288 }
12721289}
0 commit comments