mirror of
https://github.com/uqbar-dao/nectar.git
synced 2024-12-19 22:51:51 +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,67 +123,70 @@ 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) {
|
||||||
match action {
|
match action {
|
||||||
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,
|
||||||
WsMessageType::Text => {
|
message_type,
|
||||||
println!("text");
|
} => match message_type {
|
||||||
|
WsMessageType::Text => {
|
||||||
|
println!("text");
|
||||||
|
|
||||||
let bytes = payload.unwrap().bytes;
|
let bytes = payload.unwrap().bytes;
|
||||||
let text = std::str::from_utf8(&bytes).unwrap();
|
let text = std::str::from_utf8(&bytes).unwrap();
|
||||||
|
|
||||||
println!("{:?}", text);
|
println!("{:?}", text);
|
||||||
|
|
||||||
connections.ws_sender.as_mut().unwrap()
|
connections
|
||||||
.send(TungsteniteMessage::Text(text.to_string()))
|
.ws_sender
|
||||||
.await;
|
.as_mut()
|
||||||
|
.unwrap()
|
||||||
},
|
.send(TungsteniteMessage::Text(text.to_string()))
|
||||||
WsMessageType::Binary => {
|
.await;
|
||||||
println!("binary");
|
|
||||||
},
|
|
||||||
WsMessageType::Ping => {
|
|
||||||
println!("ping");
|
|
||||||
},
|
|
||||||
WsMessageType::Pong => {
|
|
||||||
println!("pong");
|
|
||||||
},
|
|
||||||
WsMessageType::Close => {
|
|
||||||
println!("close");
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
}
|
WsMessageType::Binary => {
|
||||||
HttpServerRequest::WebSocketClose(channel_id) => { }
|
println!("binary");
|
||||||
HttpServerRequest::Http(_) => todo!()
|
}
|
||||||
|
WsMessageType::Ping => {
|
||||||
|
println!("ping");
|
||||||
|
}
|
||||||
|
WsMessageType::Pong => {
|
||||||
|
println!("pong");
|
||||||
|
}
|
||||||
|
WsMessageType::Close => {
|
||||||
|
println!("close");
|
||||||
|
}
|
||||||
|
},
|
||||||
|
HttpServerRequest::WebSocketClose(channel_id) => {}
|
||||||
|
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 {
|
||||||
EthRpcAction::JsonRpcRequest(_) => unreachable!(),
|
EthRpcAction::JsonRpcRequest(_) => unreachable!(),
|
||||||
EthRpcAction::Eth(method) => { }
|
EthRpcAction::Eth(method) => {}
|
||||||
EthRpcAction::Debug(method) => { }
|
EthRpcAction::Debug(method) => {}
|
||||||
EthRpcAction::Net(method) => { }
|
EthRpcAction::Net(method) => {}
|
||||||
EthRpcAction::Trace(method) => { }
|
EthRpcAction::Trace(method) => {}
|
||||||
EthRpcAction::TxPool(method) => { }
|
EthRpcAction::TxPool(method) => {}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
println!("unknown request");
|
println!("unknown request");
|
||||||
}
|
}
|
||||||
|
|
||||||
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