Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
48 changes: 44 additions & 4 deletions src/perms/tx_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,52 @@ impl BuilderTxCache {
.map_err(Into::into)
}

async fn get_inner_with_query_and_token<T>(
&self,
join: &'static str,
query: PaginationParams,
) -> Result<T, Error>
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::<T>()
.await
.map_err(Into::into)
}

/// Get bundles from the cache.
#[instrument(skip_all)]
pub async fn get_bundles(&self) -> Result<Vec<TxCacheBundle>> {
self.get_inner_with_token::<TxCacheBundlesResponse>(BUNDLES)
.await
.map(|response| response.bundles)
pub async fn get_bundles(&self, query: Option<PaginationParams>) -> Result<Vec<TxCacheBundle>> {
if let Some(query) = query {
self.get_inner_with_query_and_token::<TxCacheBundlesResponse>(BUNDLES, query)
.await
.map(|response| response.bundles)
} else {
self.get_inner_with_token::<TxCacheBundlesResponse>(BUNDLES)
.await
.map(|response| response.bundles)
}
}

fn get_bundle_url_path(&self, bundle_id: &str) -> String {
Expand Down
Loading