stackrup 0.1.5

Stackrup into the world of micro-rollups using Stackr CLI
use serde::Deserialize;
use serde::Serialize;
use std::fs;
use std::io;
use std::env;
#[derive(Serialize, Deserialize)]
pub struct Config {
    pub project_name: String,
    pub batch_size: u32,
    pub batch_time: u32,
    pub batcher_slot_time: u32,
    pub operator_accounts: Vec<String>,
    pub aggregator_rpcs: Vec<String>,
}

#[derive(Serialize, Deserialize)]
pub struct StackrConfig {
    stackrAppId: String,
    builder: Builder,
    batcher: Batcher,
    operator: Operator,
}

#[derive(Serialize, Deserialize)]
pub struct Builder {
    batchSize: u32,
    batchTime: u32,
}

#[derive(Serialize, Deserialize)]
pub struct Batcher {
    slotTime: u32,
}

#[derive(Serialize, Deserialize)]
pub struct Operator {
    accounts: Vec<String>
}

pub fn configgenerator(config: &Config, project_name: &str) -> io::Result<()>{

    let current_dir = env::current_dir()?;

    let destination_file_path = current_dir.join(format!("{}/stackr.config.ts",&project_name));

    let accounts: Vec<String> = config.operator_accounts
        .iter()
        .map(|acc| acc.replace('\n', ""))
        .collect();

    let stackrconfig = StackrConfig {
        stackrAppId: "1".to_string(), // Assumed to be a String
        builder: Builder {
            batchSize: config.batch_size,
            batchTime: config.batch_time,
        },
        batcher: Batcher {
            slotTime: config.batcher_slot_time,
        },
        operator:Operator { accounts: accounts}
    };

    let json = serde_json::to_string_pretty(&stackrconfig).expect("Serialization failed");

    // Write the JSON string to a file
    fs::write(&destination_file_path, json).expect("Unable to write to file");

    println!("Configuration set for the project");

    Ok(())
}