Skip to content

Commit

Permalink
fix: apply suggestions from
Browse files Browse the repository at this point in the history
  • Loading branch information
oleonardolima committed Jun 2, 2022
1 parent d23a6ad commit e96ea41
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/bin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,14 @@ fn build_request_data(cli: &Cli) -> MempoolSpaceWebSocketRequestData {
match &cli.command {
Commands::AddressTracking { address } => {
return MempoolSpaceWebSocketRequestData::TrackAddress(
Address::from_str(&address.as_str()).unwrap(),
Address::from_str(address.as_str()).unwrap(),
);
}
Commands::DataStream { blocks, .. } => {
if *blocks {
return MempoolSpaceWebSocketRequestData::Blocks;
}
return MempoolSpaceWebSocketRequestData::MempoolBlocks;
MempoolSpaceWebSocketRequestData::MempoolBlocks
}
}
}
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ pub async fn fetch_data_stream(

match data {
MempoolSpaceWebSocketRequestData::Blocks => {
let message = build_websocket_request_message(&data);
subscribe_to_new_blocks(&network, &message).await
let message = build_websocket_request_message(data);
subscribe_to_new_blocks(network, &message).await
}
MempoolSpaceWebSocketRequestData::MempoolBlocks => {
return Err(anyhow!(
Expand Down
5 changes: 2 additions & 3 deletions src/mempool_space/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
pub mod api;
pub mod websocket;

use anyhow;
use api::{BlockEvent, MempoolSpaceWebSocketRequestData, MempoolSpaceWebSocketRequestMessage};
use bitcoin::Network;
use futures_core::Stream;
Expand All @@ -11,8 +10,8 @@ pub async fn subscribe_to_new_blocks(
network: &Network,
message: &MempoolSpaceWebSocketRequestMessage,
) -> anyhow::Result<impl Stream<Item = BlockEvent>> {
let url: Url = url::Url::parse(&build_websocket_address(&network)).unwrap();
websocket::connect_and_publish_message(url, &message).await
let url: Url = url::Url::parse(&build_websocket_address(network)).unwrap();
websocket::connect_and_publish_message(url, message).await
}

pub fn build_websocket_request_message(
Expand Down
4 changes: 2 additions & 2 deletions src/mempool_space/websocket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub async fn connect_and_publish_message(
let (mut websocket_stream, websocket_response) =
connect_async_tls_with_config(&url, None, None)
.await
.expect(&format!("failed to connect with url: {}", &url));
.unwrap_or_else(|_| panic!("failed to connect with url: {}", &url));

log::info!("websocket handshake successfully completed!");
log::info!(
Expand All @@ -25,7 +25,7 @@ pub async fn connect_and_publish_message(
);

let item = serde_json::to_string(&message).unwrap();
if let Err(_) = websocket_stream.send(Message::text(&item)).await {
if (websocket_stream.send(Message::text(&item)).await).is_err() {
log::error!("failed to publish first message to websocket");
return Err(anyhow!("failed to publish first message to websocket"));
};
Expand Down

0 comments on commit e96ea41

Please sign in to comment.