@@ -11,13 +11,17 @@ use anyhow::anyhow;
1111// Substreams only requires the FirehoseEndpoints.
1212#[ derive( Debug ) ]
1313pub enum ChainClient < C : Blockchain > {
14- Firehose ( FirehoseEndpoints ) ,
14+ Firehose ( FirehoseEndpoints , Option < C :: Client > ) ,
1515 Rpc ( C :: Client ) ,
1616}
1717
1818impl < C : Blockchain > ChainClient < C > {
1919 pub fn new_firehose ( firehose_endpoints : FirehoseEndpoints ) -> Self {
20- Self :: Firehose ( firehose_endpoints)
20+ Self :: Firehose ( firehose_endpoints, None )
21+ }
22+
23+ pub fn new_firehose_with_rpc ( firehose_endpoints : FirehoseEndpoints , rpc : C :: Client ) -> Self {
24+ Self :: Firehose ( firehose_endpoints, Some ( rpc) )
2125 }
2226
2327 pub fn new_rpc ( rpc : C :: Client ) -> Self {
@@ -26,21 +30,22 @@ impl<C: Blockchain> ChainClient<C> {
2630
2731 pub fn is_firehose ( & self ) -> bool {
2832 match self {
29- ChainClient :: Firehose ( _) => true ,
33+ ChainClient :: Firehose ( _, _ ) => true ,
3034 ChainClient :: Rpc ( _) => false ,
3135 }
3236 }
3337
3438 pub async fn firehose_endpoint ( & self ) -> anyhow:: Result < Arc < FirehoseEndpoint > > {
3539 match self {
36- ChainClient :: Firehose ( endpoints) => endpoints. endpoint ( ) . await ,
40+ ChainClient :: Firehose ( endpoints, _ ) => endpoints. endpoint ( ) . await ,
3741 _ => Err ( anyhow ! ( "firehose endpoint requested on rpc chain client" ) ) ,
3842 }
3943 }
4044
4145 pub fn rpc ( & self ) -> anyhow:: Result < & C :: Client > {
4246 match self {
4347 Self :: Rpc ( rpc) => Ok ( rpc) ,
48+ Self :: Firehose ( _, Some ( rpc) ) => Ok ( rpc) ,
4449 _ => Err ( anyhow ! ( "rpc endpoint requested on firehose chain client" ) ) ,
4550 }
4651 }
0 commit comments