2
2
pub use crate :: config:: BuilderConfig ;
3
3
use crate :: tasks:: oauth:: Authenticator ;
4
4
use oauth2:: TokenResponse ;
5
- use reqwest:: Url ;
5
+ use reqwest:: { Client , Url } ;
6
6
use serde:: { Deserialize , Serialize } ;
7
7
use signet_bundle:: SignetEthBundle ;
8
8
use tokio:: sync:: mpsc:: { UnboundedReceiver , UnboundedSender , unbounded_channel} ;
@@ -32,6 +32,8 @@ pub struct BundlePoller {
32
32
pub config : BuilderConfig ,
33
33
/// Authentication module that periodically fetches and stores auth tokens.
34
34
pub authenticator : Authenticator ,
35
+ /// Holds a Reqwest client
36
+ pub client : Client ,
35
37
/// Defines the interval at which the bundler polls the tx-pool for bundles.
36
38
pub poll_interval_ms : u64 ,
37
39
}
@@ -40,7 +42,12 @@ pub struct BundlePoller {
40
42
impl BundlePoller {
41
43
/// Creates a new BundlePoller from the provided builder config.
42
44
pub fn new ( config : & BuilderConfig , authenticator : Authenticator ) -> Self {
43
- Self { config : config. clone ( ) , authenticator, poll_interval_ms : 1000 }
45
+ Self {
46
+ config : config. clone ( ) ,
47
+ authenticator,
48
+ client : Client :: new ( ) ,
49
+ poll_interval_ms : 1000 ,
50
+ }
44
51
}
45
52
46
53
/// Creates a new BundlePoller from the provided builder config and with the specified poll interval in ms.
@@ -49,15 +56,16 @@ impl BundlePoller {
49
56
authenticator : Authenticator ,
50
57
poll_interval_ms : u64 ,
51
58
) -> Self {
52
- Self { config : config. clone ( ) , authenticator, poll_interval_ms }
59
+ Self { config : config. clone ( ) , authenticator, client : Client :: new ( ) , poll_interval_ms }
53
60
}
54
61
55
62
/// Fetches bundles from the transaction cache and returns them.
56
63
pub async fn check_bundle_cache ( & mut self ) -> eyre:: Result < Vec < Bundle > > {
57
64
let bundle_url: Url = Url :: parse ( & self . config . tx_pool_url ) ?. join ( "bundles" ) ?;
58
65
let token = self . authenticator . fetch_oauth_token ( ) . await ?;
59
66
60
- let result = reqwest:: Client :: new ( )
67
+ let result = self
68
+ . client
61
69
. get ( bundle_url)
62
70
. bearer_auth ( token. access_token ( ) . secret ( ) )
63
71
. send ( )
0 commit comments