Better stuff
This commit is contained in:
+6
-1
@@ -10,7 +10,12 @@ futures-util = "0.3.33"
|
|||||||
serde = { version = "1.0.229", features = ["derive", "serde_derive"] }
|
serde = { version = "1.0.229", features = ["derive", "serde_derive"] }
|
||||||
serde_json = "1.0.151"
|
serde_json = "1.0.151"
|
||||||
|
|
||||||
tokio = { version = "1.53.1", features = ["macros", "rt-multi-thread", "sync"] }
|
tokio = { version = "1.53.1", features = [
|
||||||
|
"macros",
|
||||||
|
"rt-multi-thread",
|
||||||
|
"sync",
|
||||||
|
"fs",
|
||||||
|
] }
|
||||||
tokio-tungstenite = { version = "0.30.0", features = ["native-tls"] }
|
tokio-tungstenite = { version = "0.30.0", features = ["native-tls"] }
|
||||||
log = "0.4.33"
|
log = "0.4.33"
|
||||||
env_logger = "0.11.11"
|
env_logger = "0.11.11"
|
||||||
|
|||||||
@@ -0,0 +1,56 @@
|
|||||||
|
use std::{collections::HashMap, path::PathBuf};
|
||||||
|
|
||||||
|
use crate::executor::pump_fun::PumpDevAccount;
|
||||||
|
use anyhow::{Context, anyhow};
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
pub fn get_accounts_path() -> anyhow::Result<PathBuf> {
|
||||||
|
Ok(std::env::home_dir()
|
||||||
|
.context("Failed to get home dir")?
|
||||||
|
.join(".config")
|
||||||
|
.join("sol-hunter")
|
||||||
|
.join("accounts.json"))
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
|
#[serde(tag = "type")]
|
||||||
|
pub enum Account {
|
||||||
|
PumpDev(PumpDevAccount),
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
|
pub struct AccountManger {
|
||||||
|
pub active: String,
|
||||||
|
pub accounts: HashMap<String, Account>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl AccountManger {
|
||||||
|
pub async fn get() -> anyhow::Result<Self> {
|
||||||
|
let path = get_accounts_path()?;
|
||||||
|
|
||||||
|
if !path.exists() {
|
||||||
|
let default = Self::new().await?;
|
||||||
|
|
||||||
|
tokio::fs::create_dir_all(path.parent().unwrap()).await?;
|
||||||
|
tokio::fs::write(&path, default.to_string()?).await?;
|
||||||
|
|
||||||
|
return Ok(default);
|
||||||
|
}
|
||||||
|
|
||||||
|
let output = tokio::fs::read_to_string(path).await?;
|
||||||
|
|
||||||
|
Self::from_str(&output)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn new() -> anyhow::Result<Self> {
|
||||||
|
Err(anyhow!("Not implemented yet"))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn from_str(s: &str) -> anyhow::Result<Self> {
|
||||||
|
serde_json::from_str(s).context("Failed to parse accounts")
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn to_string(&self) -> anyhow::Result<String> {
|
||||||
|
serde_json::to_string(self).context("Failed to serialize accounts")
|
||||||
|
}
|
||||||
|
}
|
||||||
+12
-7
@@ -1,15 +1,10 @@
|
|||||||
pub mod pump_fun;
|
pub mod pump_fun;
|
||||||
|
|
||||||
use rust_decimal::Decimal;
|
use rust_decimal::Decimal;
|
||||||
use serde::{Deserialize, Serialize};
|
use tokio::sync::Mutex;
|
||||||
|
|
||||||
use crate::executor::pump_fun::PumpDevAccount;
|
use crate::account::Account;
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
||||||
#[serde(tag = "type")]
|
|
||||||
pub enum Account {
|
|
||||||
PumpDev(PumpDevAccount),
|
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(async_fn_in_trait, unused_variables)]
|
#[allow(async_fn_in_trait, unused_variables)]
|
||||||
pub trait Executor {
|
pub trait Executor {
|
||||||
@@ -33,3 +28,13 @@ pub trait Executor {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Account {
|
||||||
|
pub fn executor(self) -> impl Executor {
|
||||||
|
match self {
|
||||||
|
Self::PumpDev(account) => pump_fun::PumpDev {
|
||||||
|
account: Mutex::new(account),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
pub mod account;
|
||||||
pub mod executor;
|
pub mod executor;
|
||||||
pub mod types;
|
pub mod types;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user