mirror of
https://github.com/uqbar-dao/nectar.git
synced 2024-12-20 07:01:40 +03:00
Format Rust code using rustfmt
This commit is contained in:
parent
b7f46ec10e
commit
77b720bc77
@ -1,29 +1,29 @@
|
|||||||
use crate::eth::types::{ ProviderAction, EthRpcAction };
|
use crate::eth::types::{EthRpcAction, ProviderAction};
|
||||||
use crate::http::types::{HttpServerAction, HttpServerRequest, WsMessageType};
|
use crate::http::types::{HttpServerAction, HttpServerRequest, WsMessageType};
|
||||||
use crate::types::*;
|
use crate::types::*;
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use ethers::core::types::Filter;
|
use ethers::core::types::Filter;
|
||||||
use ethers::prelude::Provider;
|
use ethers::prelude::Provider;
|
||||||
use ethers::types::{ValueOrArray, U256, U64};
|
use ethers::types::{ValueOrArray, U256, U64};
|
||||||
use ethers_providers::{Middleware, StreamExt, Ws, Http};
|
use ethers_providers::{Http, Middleware, StreamExt, Ws};
|
||||||
|
use futures::stream::SplitSink;
|
||||||
use futures::SinkExt;
|
use futures::SinkExt;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::future::Future;
|
use std::future::Future;
|
||||||
use std::pin::Pin;
|
use std::pin::Pin;
|
||||||
use tokio_tungstenite::connect_async;
|
|
||||||
use tokio_tungstenite::{MaybeTlsStream, WebSocketStream};
|
|
||||||
use tokio_tungstenite::tungstenite::Message as TungsteniteMessage;
|
|
||||||
use futures::stream::SplitSink;
|
|
||||||
use tokio::net::TcpStream;
|
use tokio::net::TcpStream;
|
||||||
|
use tokio_tungstenite::connect_async;
|
||||||
|
use tokio_tungstenite::tungstenite::Message as TungsteniteMessage;
|
||||||
|
use tokio_tungstenite::{MaybeTlsStream, WebSocketStream};
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
struct Connections {
|
struct Connections {
|
||||||
ws_sender: Option<SplitSink<WebSocketStream<MaybeTlsStream<TcpStream>>, TungsteniteMessage>>,
|
ws_sender: Option<SplitSink<WebSocketStream<MaybeTlsStream<TcpStream>>, TungsteniteMessage>>,
|
||||||
ws_provider: Option<Provider<Ws>>,
|
ws_provider: Option<Provider<Ws>>,
|
||||||
http_provider: Option<Provider<Http>>,
|
http_provider: Option<Provider<Http>>,
|
||||||
uq_provider: Option<NodeId>
|
uq_provider: Option<NodeId>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn provider(
|
pub async fn provider(
|
||||||
@ -67,13 +67,14 @@ pub async fn provider(
|
|||||||
ws_sender: None,
|
ws_sender: None,
|
||||||
ws_provider: None,
|
ws_provider: None,
|
||||||
http_provider: None,
|
http_provider: None,
|
||||||
uq_provider: None
|
uq_provider: None,
|
||||||
};
|
};
|
||||||
|
|
||||||
match Url::parse(&rpc_url).unwrap().scheme() {
|
match Url::parse(&rpc_url).unwrap().scheme() {
|
||||||
"http" | "https" => { unreachable!() }
|
"http" | "https" => {
|
||||||
|
unreachable!()
|
||||||
|
}
|
||||||
"ws" | "wss" => {
|
"ws" | "wss" => {
|
||||||
|
|
||||||
let (_ws_stream, _) = connect_async(&rpc_url).await.expect("failed to connect");
|
let (_ws_stream, _) = connect_async(&rpc_url).await.expect("failed to connect");
|
||||||
let (_ws_sender, mut ws_receiver) = _ws_stream.split();
|
let (_ws_sender, mut ws_receiver) = _ws_stream.split();
|
||||||
|
|
||||||
@ -89,16 +90,17 @@ pub async fn provider(
|
|||||||
} else {
|
} else {
|
||||||
println!("Received a binary message: {:?}", msg.into_data());
|
println!("Received a binary message: {:?}", msg.into_data());
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
println!("Error receiving a message: {:?}", e);
|
println!("Error receiving a message: {:?}", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
_ => { unreachable!() }
|
_ => {
|
||||||
|
unreachable!()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
while let Some(km) = recv_in_client.recv().await {
|
while let Some(km) = recv_in_client.recv().await {
|
||||||
@ -121,8 +123,11 @@ pub async fn provider(
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn handle_request(ipc: &Vec<u8>, payload: Option<Payload>, connections: &mut Connections) -> Result<()> {
|
async fn handle_request(
|
||||||
|
ipc: &Vec<u8>,
|
||||||
|
payload: Option<Payload>,
|
||||||
|
connections: &mut Connections,
|
||||||
|
) -> Result<()> {
|
||||||
println!("request");
|
println!("request");
|
||||||
|
|
||||||
if let Ok(action) = serde_json::from_slice::<HttpServerRequest>(ipc) {
|
if let Ok(action) = serde_json::from_slice::<HttpServerRequest>(ipc) {
|
||||||
@ -130,8 +135,10 @@ async fn handle_request(ipc: &Vec<u8>, payload: Option<Payload>, connections: &m
|
|||||||
HttpServerRequest::WebSocketOpen { path, channel_id } => {
|
HttpServerRequest::WebSocketOpen { path, channel_id } => {
|
||||||
println!("open {:?}, {:?}", path, channel_id);
|
println!("open {:?}, {:?}", path, channel_id);
|
||||||
}
|
}
|
||||||
HttpServerRequest::WebSocketPush{channel_id, message_type} => {
|
HttpServerRequest::WebSocketPush {
|
||||||
match message_type {
|
channel_id,
|
||||||
|
message_type,
|
||||||
|
} => match message_type {
|
||||||
WsMessageType::Text => {
|
WsMessageType::Text => {
|
||||||
println!("text");
|
println!("text");
|
||||||
|
|
||||||
@ -140,27 +147,28 @@ async fn handle_request(ipc: &Vec<u8>, payload: Option<Payload>, connections: &m
|
|||||||
|
|
||||||
println!("{:?}", text);
|
println!("{:?}", text);
|
||||||
|
|
||||||
connections.ws_sender.as_mut().unwrap()
|
connections
|
||||||
|
.ws_sender
|
||||||
|
.as_mut()
|
||||||
|
.unwrap()
|
||||||
.send(TungsteniteMessage::Text(text.to_string()))
|
.send(TungsteniteMessage::Text(text.to_string()))
|
||||||
.await;
|
.await;
|
||||||
|
}
|
||||||
},
|
|
||||||
WsMessageType::Binary => {
|
WsMessageType::Binary => {
|
||||||
println!("binary");
|
println!("binary");
|
||||||
},
|
}
|
||||||
WsMessageType::Ping => {
|
WsMessageType::Ping => {
|
||||||
println!("ping");
|
println!("ping");
|
||||||
},
|
}
|
||||||
WsMessageType::Pong => {
|
WsMessageType::Pong => {
|
||||||
println!("pong");
|
println!("pong");
|
||||||
},
|
}
|
||||||
WsMessageType::Close => {
|
WsMessageType::Close => {
|
||||||
println!("close");
|
println!("close");
|
||||||
|
}
|
||||||
},
|
},
|
||||||
}
|
|
||||||
}
|
|
||||||
HttpServerRequest::WebSocketClose(channel_id) => {}
|
HttpServerRequest::WebSocketClose(channel_id) => {}
|
||||||
HttpServerRequest::Http(_) => todo!()
|
HttpServerRequest::Http(_) => todo!(),
|
||||||
}
|
}
|
||||||
} else if let Ok(action) = serde_json::from_slice::<EthRpcAction>(ipc) {
|
} else if let Ok(action) = serde_json::from_slice::<EthRpcAction>(ipc) {
|
||||||
match action {
|
match action {
|
||||||
@ -176,12 +184,9 @@ async fn handle_request(ipc: &Vec<u8>, payload: Option<Payload>, connections: &m
|
|||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn handle_http () {
|
fn handle_http() {}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
fn handle_response(ipc: &Vec<u8>) -> Result<()> {
|
fn handle_response(ipc: &Vec<u8>) -> Result<()> {
|
||||||
let Ok(message) = serde_json::from_slice::<HttpServerAction>(ipc) else {
|
let Ok(message) = serde_json::from_slice::<HttpServerAction>(ipc) else {
|
||||||
|
Loading…
Reference in New Issue
Block a user