Skip to content

Commit c296a10

Browse files
committed
chore: dedup
1 parent 6c964d3 commit c296a10

File tree

3 files changed

+23
-36
lines changed

3 files changed

+23
-36
lines changed

crates/tx-cache/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@ eyre.workspace = true
2121
reqwest.workspace = true
2222
serde = { workspace = true, features = ["derive"] }
2323
tracing.workspace = true
24-
uuid = { workspace = true, features = ["serde"] }
24+
uuid = { workspace = true, features = ["serde", "v4"] }

crates/tx-cache/src/client.rs

Lines changed: 10 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -93,43 +93,26 @@ impl TxCache {
9393
self.client.post(url).json(&obj).send().await?.error_for_status().map_err(Into::into)
9494
}
9595

96-
async fn get_inner<T>(&self, join: &'static str) -> Result<T, Error>
97-
where
98-
T: DeserializeOwned,
99-
{
100-
// Append the path to the URL.
101-
let url = self
102-
.url
103-
.join(join)
104-
.inspect_err(|e| warn!(%e, "Failed to join URL. Not querying transaction cache."))?;
105-
106-
// Get the result.
107-
self.client
108-
.get(url)
109-
.send()
110-
.await
111-
.inspect_err(|e| warn!(%e, "Failed to get object from transaction cache."))?
112-
.json::<T>()
113-
.await
114-
.map_err(Into::into)
115-
}
116-
117-
async fn get_inner_with_query<T>(
96+
async fn get_inner<T>(
11897
&self,
11998
join: &'static str,
120-
query: PaginationParams<T::Key>,
99+
query: Option<PaginationParams<T::Key>>,
121100
) -> Result<T, Error>
122101
where
123102
T: DeserializeOwned + CacheObject,
124103
{
125-
// Append the path to the URL.
126104
let url = self
127105
.url
128106
.join(join)
129107
.inspect_err(|e| warn!(%e, "Failed to join URL. Not querying transaction cache."))?;
130108

131-
let request = self.client.get(url).query(&query.cursor().to_query_object());
109+
let request = if let Some(query) = query {
110+
self.client.get(url).query(&query.cursor().to_query_object())
111+
} else {
112+
self.client.get(url)
113+
};
132114

115+
// Get the result.
133116
request
134117
.send()
135118
.await
@@ -169,11 +152,7 @@ impl TxCache {
169152
&self,
170153
query: Option<PaginationParams<TxKey>>,
171154
) -> Result<CacheResponse<TxCacheTransactionsResponse>, Error> {
172-
if let Some(query) = query {
173-
self.get_inner_with_query(TRANSACTIONS, query).await
174-
} else {
175-
self.get_inner(TRANSACTIONS).await
176-
}
155+
self.get_inner(TRANSACTIONS, query).await
177156
}
178157

179158
/// Get signed orders from the URL.
@@ -182,10 +161,6 @@ impl TxCache {
182161
&self,
183162
query: Option<PaginationParams<OrderKey>>,
184163
) -> Result<CacheResponse<TxCacheOrdersResponse>, Error> {
185-
if let Some(query) = query {
186-
self.get_inner_with_query(ORDERS, query).await
187-
} else {
188-
self.get_inner(ORDERS).await
189-
}
164+
self.get_inner(ORDERS, query).await
190165
}
191166
}

crates/tx-cache/src/types.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,10 @@ impl From<TxCacheBundleResponse> for TxCacheBundle {
183183
}
184184
}
185185

186+
impl CacheObject for TxCacheBundleResponse {
187+
type Key = BundleKey;
188+
}
189+
186190
impl TxCacheBundleResponse {
187191
/// Create a new bundle response from a bundle.
188192
pub const fn new(bundle: TxCacheBundle) -> Self {
@@ -275,6 +279,10 @@ impl From<TxCacheSendBundleResponse> for uuid::Uuid {
275279
}
276280
}
277281

282+
impl CacheObject for TxCacheSendBundleResponse {
283+
type Key = BundleKey;
284+
}
285+
278286
/// Response from the transaction cache `transactions` endpoint, containing a list of transactions.
279287
#[derive(Debug, Clone, Serialize, Deserialize)]
280288
pub struct TxCacheTransactionsResponse {
@@ -341,6 +349,10 @@ impl From<TxCacheSendTransactionResponse> for B256 {
341349
}
342350
}
343351

352+
impl CacheObject for TxCacheSendTransactionResponse {
353+
type Key = TxKey;
354+
}
355+
344356
impl TxCacheSendTransactionResponse {
345357
/// Create a new transaction response from a transaction hash.
346358
pub const fn new(tx_hash: B256) -> Self {

0 commit comments

Comments
 (0)