Testing websocket
This commit is contained in:
+29
-8
@@ -1,14 +1,22 @@
|
||||
mod pump_fun;
|
||||
|
||||
use crate::launchpad::pump_fun::PumpFun;
|
||||
use anyhow::Context;
|
||||
use helius::Helius;
|
||||
use futures_util::StreamExt;
|
||||
use rust_decimal::Decimal;
|
||||
use std::{collections::HashMap, sync::Arc};
|
||||
use tokio::sync::{Mutex, mpsc};
|
||||
use tokio_tungstenite::tungstenite::Message;
|
||||
|
||||
pub struct Client(
|
||||
pub Mutex<
|
||||
tokio_tungstenite::WebSocketStream<
|
||||
tokio_tungstenite::MaybeTlsStream<tokio::net::TcpStream>,
|
||||
>,
|
||||
>,
|
||||
);
|
||||
|
||||
pub struct Executor {
|
||||
pub client: Helius,
|
||||
pub client: Arc<Client>,
|
||||
|
||||
pub pump_fun: Mutex<PumpFun>,
|
||||
}
|
||||
@@ -18,7 +26,7 @@ pub struct Executor {
|
||||
pub trait Launchpad: Send + Sync {
|
||||
async fn buy(
|
||||
&mut self,
|
||||
client: &Helius,
|
||||
client: &Client,
|
||||
|
||||
mint: &str,
|
||||
amount: Decimal,
|
||||
@@ -28,7 +36,7 @@ pub trait Launchpad: Send + Sync {
|
||||
|
||||
async fn sell(
|
||||
&mut self,
|
||||
client: &Helius,
|
||||
client: &Client,
|
||||
|
||||
mint: &str,
|
||||
amount: u8,
|
||||
@@ -42,7 +50,13 @@ pub trait Launchpad: Send + Sync {
|
||||
impl Executor {
|
||||
pub async fn new(api_key: &str) -> anyhow::Result<Arc<Self>> {
|
||||
Ok(Arc::new(Self {
|
||||
client: Helius::new_async(api_key, helius::types::Cluster::Devnet).await?,
|
||||
client: Arc::new(Client(Mutex::new(
|
||||
tokio_tungstenite::connect_async(format!(
|
||||
"wss://devnet.helius-rpc.com/?api-key={api_key}"
|
||||
))
|
||||
.await?
|
||||
.0,
|
||||
))),
|
||||
|
||||
pump_fun: Mutex::new(PumpFun::new()),
|
||||
}))
|
||||
@@ -94,9 +108,16 @@ impl Executor {
|
||||
pub async fn listen(self: &Arc<Self>) -> anyhow::Result<mpsc::Receiver<u32>> {
|
||||
let (tx, rx) = mpsc::channel(10);
|
||||
|
||||
let ws = self.client.ws().context("Failed to get WebSocket")?;
|
||||
let client = self.client.clone();
|
||||
|
||||
tokio::spawn(async move {});
|
||||
tokio::spawn(async move {
|
||||
match client.0.lock().await.next().await {
|
||||
Some(Ok(Message::Text(msg))) => {}
|
||||
Some(Ok(msg)) => {}
|
||||
Some(Err(e)) => {}
|
||||
None => {}
|
||||
}
|
||||
});
|
||||
|
||||
Ok(rx)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user