good-notifier 0.1.102

A good notifier for telegram and slack, and creating json logs
Documentation
use serde::Serialize;
use std::{fs, io, path::PathBuf};

// TODO: create a handle tx for deployments or just Option<DeployedContractAddr>

pub struct Info {
    /// path for a `/info` folder
    info_path: PathBuf,
}

impl Info {
    pub fn new(info_path: PathBuf) -> Info {
        Info { info_path }
    }

    pub fn write_to_json_file<T: Serialize>(&self, path: String, data: T) -> io::Result<()> {
        let path = self.info_path.join(path);
        let json = serde_json::to_string(&data).map_err(|err| {
            io::Error::new(
                io::ErrorKind::Other,
                format!("Failed to serialize data: {}", err),
            )
        })?;

        fs::write(path, json)
    }
}