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
5 changes: 1 addition & 4 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,7 @@ jobs:
profile: default
override: true

- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1

- uses: Swatinem/rust-cache@v2
# - uses: Swatinem/rust-cache@v2

- uses: taiki-e/install-action@v1
with:
Expand Down
3 changes: 3 additions & 0 deletions blockchain_api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ edition = "2021"
license = "Apache-2.0"

[dependencies]
alloy-provider = { git = "https://github.com/alloy-rs/alloy.git", rev = "d68a6b7" }
alloy-transport-http = { git = "https://github.com/alloy-rs/alloy.git", rev = "d68a6b7" }
alloy-rpc-client = { git = "https://github.com/alloy-rs/alloy.git", rev = "d68a6b7" }
relay_rpc = { path = "../relay_rpc", features = ["cacao"] }
reqwest = { version = "0.12.2", features = ["json"] }
serde = "1.0"
Expand Down
59 changes: 44 additions & 15 deletions blockchain_api/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
pub use reqwest::Error;
use {
relay_rpc::{auth::cacao::signature::get_rpc_url::GetRpcUrl, domain::ProjectId},
alloy_provider::ReqwestProvider,
alloy_rpc_client::RpcClient,
alloy_transport_http::Http,
relay_rpc::{auth::cacao::signature::get_provider::GetProvider, domain::ProjectId},
serde::Deserialize,
std::{collections::HashSet, convert::Infallible, sync::Arc, time::Duration},
std::{
collections::{HashMap, HashSet},
convert::Infallible,
sync::Arc,
time::Duration,
},
tokio::{sync::RwLock, task::JoinHandle},
tracing::error,
url::Url,
Expand All @@ -26,6 +34,8 @@ pub struct BlockchainApiProvider {
blockchain_api_rpc_endpoint: Url,
supported_chains: Arc<RwLock<HashSet<String>>>,
refresh_job: Arc<JoinHandle<Infallible>>,
http_client: reqwest::Client,
provider_cache: Arc<RwLock<HashMap<String, ReqwestProvider>>>,
}

impl Drop for BlockchainApiProvider {
Expand Down Expand Up @@ -86,6 +96,8 @@ impl BlockchainApiProvider {
blockchain_api_rpc_endpoint,
supported_chains,
refresh_job: Arc::new(refresh_job),
http_client: reqwest::Client::new(),
provider_cache: Arc::new(RwLock::new(HashMap::new())),
})
}
}
Expand All @@ -98,19 +110,36 @@ fn build_rpc_url(blockchain_api_rpc_endpoint: Url, chain_id: &str, project_id: &
url
}

impl GetRpcUrl for BlockchainApiProvider {
async fn get_rpc_url(&self, chain_id: String) -> Option<Url> {
self.supported_chains
.read()
.await
.contains(&chain_id)
.then(|| {
build_rpc_url(
self.blockchain_api_rpc_endpoint.clone(),
&chain_id,
self.project_id.as_ref(),
)
})
impl GetProvider for BlockchainApiProvider {
type Provider = ReqwestProvider;
type Transport = alloy_transport_http::Http<reqwest::Client>;

async fn get_provider(&self, chain_id: String) -> Option<Self::Provider> {
if self.supported_chains.read().await.contains(&chain_id) {
Some(
if let Some(provider) = self.provider_cache.read().await.get(&chain_id) {
provider.clone()
} else {
let url = build_rpc_url(
self.blockchain_api_rpc_endpoint.clone(),
&chain_id,
self.project_id.as_ref(),
);
let provider = ReqwestProvider::new({
let http = Http::with_client(self.http_client.clone(), url);
let is_local = http.guess_local();
RpcClient::new(http, is_local)
});
self.provider_cache
.write()
.await
.insert(chain_id.clone(), provider.clone());
provider
},
)
} else {
None
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions relay_client/src/websocket/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ impl ClientStream {

/// Closes the connection.
pub async fn close(&mut self, frame: Option<CloseFrame<'static>>) -> Result<(), ClientError> {
self.close_frame = frame.clone();
self.close_frame.clone_from(&frame);
self.socket
.close(frame)
.await
Expand Down Expand Up @@ -220,7 +220,7 @@ impl ClientStream {
}

Message::Close(frame) => {
self.close_frame = frame.clone();
self.close_frame.clone_from(frame);
Some(StreamEvent::ConnectionClosed(frame.clone()))
}

Expand Down
27 changes: 5 additions & 22 deletions relay_rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,10 @@ license = "Apache-2.0"

[features]
cacao = [
"dep:k256",
"dep:sha3",
"dep:erc6492",
"dep:alloy-provider",
"dep:alloy-transport",
"dep:alloy-transport-http",
"dep:alloy-rpc-types",
"dep:alloy-json-rpc",
"dep:alloy-json-abi",
"dep:alloy-sol-types",
"dep:alloy-primitives",
"dep:alloy-node-bindings",
"dep:alloy-contract"
]

[dependencies]
Expand All @@ -42,28 +34,19 @@ chrono = { version = "0.4", default-features = false, features = [
regex = "1.7"
once_cell = "1.16"
jsonwebtoken = "8.1"
k256 = { version = "0.13", optional = true }
sha3 = { version = "0.10", optional = true }
sha2 = { version = "0.10.6" }
url = "2"
alloy-provider = { git = "https://github.com/alloy-rs/alloy.git", rev = "d68a6b7", optional = true }
alloy-transport = { git = "https://github.com/alloy-rs/alloy.git", rev = "d68a6b7", optional = true }
alloy-transport-http = { git = "https://github.com/alloy-rs/alloy.git", rev = "d68a6b7", optional = true }
alloy-rpc-types = { git = "https://github.com/alloy-rs/alloy.git", rev = "d68a6b7", optional = true }
alloy-json-rpc = { git = "https://github.com/alloy-rs/alloy.git", rev = "d68a6b7", optional = true }
alloy-node-bindings = { git = "https://github.com/alloy-rs/alloy.git", rev = "d68a6b7", optional = true }
alloy-contract = { git = "https://github.com/alloy-rs/alloy.git", rev = "d68a6b7", optional = true }
alloy-json-abi = { version = "0.7.0", optional = true }
alloy-sol-types = { version = "0.7.0", optional = true }
alloy-primitives = { version = "0.7.0", optional = true }
erc6492 = { git = "https://github.com/WalletConnect/erc6492.git", optional = true }
strum = { version = "0.26", features = ["strum_macros", "derive"] }

[dev-dependencies]
k256 = "0.13"
tokio = { version = "1.35.1", features = ["test-util", "macros"] }

[build-dependencies]
serde_json = "1.0"
hex = "0.4.3"
alloy-transport-http = { git = "https://github.com/alloy-rs/alloy.git", rev = "d68a6b7" }
reqwest = "0.12.4"

[lints.clippy]
indexing_slicing = "deny"
98 changes: 0 additions & 98 deletions relay_rpc/build.rs

This file was deleted.

49 changes: 0 additions & 49 deletions relay_rpc/contracts/Create2.sol

This file was deleted.

Loading