Skip to content

Commit

Permalink
fix: allow insecure connections with subxt (#5479)
Browse files Browse the repository at this point in the history
  • Loading branch information
dandanlen authored Dec 9, 2024
1 parent 86c4e99 commit 4469f9b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
14 changes: 11 additions & 3 deletions engine/src/dot/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ macro_rules! refresh_connection_on_error {
);

let new_client =
OnlineClient::<PolkadotConfig>::from_url(&$self.polkadot_network_ws_url).await?;
OnlineClient::<PolkadotConfig>::from_insecure_url(&$self.polkadot_network_ws_url).await?;
let result = new_client.$namespace().$method($($arg,)*).await.map_err(|e| anyhow!("Failed to query {} Polkadot with error: {e}", stringify!($method)));
let mut online_client_guard = $self.online_client.write().await;
*online_client_guard = new_client;
Expand All @@ -53,8 +53,12 @@ macro_rules! refresh_connection_on_error {

impl DotRpcClient {
pub async fn new(polkadot_network_ws_url: &str, http_client: DotHttpRpcClient) -> Result<Self> {
if subxt::utils::validate_url_is_secure(polkadot_network_ws_url).is_err() {
warn!("Using insecure Polkadot websocket endpoint: {polkadot_network_ws_url}");
}

let online_client = Arc::new(RwLock::new(
OnlineClient::<PolkadotConfig>::from_url(polkadot_network_ws_url).await?,
OnlineClient::<PolkadotConfig>::from_insecure_url(polkadot_network_ws_url).await?,
));
Ok(Self {
online_client,
Expand Down Expand Up @@ -186,7 +190,11 @@ async fn create_online_client(
ws_endpoint: &SecretUrl,
expected_genesis_hash: Option<PolkadotHash>,
) -> Result<OnlineClient<PolkadotConfig>> {
let client = OnlineClient::<PolkadotConfig>::from_url(ws_endpoint).await?;
if subxt::utils::validate_url_is_secure(ws_endpoint.as_ref()).is_err() {
warn!("Using insecure Polkadot websocket endpoint: {ws_endpoint}");
}

let client = OnlineClient::<PolkadotConfig>::from_insecure_url(ws_endpoint).await?;

if let Some(expected_genesis_hash) = expected_genesis_hash {
let genesis_hash = client.genesis_hash();
Expand Down
2 changes: 1 addition & 1 deletion utilities/scale-json-event-logger/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ async fn main() -> anyhow::Result<()> {
// Any remaining arguments are assumed to be path filters.
let filter = PathFilter(std::env::args().skip(3).collect::<Vec<_>>());

let client = subxt::OnlineClient::<SubstrateConfig>::from_url(url).await.unwrap();
let client = subxt::OnlineClient::<SubstrateConfig>::from_insecure_url(url).await.unwrap();

match hash_opt {
HashOption::Latest => {
Expand Down

0 comments on commit 4469f9b

Please sign in to comment.