Skip to content

Commit

Permalink
fix: clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
ngutech21 committed Jul 15, 2024
1 parent bb355ca commit 48ad089
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 30 deletions.
14 changes: 7 additions & 7 deletions moksha-core/src/keyset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

use hex::ToHex;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use std::{collections::HashMap, fmt::Display};
use utoipa::ToSchema;

use bitcoin_hashes::{sha256, Hash};
Expand Down Expand Up @@ -105,9 +105,9 @@ impl KeysetId {
}
}

impl ToString for KeysetId {
fn to_string(&self) -> String {
format!("{}{}", self.0.to_string(), self.1)
impl Display for KeysetId {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(f, "{}{}", self.0, self.1)
}
}

Expand All @@ -125,10 +125,10 @@ impl From<String> for KeysetIdType {
}
}

impl ToString for KeysetIdType {
fn to_string(&self) -> String {
impl Display for KeysetIdType {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match self {
KeysetIdType::V1 => "00".to_string(),
KeysetIdType::V1 => write!(f, "00"),
}
}
}
Expand Down
42 changes: 19 additions & 23 deletions moksha-wallet/src/config_path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,27 @@ pub const ENV_DB_PATH: &str = "WALLET_DB_PATH";
/// println!("Database path: {}", db_path);
/// ```
pub fn db_path() -> String {
std::env::var(ENV_DB_PATH).map_or_else(
|_| {
let home = home_dir()
.expect("home dir not found")
.to_str()
.expect("home dir is invalid")
.to_owned();
// in a sandboxed environment on mac the path looks like
// /Users/$USER_NAME/Library/Containers/..... so we have are just ising the first 2 parts
let home = home
.split('/')
.take(3)
.collect::<Vec<&str>>()
.join(std::path::MAIN_SEPARATOR_STR);
let moksha_dir = format!("{}{}.moksha", home, std::path::MAIN_SEPARATOR);
std::env::var(ENV_DB_PATH).unwrap_or_else(|_| {
let home = home_dir()
.expect("home dir not found")
.to_str()
.expect("home dir is invalid")
.to_owned();
// in a sandboxed environment on mac the path looks like
// /Users/$USER_NAME/Library/Containers/..... so we have are just ising the first 2 parts
let home = home
.split('/')
.take(3)
.collect::<Vec<&str>>()
.join(std::path::MAIN_SEPARATOR_STR);
let moksha_dir = format!("{}{}.moksha", home, std::path::MAIN_SEPARATOR);

if !std::path::Path::new(&moksha_dir).exists() {
create_dir(std::path::Path::new(&moksha_dir))
.expect("failed to create .moksha dir");
}
if !std::path::Path::new(&moksha_dir).exists() {
create_dir(std::path::Path::new(&moksha_dir)).expect("failed to create .moksha dir");
}

format!("{moksha_dir}/wallet.db")
},
|val| val,
)
format!("{moksha_dir}/wallet.db")
})
}

pub fn config_dir() -> PathBuf {
Expand Down

0 comments on commit 48ad089

Please sign in to comment.