mirror of
https://github.com/uqbar-dao/nectar.git
synced 2024-12-24 09:06:10 +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::http::types::{ HttpServerAction, HttpServerRequest, WsMessageType };
|
||||
use crate::eth::types::{EthRpcAction, ProviderAction};
|
||||
use crate::http::types::{HttpServerAction, HttpServerRequest, WsMessageType};
|
||||
use crate::types::*;
|
||||
use anyhow::Result;
|
||||
use ethers::core::types::Filter;
|
||||
use ethers::prelude::Provider;
|
||||
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 serde::{Deserialize, Serialize};
|
||||
use serde_json::json;
|
||||
use std::collections::HashMap;
|
||||
use std::future::Future;
|
||||
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_tungstenite::connect_async;
|
||||
use tokio_tungstenite::tungstenite::Message as TungsteniteMessage;
|
||||
use tokio_tungstenite::{MaybeTlsStream, WebSocketStream};
|
||||
use url::Url;
|
||||
|
||||
struct Connections {
|
||||
ws_sender: Option<SplitSink<WebSocketStream<MaybeTlsStream<TcpStream>>,TungsteniteMessage>>,
|
||||
ws_sender: Option<SplitSink<WebSocketStream<MaybeTlsStream<TcpStream>>, TungsteniteMessage>>,
|
||||
ws_provider: Option<Provider<Ws>>,
|
||||
http_provider: Option<Provider<Http>>,
|
||||
uq_provider: Option<NodeId>
|
||||
uq_provider: Option<NodeId>,
|
||||
}
|
||||
|
||||
pub async fn provider(
|
||||
@ -67,13 +67,14 @@ pub async fn provider(
|
||||
ws_sender: None,
|
||||
ws_provider: None,
|
||||
http_provider: None,
|
||||
uq_provider: None
|
||||
uq_provider: None,
|
||||
};
|
||||
|
||||
match Url::parse(&rpc_url).unwrap().scheme() {
|
||||
"http" | "https" => { unreachable!() }
|
||||
"http" | "https" => {
|
||||
unreachable!()
|
||||
}
|
||||
"ws" | "wss" => {
|
||||
|
||||
let (_ws_stream, _) = connect_async(&rpc_url).await.expect("failed to connect");
|
||||
let (_ws_sender, mut ws_receiver) = _ws_stream.split();
|
||||
|
||||
@ -89,16 +90,17 @@ pub async fn provider(
|
||||
} else {
|
||||
println!("Received a binary message: {:?}", msg.into_data());
|
||||
}
|
||||
},
|
||||
}
|
||||
Err(e) => {
|
||||
println!("Error receiving a message: {:?}", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
_ => { unreachable!() }
|
||||
_ => {
|
||||
unreachable!()
|
||||
}
|
||||
}
|
||||
|
||||
while let Some(km) = recv_in_client.recv().await {
|
||||
@ -121,67 +123,70 @@ pub async fn provider(
|
||||
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");
|
||||
|
||||
if let Ok(action) = serde_json::from_slice::<HttpServerRequest>(ipc) {
|
||||
match action {
|
||||
HttpServerRequest::WebSocketOpen{path, channel_id} => {
|
||||
HttpServerRequest::WebSocketOpen { path, channel_id } => {
|
||||
println!("open {:?}, {:?}", path, channel_id);
|
||||
}
|
||||
HttpServerRequest::WebSocketPush{channel_id, message_type} => {
|
||||
match message_type {
|
||||
WsMessageType::Text => {
|
||||
println!("text");
|
||||
HttpServerRequest::WebSocketPush {
|
||||
channel_id,
|
||||
message_type,
|
||||
} => match message_type {
|
||||
WsMessageType::Text => {
|
||||
println!("text");
|
||||
|
||||
let bytes = payload.unwrap().bytes;
|
||||
let text = std::str::from_utf8(&bytes).unwrap();
|
||||
let bytes = payload.unwrap().bytes;
|
||||
let text = std::str::from_utf8(&bytes).unwrap();
|
||||
|
||||
println!("{:?}", text);
|
||||
println!("{:?}", text);
|
||||
|
||||
connections.ws_sender.as_mut().unwrap()
|
||||
.send(TungsteniteMessage::Text(text.to_string()))
|
||||
.await;
|
||||
|
||||
},
|
||||
WsMessageType::Binary => {
|
||||
println!("binary");
|
||||
},
|
||||
WsMessageType::Ping => {
|
||||
println!("ping");
|
||||
},
|
||||
WsMessageType::Pong => {
|
||||
println!("pong");
|
||||
},
|
||||
WsMessageType::Close => {
|
||||
println!("close");
|
||||
},
|
||||
connections
|
||||
.ws_sender
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.send(TungsteniteMessage::Text(text.to_string()))
|
||||
.await;
|
||||
}
|
||||
}
|
||||
HttpServerRequest::WebSocketClose(channel_id) => { }
|
||||
HttpServerRequest::Http(_) => todo!()
|
||||
WsMessageType::Binary => {
|
||||
println!("binary");
|
||||
}
|
||||
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) {
|
||||
match action {
|
||||
EthRpcAction::JsonRpcRequest(_) => unreachable!(),
|
||||
EthRpcAction::Eth(method) => { }
|
||||
EthRpcAction::Debug(method) => { }
|
||||
EthRpcAction::Net(method) => { }
|
||||
EthRpcAction::Trace(method) => { }
|
||||
EthRpcAction::TxPool(method) => { }
|
||||
EthRpcAction::Eth(method) => {}
|
||||
EthRpcAction::Debug(method) => {}
|
||||
EthRpcAction::Net(method) => {}
|
||||
EthRpcAction::Trace(method) => {}
|
||||
EthRpcAction::TxPool(method) => {}
|
||||
}
|
||||
} else {
|
||||
println!("unknown request");
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
||||
}
|
||||
|
||||
fn handle_http () {
|
||||
|
||||
}
|
||||
fn handle_http() {}
|
||||
|
||||
fn handle_response(ipc: &Vec<u8>) -> Result<()> {
|
||||
let Ok(message) = serde_json::from_slice::<HttpServerAction>(ipc) else {
|
||||
|
Loading…
Reference in New Issue
Block a user