|
1 | 1 | use crate::types::{ |
2 | | - TxCacheOrdersResponse, TxCacheSendBundleResponse, TxCacheSendTransactionResponse, |
3 | | - TxCacheTransactionsResponse, |
| 2 | + CacheObject, CacheResponse, OrderKey, TxCacheOrdersResponse, TxCacheSendBundleResponse, |
| 3 | + TxCacheSendTransactionResponse, TxCacheTransactionsResponse, TxKey, |
4 | 4 | }; |
5 | 5 | use alloy::consensus::TxEnvelope; |
6 | 6 | use eyre::Error; |
@@ -93,22 +93,21 @@ impl TxCache { |
93 | 93 | self.client.post(url).json(&obj).send().await?.error_for_status().map_err(Into::into) |
94 | 94 | } |
95 | 95 |
|
96 | | - async fn get_inner<T>(&self, join: &'static str) -> Result<T, Error> |
| 96 | + async fn get_inner<T>(&self, join: &'static str, query: Option<T::Key>) -> Result<T, Error> |
97 | 97 | where |
98 | | - T: DeserializeOwned, |
| 98 | + T: DeserializeOwned + CacheObject, |
99 | 99 | { |
100 | | - // Append the path to the URL. |
101 | 100 | let url = self |
102 | 101 | .url |
103 | 102 | .join(join) |
104 | 103 | .inspect_err(|e| warn!(%e, "Failed to join URL. Not querying transaction cache."))?; |
105 | 104 |
|
106 | | - // Get the result. |
107 | 105 | self.client |
108 | 106 | .get(url) |
| 107 | + .query(&query) |
109 | 108 | .send() |
110 | 109 | .await |
111 | | - .inspect_err(|e| warn!(%e, "Failed to get object from transaction cache"))? |
| 110 | + .inspect_err(|e| warn!(%e, "Failed to get object from transaction cache."))? |
112 | 111 | .json::<T>() |
113 | 112 | .await |
114 | 113 | .map_err(Into::into) |
@@ -140,17 +139,19 @@ impl TxCache { |
140 | 139 |
|
141 | 140 | /// Get transactions from the URL. |
142 | 141 | #[instrument(skip_all)] |
143 | | - pub async fn get_transactions(&self) -> Result<Vec<TxEnvelope>, Error> { |
144 | | - let response: TxCacheTransactionsResponse = |
145 | | - self.get_inner::<TxCacheTransactionsResponse>(TRANSACTIONS).await?; |
146 | | - Ok(response.transactions) |
| 142 | + pub async fn get_transactions( |
| 143 | + &self, |
| 144 | + query: Option<TxKey>, |
| 145 | + ) -> Result<CacheResponse<TxCacheTransactionsResponse>, Error> { |
| 146 | + self.get_inner(TRANSACTIONS, query).await |
147 | 147 | } |
148 | 148 |
|
149 | 149 | /// Get signed orders from the URL. |
150 | 150 | #[instrument(skip_all)] |
151 | | - pub async fn get_orders(&self) -> Result<Vec<SignedOrder>, Error> { |
152 | | - let response: TxCacheOrdersResponse = |
153 | | - self.get_inner::<TxCacheOrdersResponse>(ORDERS).await?; |
154 | | - Ok(response.orders) |
| 151 | + pub async fn get_orders( |
| 152 | + &self, |
| 153 | + query: Option<OrderKey>, |
| 154 | + ) -> Result<CacheResponse<TxCacheOrdersResponse>, Error> { |
| 155 | + self.get_inner(ORDERS, query).await |
155 | 156 | } |
156 | 157 | } |
0 commit comments