Răsfoiți Sursa

further simplfied path retrieval

rachel-rose 5 ani în urmă
părinte
comite
1d54c62e2b
3 a modificat fișierele cu 9 adăugiri și 26 ștergeri
  1. 1 1
      src/bin/darkfid.rs
  2. 5 23
      src/rpc/adapter.rs
  3. 3 2
      src/wallet/walletdb.rs

+ 1 - 1
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)",

+ 5 - 23
src/rpc/adapter.rs

@@ -12,55 +12,37 @@ impl RpcAdapter {
         Arc::new(Self {})
     }
 
-    pub async fn get_path(wallet: &str) -> Result<PathBuf> {
-        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<PathBuf> {
         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<u8>) -> 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<u8>) -> 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(())
     }

+ 3 - 2
src/wallet/walletdb.rs

@@ -24,12 +24,13 @@ impl WalletDB {
     //        let privkey = serial::serialize(&secret);
     //        Ok(pubkey, privkey)
     //    }
-    pub async fn path() -> Result<PathBuf> {
-        let path = dirs::home_dir()
+    pub async fn path(wallet: &str) -> Result<PathBuf> {
+        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)
     }