Skip to content
Open
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
38 changes: 32 additions & 6 deletions src/perms/tx_cache.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,40 @@
use crate::perms::oauth::SharedToken;
use serde::de::DeserializeOwned;
use signet_tx_cache::{
error::Result,
error::TxCacheError,
types::{BundleKey, CacheObject, TxCacheBundle, TxCacheBundleResponse, TxCacheBundlesResponse},
TxCache,
};
use tracing::{instrument, warn};
use thiserror::Error;
use tokio::sync::watch;
use tracing::instrument;

/// Result type for [`BuilderTxCache`] operations.
pub type Result<T> = std::result::Result<T, BuilderTxCacheError>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
pub type Result<T> = std::result::Result<T, BuilderTxCacheError>;
pub type Result<T> = core::result::Result<T, BuilderTxCacheError>;


/// Errors that can occur when using the [`BuilderTxCache`] client.
#[derive(Debug, Error)]
pub enum BuilderTxCacheError {
/// Failed to retrieve the authentication token.
#[error("failed to retrieve auth token: {0}")]
TokenRetrieval(#[from] watch::error::RecvError),

/// An error occurred during a TxCache operation.
#[error(transparent)]
TxCache(#[from] TxCacheError),
}

impl From<reqwest::Error> for BuilderTxCacheError {
fn from(err: reqwest::Error) -> Self {
BuilderTxCacheError::TxCache(TxCacheError::Reqwest(err))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By not using from, we unconditionally make this a TxCacheError::Reqwest error. Using from means we'll set it to whichever of TxCacheError::NotFound, TxCacheError::NotOurSlot or TxCacheError::Reqwest is appropriate,

Suggested change
BuilderTxCacheError::TxCache(TxCacheError::Reqwest(err))
BuilderTxCacheError::TxCache(TxCacheError::from(err))

}
}

impl From<url::ParseError> for BuilderTxCacheError {
fn from(err: url::ParseError) -> Self {
BuilderTxCacheError::TxCache(TxCacheError::Url(err))
}
}

const BUNDLES: &str = "bundles";

Expand Down Expand Up @@ -77,10 +106,7 @@ impl BuilderTxCache {
T: DeserializeOwned + CacheObject,
{
let url = self.tx_cache.url().join(join)?;
let secret = self.token.secret().await.unwrap_or_else(|_| {
warn!("Failed to get token secret");
"".to_string()
});
let secret = self.token.secret().await?;

self.tx_cache
.client()
Expand Down
10 changes: 8 additions & 2 deletions tests/tx-cache.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#![cfg(feature = "perms")]

use init4_bin_base::perms::{tx_cache::BuilderTxCache, SharedToken};
use init4_bin_base::perms::{
tx_cache::{BuilderTxCache, BuilderTxCacheError},
SharedToken,
};
use signet_tx_cache::TxCacheError;

const URL: &str = "https://transactions.parmigiana.signet.sh";
Expand All @@ -12,5 +15,8 @@ async fn test_tx_cache_get_bundles() {

let bundles = client.get_bundles(None).await.unwrap_err();

assert!(matches!(bundles, TxCacheError::NotOurSlot));
assert!(matches!(
bundles,
BuilderTxCacheError::TxCache(TxCacheError::NotOurSlot)
));
Comment on lines +18 to +21
Copy link
Contributor

@Fraser999 Fraser999 Feb 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this matches the new behaviour, but the test is ignored, so not picked up in CI.

}