/// Generates new wallet and returns the seed.
Generates new wallet and returns the seed.
Generates new wallet and returns the seed .
pub fn new_wallet(wallet_dir: &str, password: &str) -> Result<String, Box<dyn Error>> {
    let your_recovery_phrase = "Your recovery phrase is:";
    let path = Path::new(&wallet_dir);
    if !Path::exists(path) {
        Command::new("mkdir").arg(wallet_dir).output()?;
        let output = Command::new("grin-wallet")
            .current_dir(wallet_dir)
            .args(&["-p", password, "init", "-h"])
            .output()?;
        let utf8_output = String::from_utf8_lossy(&output.stdout).to_string();
        let lines: Vec<&str> = utf8_output.split("\n").collect();
        let seed_index = lines.iter().position(|&r| r == your_recovery_phrase);
        if let Some(i) = seed_index {
            Ok(lines[i + 2].to_string())
        } else {
            Err(Box::new(CreateWalletError))
        }
    } else {
        Err(Box::new(WalletExistsError))
    }
}
pub fn new_wallet ( wallet_dir : & str , password : & str ) -> Result < String , Box < dyn Error > > { let your_recovery_phrase = " " ; let path = Path :: new ( & wallet_dir ) ; if ! Path :: exists ( path ) { Command :: new ( " " ) . arg ( wallet_dir ) . output ( ) ? ; let output = Command :: new ( " " ) . current_dir ( wallet_dir ) . args ( & [ " " , password , " " , " " ] ) . output ( ) ? ; let utf8_output = String :: from_utf8_lossy ( & output . stdout ) . to_string ( ) ; let lines : Vec < & str > = utf8_output . split ( " \n " ) . collect ( ) ; let seed_index = lines . iter ( ) . position ( | & r | r == your_recovery_phrase ) ; if let Some ( i ) = seed_index { Ok ( lines [ i + 2 ] . to_string ( ) ) } else { Err ( Box :: new ( CreateWalletError ) ) } } else { Err ( Box :: new ( WalletExistsError ) ) } }
Generates new wallet and returns the seed.
Generates new wallet and returns the seed .
wallet_dir
&str
password
&str