From 1d54c62e2b20dc6306427872cb3699e2e601ff4f Mon Sep 17 00:00:00 2001 From: rachel-rose Date: Mon, 7 Jun 2021 11:51:21 +0200 Subject: [PATCH] further simplfied path retrieval --- src/bin/darkfid.rs | 2 +- src/rpc/adapter.rs | 28 +++++----------------------- src/wallet/walletdb.rs | 5 +++-- 3 files changed, 9 insertions(+), 26 deletions(-) diff --git a/src/bin/darkfid.rs b/src/bin/darkfid.rs index 9a144f6c6..e0ef48172 100644 --- a/src/bin/darkfid.rs +++ b/src/bin/darkfid.rs @@ -49,7 +49,7 @@ impl ProgramState for State { fn is_valid_cashier_public_key(&self, _public: &jubjub::SubgroupPoint) -> bool { // TODO // Still needs to be tested - //let path = WalletDB::wallet_path(); + let path = WalletDB::path("cashier.db"); //let connect = Connection::open(&path).expect("Failed to connect to database."); //connect.execute( // " SELECT key_public FROM cashier WHERE key_public IN (SELECT key_public)", diff --git a/src/rpc/adapter.rs b/src/rpc/adapter.rs index 0811d8cf3..792e68ae1 100644 --- a/src/rpc/adapter.rs +++ b/src/rpc/adapter.rs @@ -12,55 +12,37 @@ impl RpcAdapter { Arc::new(Self {}) } - pub async fn get_path(wallet: &str) -> Result { - debug!(target: "adapter", "TEST PATH [START]"); - let mut path = WalletDB::path().await.expect("Failed to get path"); - debug!(target: "adapter", "TEST PATH {:?}", path); - path.push(wallet); - Ok(path) - } - pub async fn key_gen() -> Result { debug!(target: "adapter", "key_gen() [START]"); - let path = Self::get_path("wallet.db") - .await - .expect("Failed to get path"); + let path = WalletDB::path("wallet.db").await.expect("Failed to get path"); //WalletDB::key_gen(path).await?; Ok(path) } pub async fn new_wallet() -> Result<()> { debug!(target: "adapter", "new_wallet() [START]"); - let path = Self::get_path("wallet.db") - .await - .expect("Failed to get path"); + let path = WalletDB::path("wallet.db").await.expect("Failed to get path"); WalletDB::new(path).await?; Ok(()) } pub async fn new_cashier_wallet() -> Result<()> { debug!(target: "adapter", "new_cashier_wallet() [START]"); - let path = Self::get_path("cashier.db") - .await - .expect("Failed to get path"); + let path = WalletDB::path("cashier.db").await.expect("Failed to get path"); WalletDB::new(path).await?; Ok(()) } pub async fn save_cash_key(pubkey: Vec) -> Result<()> { debug!(target: "adapter", "save_cash_key() [START]"); - let path = Self::get_path("cashier.db") - .await - .expect("Failed to get path"); + let path = WalletDB::path("cashier.db").await.expect("Failed to get path"); WalletDB::save(path, pubkey).await?; Ok(()) } pub async fn save_key(pubkey: Vec) -> Result<()> { debug!(target: "adapter", "save_key() [START]"); - let path = Self::get_path("wallet.db") - .await - .expect("Failed to get path"); + let path = WalletDB::path("wallet.db").await.expect("Failed to get path"); WalletDB::save(path, pubkey).await?; Ok(()) } diff --git a/src/wallet/walletdb.rs b/src/wallet/walletdb.rs index 367519ad2..d5b56e2a1 100644 --- a/src/wallet/walletdb.rs +++ b/src/wallet/walletdb.rs @@ -24,12 +24,13 @@ impl WalletDB { // let privkey = serial::serialize(&secret); // Ok(pubkey, privkey) // } - pub async fn path() -> Result { - let path = dirs::home_dir() + pub async fn path(wallet: &str) -> Result { + let mut path = dirs::home_dir() .expect("cannot find home directory.") .as_path() .join(".config/darkfi/"); debug!(target: "walletdb", "CREATE PATH {:?}", path); + path.push(wallet); Ok(path) }