Skip to content

Commit 9ed235e

Browse files
committed
fix: use Provider instead of URL
1 parent 1ff884f commit 9ed235e

File tree

9 files changed

+48
-29
lines changed

9 files changed

+48
-29
lines changed

blockchain_api/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ edition = "2021"
55
license = "Apache-2.0"
66

77
[dependencies]
8+
alloy-provider = { git = "https://github.com/alloy-rs/alloy.git", rev = "d68a6b7" }
9+
alloy-transport-http = { git = "https://github.com/alloy-rs/alloy.git", rev = "d68a6b7" }
810
relay_rpc = { path = "../relay_rpc", features = ["cacao"] }
911
reqwest = { version = "0.12.2", features = ["json"] }
1012
serde = "1.0"

blockchain_api/src/lib.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
pub use reqwest::Error;
22
use {
3-
relay_rpc::{auth::cacao::signature::get_rpc_url::GetRpcUrl, domain::ProjectId},
3+
alloy_provider::ReqwestProvider,
4+
relay_rpc::{auth::cacao::signature::get_provider::GetProvider, domain::ProjectId},
45
serde::Deserialize,
56
std::{collections::HashSet, convert::Infallible, sync::Arc, time::Duration},
67
tokio::{sync::RwLock, task::JoinHandle},
@@ -98,18 +99,22 @@ fn build_rpc_url(blockchain_api_rpc_endpoint: Url, chain_id: &str, project_id: &
9899
url
99100
}
100101

101-
impl GetRpcUrl for BlockchainApiProvider {
102-
async fn get_rpc_url(&self, chain_id: String) -> Option<Url> {
102+
impl GetProvider for BlockchainApiProvider {
103+
type Provider = ReqwestProvider;
104+
type Transport = alloy_transport_http::Http<reqwest::Client>;
105+
106+
async fn get_provider(&self, chain_id: String) -> Option<Self::Provider> {
103107
self.supported_chains
104108
.read()
105109
.await
106110
.contains(&chain_id)
107111
.then(|| {
108-
build_rpc_url(
112+
let url = build_rpc_url(
109113
self.blockchain_api_rpc_endpoint.clone(),
110114
&chain_id,
111115
self.project_id.as_ref(),
112-
)
116+
);
117+
ReqwestProvider::new_http(url)
113118
})
114119
}
115120
}

relay_client/src/websocket/stream.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ impl ClientStream {
141141

142142
/// Closes the connection.
143143
pub async fn close(&mut self, frame: Option<CloseFrame<'static>>) -> Result<(), ClientError> {
144-
self.close_frame = frame.clone();
144+
self.close_frame.clone_from(&frame);
145145
self.socket
146146
.close(frame)
147147
.await
@@ -220,7 +220,7 @@ impl ClientStream {
220220
}
221221

222222
Message::Close(frame) => {
223-
self.close_frame = frame.clone();
223+
self.close_frame.clone_from(frame);
224224
Some(StreamEvent::ConnectionClosed(frame.clone()))
225225
}
226226

relay_rpc/Cargo.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ license = "Apache-2.0"
77
[features]
88
default = ["cacao"]
99
cacao = [
10+
"dep:erc6492",
11+
"dep:alloy-transport",
1012
"dep:alloy-provider",
1113
"dep:alloy-primitives",
12-
"dep:erc6492",
1314
]
1415

1516
[dependencies]
@@ -36,6 +37,7 @@ once_cell = "1.16"
3637
jsonwebtoken = "8.1"
3738
sha2 = { version = "0.10.6" }
3839
url = "2"
40+
alloy-transport = { git = "https://github.com/alloy-rs/alloy.git", rev = "d68a6b7", optional = true }
3941
alloy-provider = { git = "https://github.com/alloy-rs/alloy.git", rev = "d68a6b7", optional = true }
4042
alloy-primitives = { version = "0.7.0", optional = true }
4143
erc6492 = { git = "https://github.com/WalletConnect/erc6492.git", optional = true }
@@ -44,6 +46,8 @@ strum = { version = "0.26", features = ["strum_macros", "derive"] }
4446
[dev-dependencies]
4547
k256 = "0.13"
4648
tokio = { version = "1.35.1", features = ["test-util", "macros"] }
49+
alloy-transport-http = { git = "https://github.com/alloy-rs/alloy.git", rev = "d68a6b7" }
50+
reqwest = "0.12.4"
4751

4852
[lints.clippy]
4953
indexing_slicing = "deny"

relay_rpc/src/auth/cacao.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use {
22
self::{
33
header::Header,
44
payload::Payload,
5-
signature::{get_rpc_url::GetRpcUrl, Signature},
5+
signature::{get_provider::GetProvider, Signature},
66
},
77
alloy_primitives::AddressError,
88
core::fmt::Debug,
@@ -98,7 +98,7 @@ pub struct Cacao {
9898
impl Cacao {
9999
const ETHEREUM: &'static str = "Ethereum";
100100

101-
pub async fn verify(&self, provider: Option<&impl GetRpcUrl>) -> Result<(), CacaoError> {
101+
pub async fn verify(&self, provider: Option<&impl GetProvider>) -> Result<(), CacaoError> {
102102
self.p.validate()?;
103103
self.h.validate()?;
104104
self.s.verify(self, provider).await
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
use {alloy_provider::Provider, alloy_transport::Transport};
2+
3+
pub trait GetProvider {
4+
type Transport: Transport + Clone;
5+
type Provider: Provider<Self::Transport>;
6+
7+
#[allow(async_fn_in_trait)]
8+
async fn get_provider(&self, chain_id: String) -> Option<Self::Provider>;
9+
}

relay_rpc/src/auth/cacao/signature/get_rpc_url.rs

Lines changed: 0 additions & 6 deletions
This file was deleted.

relay_rpc/src/auth/cacao/signature/mod.rs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
use {
22
self::{
33
eip191::{verify_eip191, EIP191},
4-
get_rpc_url::GetRpcUrl,
4+
get_provider::GetProvider,
55
},
66
super::{Cacao, CacaoError},
77
alloy_primitives::{hex::FromHex, Address, Bytes},
8-
alloy_provider::{network::Ethereum, ReqwestProvider},
98
erc6492::verify_signature,
109
serde::{Deserialize, Serialize},
1110
};
1211

1312
pub mod eip191;
14-
pub mod get_rpc_url;
13+
pub mod get_provider;
1514

1615
#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize, Hash)]
1716
pub struct Signature {
@@ -26,7 +25,7 @@ impl Signature {
2625
pub async fn verify(
2726
&self,
2827
cacao: &Cacao,
29-
provider: Option<&impl GetRpcUrl>,
28+
provider: Option<&impl GetProvider>,
3029
) -> Result<(), CacaoError> {
3130
let chain_id = cacao.p.chain_id_reference()?;
3231
let address = cacao.p.address()?;
@@ -43,12 +42,10 @@ impl Signature {
4342
}
4443
EIP1271 | EIP6492 => {
4544
if let Some(provider) = provider {
46-
let provider = ReqwestProvider::<Ethereum>::new_http(
47-
provider
48-
.get_rpc_url(chain_id)
49-
.await
50-
.ok_or(CacaoError::ProviderNotAvailable)?,
51-
);
45+
let provider = provider
46+
.get_provider(chain_id)
47+
.await
48+
.ok_or(CacaoError::ProviderNotAvailable)?;
5249
let result = verify_signature(signature, address, message, provider)
5350
.await
5451
.map_err(CacaoError::Rpc)?;

relay_rpc/src/auth/cacao/tests.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
1-
use {super::signature::get_rpc_url::GetRpcUrl, crate::auth::cacao::Cacao, url::Url};
1+
use {
2+
super::signature::get_provider::GetProvider,
3+
crate::auth::cacao::Cacao,
4+
alloy_provider::ReqwestProvider,
5+
};
26

37
struct MockGetRpcUrl;
48

5-
impl GetRpcUrl for MockGetRpcUrl {
6-
async fn get_rpc_url(&self, _: String) -> Option<Url> {
9+
// https://github.com/alloy-rs/alloy/issues/568
10+
impl GetProvider for MockGetRpcUrl {
11+
type Provider = ReqwestProvider;
12+
type Transport = alloy_transport_http::Http<reqwest::Client>;
13+
14+
async fn get_provider(&self, _: String) -> Option<Self::Provider> {
715
None
816
}
917
}

0 commit comments

Comments
 (0)