@@ -66,12 +66,52 @@ impl BuilderTxCache {
6666 . map_err ( Into :: into)
6767 }
6868
69+ async fn get_inner_with_query_and_token < T > (
70+ & self ,
71+ join : & ' static str ,
72+ query : PaginationParams ,
73+ ) -> Result < T , Error >
74+ where
75+ T : DeserializeOwned ,
76+ {
77+ // Append the path to the URL.
78+ let secret = self . token . secret ( ) . await ?;
79+ let url = self
80+ . url
81+ . join ( join)
82+ . inspect_err ( |e| warn ! ( %e, "Failed to join URL. Not querying transaction cache." ) ) ?;
83+
84+ let mut request = self . client . get ( url) ;
85+
86+ if let Some ( cursor) = query. cursor ( ) {
87+ request = request. query ( & [ ( "cursor" , cursor) ] ) ;
88+ }
89+ if let Some ( limit) = query. limit ( ) {
90+ request = request. query ( & [ ( "limit" , limit) ] ) ;
91+ }
92+
93+ request
94+ . bearer_auth ( secret)
95+ . send ( )
96+ . await
97+ . inspect_err ( |e| warn ! ( %e, "Failed to get object from transaction cache." ) ) ?
98+ . json :: < T > ( )
99+ . await
100+ . map_err ( Into :: into)
101+ }
102+
69103 /// Get bundles from the cache.
70104 #[ instrument( skip_all) ]
71- pub async fn get_bundles ( & self ) -> Result < Vec < TxCacheBundle > > {
72- self . get_inner_with_token :: < TxCacheBundlesResponse > ( BUNDLES )
73- . await
74- . map ( |response| response. bundles )
105+ pub async fn get_bundles ( & self , query : Option < PaginationParams > ) -> Result < Vec < TxCacheBundle > > {
106+ if let Some ( query) = query {
107+ self . get_inner_with_query_and_token :: < TxCacheBundlesResponse > ( BUNDLES , query)
108+ . await
109+ . map ( |response| response. bundles )
110+ } else {
111+ self . get_inner_with_token :: < TxCacheBundlesResponse > ( BUNDLES )
112+ . await
113+ . map ( |response| response. bundles )
114+ }
75115 }
76116
77117 fn get_bundle_url_path ( & self , bundle_id : & str ) -> String {
0 commit comments