132 lines
3.7 KiB
Rust
132 lines
3.7 KiB
Rust
// TODO: delete this file after migration0 gets executed
|
|
|
|
use chrono::Utc;
|
|
use dashmap::DashMap;
|
|
use serde::{Deserialize, Serialize};
|
|
use std::collections::{HashMap, HashSet};
|
|
|
|
#[derive(Clone, Default, Serialize, Deserialize, Debug)]
|
|
pub struct AccountData {
|
|
pub balance: u64,
|
|
pub tmp_locked: u64,
|
|
// holds reasons why VMs of this account got kicked
|
|
pub kicked_for: Vec<String>,
|
|
pub last_kick: chrono::DateTime<Utc>,
|
|
// holds accounts that banned this account
|
|
pub banned_by: HashSet<String>,
|
|
}
|
|
|
|
#[derive(Clone, Default, Serialize, Deserialize)]
|
|
pub struct OperatorData {
|
|
pub escrow: u64,
|
|
pub email: String,
|
|
pub banned_users: HashSet<String>,
|
|
pub vm_nodes: HashSet<String>,
|
|
pub app_nodes: HashSet<String>,
|
|
}
|
|
|
|
#[derive(Eq, PartialEq, Clone, Debug, Default, Serialize, Deserialize)]
|
|
pub struct VmNode {
|
|
pub public_key: String,
|
|
pub operator_wallet: String,
|
|
pub country: String,
|
|
pub region: String,
|
|
pub city: String,
|
|
pub ip: String,
|
|
pub avail_mem_mb: u32,
|
|
pub avail_vcpus: u32,
|
|
pub avail_storage_gbs: u32,
|
|
pub avail_ipv4: u32,
|
|
pub avail_ipv6: u32,
|
|
pub avail_ports: u32,
|
|
pub max_ports_per_vm: u32,
|
|
// nanoLP per unit per minute
|
|
pub price: u64,
|
|
// 1st String is user wallet and 2nd String is report message
|
|
pub reports: HashMap<String, String>,
|
|
pub offline_minutes: u64,
|
|
}
|
|
|
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
|
pub struct VmContract {
|
|
pub uuid: String,
|
|
pub hostname: String,
|
|
pub admin_pubkey: String,
|
|
pub node_pubkey: String,
|
|
pub exposed_ports: Vec<u32>,
|
|
pub public_ipv4: String,
|
|
pub public_ipv6: String,
|
|
pub disk_size_gb: u32,
|
|
pub vcpus: u32,
|
|
pub memory_mb: u32,
|
|
pub kernel_sha: String,
|
|
pub dtrfs_sha: String,
|
|
pub created_at: chrono::DateTime<Utc>,
|
|
pub updated_at: chrono::DateTime<Utc>,
|
|
// recommended value is 20000
|
|
/// price per unit per minute
|
|
pub price_per_unit: u64,
|
|
pub locked_nano: u64,
|
|
pub collected_at: chrono::DateTime<Utc>,
|
|
}
|
|
|
|
#[derive(Clone, Debug, Default, Serialize, Deserialize)]
|
|
pub struct AppContract {
|
|
pub uuid: String,
|
|
pub package_url: String,
|
|
pub admin_pubkey: String,
|
|
pub node_pubkey: String,
|
|
pub mapped_ports: Vec<(u16, u16)>,
|
|
pub host_ipv4: String,
|
|
pub disk_size_mb: u32,
|
|
pub vcpus: u32,
|
|
pub memory_mb: u32,
|
|
pub created_at: chrono::DateTime<Utc>,
|
|
pub updated_at: chrono::DateTime<Utc>,
|
|
// price per unit per minute
|
|
// recommended value is 20000
|
|
pub price_per_unit: u64,
|
|
pub locked_nano: u64,
|
|
pub collected_at: chrono::DateTime<Utc>,
|
|
pub hratls_pubkey: String,
|
|
pub public_package_mr_enclave: Option<Vec<u8>>,
|
|
pub app_name: String,
|
|
}
|
|
|
|
#[derive(Eq, Hash, PartialEq, Clone, Debug, Default, Serialize, Deserialize)]
|
|
pub struct AppNode {
|
|
pub node_pubkey: String,
|
|
pub operator_wallet: String,
|
|
pub country: String,
|
|
pub region: String,
|
|
pub city: String,
|
|
pub ip: String,
|
|
pub avail_mem_mb: u32,
|
|
pub avail_vcpus: u32,
|
|
pub avail_storage_mb: u32,
|
|
pub avail_no_of_port: u32,
|
|
pub max_ports_per_app: u32,
|
|
// nanotokens per unit per minute
|
|
pub price: u64,
|
|
pub offline_minutes: u64,
|
|
}
|
|
|
|
#[derive(Default, Serialize, Deserialize)]
|
|
pub struct BrainData {
|
|
pub accounts: DashMap<String, AccountData>,
|
|
pub operators: DashMap<String, OperatorData>,
|
|
pub vm_nodes: Vec<VmNode>,
|
|
pub vm_contracts: Vec<VmContract>,
|
|
|
|
pub app_nodes: Vec<AppNode>,
|
|
pub app_contracts: Vec<AppContract>,
|
|
}
|
|
|
|
impl BrainData {
|
|
pub fn load_from_disk() -> Result<Self, Box<dyn std::error::Error>> {
|
|
let content = std::fs::read_to_string("./saved_data.yaml")?;
|
|
let data: Self = serde_yaml::from_str(&content)?;
|
|
Ok(data)
|
|
}
|
|
}
|