Skip to content
Merged
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
4 changes: 2 additions & 2 deletions mm2src/coins/tendermint/tendermint_balance_events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ impl EventBehaviour for TendermintCoin {

let socket_address = format!("{}/{}", http_uri_to_ws_address(node_uri), "websocket");

let mut wsocket = match tokio_tungstenite_wasm::connect(socket_address).await {
let mut wsocket = match tokio_tungstenite_wasm::connect(&socket_address).await {
Ok(ws) => ws,
Err(e) => {
log::error!("{e}");
log::error!("Couldn't connect to '{socket_address}': {e}");
continue;
},
};
Expand Down
14 changes: 12 additions & 2 deletions mm2src/common/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1121,9 +1121,10 @@ pub fn http_uri_to_ws_address(uri: http::Uri) -> String {
};

let host_address = uri.host().expect("Host can't be empty.");
let path = if uri.path() == "/" { "" } else { uri.path() };
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is a trailing slash problematic or just for empty path? Because we don't trim this case: path/to/something/ here, right?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By default uri path is "/" and we don't want that to be included in results. for path/to/something/ having trailing slash is totally fine.

let port = uri.port_u16().map(|p| format!(":{}", p)).unwrap_or_default();

format!("{}{}{}", address_prefix, host_address, port)
format!("{}{}{}{}", address_prefix, host_address, port, path)
}

#[test]
Expand All @@ -1132,13 +1133,22 @@ fn test_http_uri_to_ws_address() {
let ws_connection = http_uri_to_ws_address(uri);
assert_eq!(ws_connection, "wss://cosmos-rpc.polkachu.com");

let uri = "http://cosmos-rpc.polkachu.com".parse::<http::Uri>().unwrap();
let uri = "http://cosmos-rpc.polkachu.com/".parse::<http::Uri>().unwrap();
let ws_connection = http_uri_to_ws_address(uri);
assert_eq!(ws_connection, "ws://cosmos-rpc.polkachu.com");

let uri = "http://34.82.96.8:26657".parse::<http::Uri>().unwrap();
let ws_connection = http_uri_to_ws_address(uri);
assert_eq!(ws_connection, "ws://34.82.96.8:26657");

let uri = "https://cosmos.blockpi.network/rpc/v1/65cc8a9ffe1627352b911dd4b7c751db4a3eaee3"
.parse::<http::Uri>()
.unwrap();
let ws_connection = http_uri_to_ws_address(uri);
assert_eq!(
ws_connection,
"wss://cosmos.blockpi.network/rpc/v1/65cc8a9ffe1627352b911dd4b7c751db4a3eaee3"
);
}

#[test]
Expand Down