From a51168a07e3b0a28ce2db401dd118d09ee0bef62 Mon Sep 17 00:00:00 2001 From: evalir Date: Fri, 31 Oct 2025 11:29:40 +0100 Subject: [PATCH] feat(tx-cache): update client to fetch bundles with pagination WIP, we need to settle on how the actual pagination types are gonna look still --- Cargo.toml | 4 ++-- src/perms/tx_cache.rs | 48 +++++++++++++++++++++++++++++++++++++++---- 2 files changed, 46 insertions(+), 6 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index bc4db8b..3806c69 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -86,11 +86,11 @@ name = "tx_cache" path = "examples/tx_cache.rs" required-features = ["perms"] -# [patch.crates-io] +[patch.crates-io] # signet-bundle = { path = "../sdk/crates/bundle"} # signet-constants = { path = "../sdk/crates/constants"} # signet-evm = { path = "../sdk/crates/evm"} # signet-extract = { path = "../sdk/crates/extract"} -# signet-tx-cache = { path = "../sdk/crates/tx-cache"} +signet-tx-cache = { path = "../signet-sdk/crates/tx-cache"} # signet-types = { path = "../sdk/crates/types"} # signet-zenith = { path = "../sdk/crates/zenith"} \ No newline at end of file diff --git a/src/perms/tx_cache.rs b/src/perms/tx_cache.rs index b575176..2c34c89 100644 --- a/src/perms/tx_cache.rs +++ b/src/perms/tx_cache.rs @@ -66,12 +66,52 @@ impl BuilderTxCache { .map_err(Into::into) } + async fn get_inner_with_query_and_token( + &self, + join: &'static str, + query: PaginationParams, + ) -> Result + where + T: DeserializeOwned, + { + // Append the path to the URL. + let secret = self.token.secret().await?; + let url = self + .url + .join(join) + .inspect_err(|e| warn!(%e, "Failed to join URL. Not querying transaction cache."))?; + + let mut request = self.client.get(url); + + if let Some(cursor) = query.cursor() { + request = request.query(&[("cursor", cursor)]); + } + if let Some(limit) = query.limit() { + request = request.query(&[("limit", limit)]); + } + + request + .bearer_auth(secret) + .send() + .await + .inspect_err(|e| warn!(%e, "Failed to get object from transaction cache."))? + .json::() + .await + .map_err(Into::into) + } + /// Get bundles from the cache. #[instrument(skip_all)] - pub async fn get_bundles(&self) -> Result> { - self.get_inner_with_token::(BUNDLES) - .await - .map(|response| response.bundles) + pub async fn get_bundles(&self, query: Option) -> Result> { + if let Some(query) = query { + self.get_inner_with_query_and_token::(BUNDLES, query) + .await + .map(|response| response.bundles) + } else { + self.get_inner_with_token::(BUNDLES) + .await + .map(|response| response.bundles) + } } fn get_bundle_url_path(&self, bundle_id: &str) -> String {