Skip to content

Commit a51168a

Browse files
committed
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
1 parent e34c154 commit a51168a

File tree

2 files changed

+46
-6
lines changed

2 files changed

+46
-6
lines changed

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,11 @@ name = "tx_cache"
8686
path = "examples/tx_cache.rs"
8787
required-features = ["perms"]
8888

89-
# [patch.crates-io]
89+
[patch.crates-io]
9090
# signet-bundle = { path = "../sdk/crates/bundle"}
9191
# signet-constants = { path = "../sdk/crates/constants"}
9292
# signet-evm = { path = "../sdk/crates/evm"}
9393
# signet-extract = { path = "../sdk/crates/extract"}
94-
# signet-tx-cache = { path = "../sdk/crates/tx-cache"}
94+
signet-tx-cache = { path = "../signet-sdk/crates/tx-cache"}
9595
# signet-types = { path = "../sdk/crates/types"}
9696
# signet-zenith = { path = "../sdk/crates/zenith"}

src/perms/tx_cache.rs

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)