Skip to content

Commit 1fa05e9

Browse files
committed
feat: tx cache
1 parent 3c8faca commit 1fa05e9

File tree

4 files changed

+28
-1
lines changed

4 files changed

+28
-1
lines changed

crates/constants/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ alloy.workspace = true
1313
serde.workspace = true
1414
serde_json.workspace = true
1515
thiserror.workspace = true
16-
16+
reqwest.workspace = true
1717

1818
[features]
1919
default = []

crates/constants/src/types/environment.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,9 @@ impl SignetEnvironmentConstants {
4444
pub const fn transaction_cache(&self) -> &str {
4545
self.transaction_cache
4646
}
47+
48+
/// Get the transaction cache URL.
49+
pub fn transaction_cache_url(&self) -> reqwest::Url {
50+
reqwest::Url::parse(self.transaction_cache).expect("Invalid transaction cache URL")
51+
}
4752
}

crates/tx-cache/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ signet-bundle.workspace = true
1515
signet-evm.workspace = true
1616
signet-types.workspace = true
1717
signet-zenith.workspace = true
18+
signet-constants.workspace = true
1819

1920
ajj.workspace = true
2021
trevm.workspace = true

crates/tx-cache/src/client.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use alloy::consensus::TxEnvelope;
66
use eyre::Error;
77
use serde::{de::DeserializeOwned, Serialize};
88
use signet_bundle::SignetEthBundle;
9+
use signet_constants::SignetEnvironmentConstants;
910
use signet_types::SignedOrder;
1011
use tracing::{instrument, warn};
1112

@@ -35,6 +36,19 @@ impl TxCache {
3536
Self { url, client: reqwest::Client::new() }
3637
}
3738

39+
/// Create a new cache for Pecorino.
40+
pub fn pecorino() -> Self {
41+
SignetEnvironmentConstants::pecorino().into()
42+
}
43+
44+
/// Create a new cache for Pecorino and client.
45+
pub fn pecorino_with_client(client: reqwest::Client) -> Self {
46+
Self::new_with_client(
47+
SignetEnvironmentConstants::pecorino().transaction_cache_url(),
48+
client,
49+
)
50+
}
51+
3852
async fn forward_inner<T: Serialize + Send, R: DeserializeOwned>(
3953
&self,
4054
join: &'static str,
@@ -136,3 +150,10 @@ impl TxCache {
136150
Ok(response.orders)
137151
}
138152
}
153+
154+
// implement a From trait for TxCache from SignetEnvironmentConstants
155+
impl From<SignetEnvironmentConstants> for TxCache {
156+
fn from(constants: SignetEnvironmentConstants) -> Self {
157+
Self::new(constants.transaction_cache_url())
158+
}
159+
}

0 commit comments

Comments
 (0)