Skip to content

Commit e41792e

Browse files
Evalirclaude
andauthored
feat(perms): add SSE subscribe_bundles to BuilderTxCache (#131)
* feat(perms): add SSE subscribe_bundles to BuilderTxCache Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * chore: bump version to 0.18.0 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 6412c52 commit e41792e

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

Cargo.toml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name = "init4-bin-base"
33

44
description = "Internal utilities for binaries produced by the init4 team"
55
keywords = ["init4", "bin", "base"]
6-
version = "0.18.0-rc.13"
6+
version = "0.18.0"
77
edition = "2021"
88
rust-version = "1.85"
99
authors = ["init4", "James Prestwich", "evalir"]
@@ -15,8 +15,8 @@ repository = "https://github.com/init4tech/bin-base"
1515
init4-from-env-derive = { version = "0.2.0", path = "from-env-derive" }
1616

1717
# Signet
18-
signet-constants = { version = "0.16.0-rc.11" }
19-
signet-tx-cache = { version = "0.16.0-rc.11", optional = true }
18+
signet-constants = { version = "0.16.0" }
19+
signet-tx-cache = { version = "0.16.0", optional = true }
2020

2121
# alloy
2222
alloy = { version = "1.0.35", optional = true, default-features = false, features = ["std", "signer-local", "consensus", "network"] }
@@ -76,6 +76,7 @@ default = ["alloy", "rustls"]
7676
alloy = ["dep:alloy"]
7777
aws = ["alloy", "alloy?/signer-aws", "dep:async-trait", "dep:aws-config", "dep:aws-sdk-kms"]
7878
perms = ["dep:eyre", "dep:oauth2", "dep:tokio", "dep:reqwest", "dep:signet-tx-cache", "dep:futures-util"]
79+
sse = ["perms", "signet-tx-cache/sse"]
7980
pylon = ["perms", "alloy/kzg"]
8081
block_watcher = ["dep:tokio"]
8182
rustls = ["dep:rustls", "rustls/aws-lc-rs"]

src/perms/tx_cache.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ impl From<url::ParseError> for BuilderTxCacheError {
3939
}
4040

4141
const BUNDLES: &str = "bundles";
42+
#[cfg(feature = "sse")]
43+
const BUNDLES_FEED: &str = "bundles/feed";
4244

4345
/// A client for interacting with the transaction cache, a thin wrapper around
4446
/// the [`TxCache`] and [`SharedToken`] that implements the necessary methods
@@ -188,3 +190,24 @@ impl BuilderTxCache {
188190
.map_err(Into::into)
189191
}
190192
}
193+
194+
#[cfg(feature = "sse")]
195+
impl BuilderTxCache {
196+
/// Subscribe to real-time bundle events via SSE.
197+
///
198+
/// Connects to the `/bundles/feed` endpoint with bearer auth and
199+
/// returns a [`Stream`] that yields each [`CachedBundle`] as it
200+
/// arrives. The stream terminates on the first error, which is
201+
/// yielded as the final item.
202+
#[instrument(skip_all)]
203+
pub async fn subscribe_bundles(
204+
&self,
205+
) -> Result<impl Stream<Item = Result<CachedBundle>> + Send> {
206+
let secret = self.token.secret().await?;
207+
let stream = self
208+
.tx_cache
209+
.subscribe_inner::<CachedBundle>(BUNDLES_FEED, Some(&secret))
210+
.await?;
211+
Ok(stream.map(|r| r.map_err(Into::into)))
212+
}
213+
}

0 commit comments

Comments
 (0)