ソースを参照

cli_config: add load_keypair_to_str() function

ghassmo 4 年 前
コミット
7e3ec8d009
1 ファイル変更11 行追加0 行削除
  1. 11 0
      src/cli/cli_config.rs

+ 11 - 0
src/cli/cli_config.rs

@@ -10,6 +10,17 @@ use std::{
 
 
 use crate::{Error, Result};
 use crate::{Error, Result};
 
 
+pub fn load_keypair_to_str(path: PathBuf) -> Result<String> {
+    if Path::new(&path).exists() {
+        let key = fs::read(&path)?;
+        let str_buff = str::from_utf8(&key)?;
+        Ok(str_buff.to_string())
+    } else {
+        println!("Could not parse keypair path");
+        Err(Error::KeypairPathNotFound)
+    }
+}
+
 #[derive(Clone, Default)]
 #[derive(Clone, Default)]
 pub struct Config<T> {
 pub struct Config<T> {
     config: PhantomData<T>,
     config: PhantomData<T>,