Added accounts
This commit is contained in:
@@ -2,7 +2,7 @@ use std::sync::Arc;
|
|||||||
|
|
||||||
use tokio::{sync::Mutex, task::JoinHandle};
|
use tokio::{sync::Mutex, task::JoinHandle};
|
||||||
|
|
||||||
use crate::{config::Config, terminal::TerminalServer};
|
use crate::{store::config::Config, terminal::TerminalServer};
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct Engine {
|
pub struct Engine {
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
pub mod config;
|
|
||||||
pub mod engine;
|
pub mod engine;
|
||||||
pub mod fetch;
|
pub mod fetch;
|
||||||
|
pub mod store;
|
||||||
pub mod terminal;
|
pub mod terminal;
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
|
|||||||
@@ -0,0 +1,41 @@
|
|||||||
|
use std::collections::HashMap;
|
||||||
|
|
||||||
|
use hypersdk::U160;
|
||||||
|
|
||||||
|
#[derive(Debug, serde::Serialize, serde::Deserialize)]
|
||||||
|
pub struct Account {
|
||||||
|
pub address: U160,
|
||||||
|
pub private_key: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Default, serde::Serialize, serde::Deserialize)]
|
||||||
|
pub struct AccountList(pub HashMap<String, Account>);
|
||||||
|
|
||||||
|
impl AccountList {
|
||||||
|
pub async fn new() -> tokio::io::Result<Self> {
|
||||||
|
let path = crate::store::pulse_accounts_file()?;
|
||||||
|
|
||||||
|
if !path.exists() {
|
||||||
|
let default = Self::default();
|
||||||
|
|
||||||
|
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 fn from_str(s: &str) -> tokio::io::Result<Self> {
|
||||||
|
toml::from_str(s)
|
||||||
|
.map_err(|v| tokio::io::Error::new(std::io::ErrorKind::InvalidInput, v.to_string()))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn to_string(&self) -> tokio::io::Result<String> {
|
||||||
|
toml::to_string(self)
|
||||||
|
.map_err(|v| tokio::io::Error::new(std::io::ErrorKind::Other, v.to_string()))
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,19 +1,3 @@
|
|||||||
use std::path::PathBuf;
|
|
||||||
|
|
||||||
pub fn home_dir() -> tokio::io::Result<PathBuf> {
|
|
||||||
std::env::home_dir().ok_or_else(|| {
|
|
||||||
tokio::io::Error::new(std::io::ErrorKind::NotFound, "Unable to get home directory")
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn pulse_directory() -> tokio::io::Result<PathBuf> {
|
|
||||||
Ok(home_dir()?.join(".config/pulse-trader"))
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn pulse_config_directory() -> tokio::io::Result<PathBuf> {
|
|
||||||
Ok(home_dir()?.join(".config/pulse-trader/config.toml"))
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Default, serde::Serialize, serde::Deserialize)]
|
#[derive(Debug, Default, serde::Serialize, serde::Deserialize)]
|
||||||
pub struct WatchList {
|
pub struct WatchList {
|
||||||
pub symbols: Vec<String>,
|
pub symbols: Vec<String>,
|
||||||
@@ -26,7 +10,7 @@ pub struct Config {
|
|||||||
|
|
||||||
impl Config {
|
impl Config {
|
||||||
pub async fn new() -> tokio::io::Result<Self> {
|
pub async fn new() -> tokio::io::Result<Self> {
|
||||||
let path = pulse_config_directory()?;
|
let path = crate::store::pulse_config_file()?;
|
||||||
|
|
||||||
if !path.exists() {
|
if !path.exists() {
|
||||||
let default = Self::default();
|
let default = Self::default();
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
|
pub mod accounts;
|
||||||
|
pub mod config;
|
||||||
|
|
||||||
|
pub fn home_dir() -> tokio::io::Result<PathBuf> {
|
||||||
|
std::env::home_dir().ok_or_else(|| {
|
||||||
|
tokio::io::Error::new(std::io::ErrorKind::NotFound, "Unable to get home directory")
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn pulse_directory() -> tokio::io::Result<PathBuf> {
|
||||||
|
Ok(home_dir()?.join(".config").join("pulse-trader"))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn pulse_config_file() -> tokio::io::Result<PathBuf> {
|
||||||
|
Ok(pulse_directory()?.join("config.toml"))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn pulse_accounts_file() -> tokio::io::Result<PathBuf> {
|
||||||
|
Ok(pulse_directory()?.join("accounts.toml"))
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user