Эх сурвалжийг харах

add walletdb path to darkfid config file

ghassmo 5 жил өмнө
parent
commit
94c63b15be

+ 4 - 1
src/bin/darkfid.rs

@@ -147,8 +147,11 @@ async fn start(executor: Arc<Executor<'_>>, config: Arc<&DarkfidConfig>) -> Resu
     let connect_addr: SocketAddr = config.connect_url.parse()?;
     let sub_addr: SocketAddr = config.subscriber_url.parse()?;
     let database_path = config.database_path.clone();
+    let walletdb_path = config.walletdb_path.clone();
 
     let database_path = join_config_path(&PathBuf::from(database_path))?;
+    let walletdb_path = join_config_path(&PathBuf::from(walletdb_path))?;
+
     let rocks = Rocks::new(&database_path)?;
 
     let rocks2 = rocks.clone();
@@ -179,7 +182,7 @@ async fn start(executor: Arc<Executor<'_>>, config: Arc<&DarkfidConfig>) -> Resu
     let merkle_roots = RocksColumn::<columns::MerkleRoots>::new(rocks.clone());
     let nullifiers = RocksColumn::<columns::Nullifiers>::new(rocks);
 
-    let wallet = Arc::new(WalletDb::new("wallet.db", config.password.clone())?);
+    let wallet = Arc::new(WalletDb::new(&walletdb_path, config.password.clone())?);
 
     let ex = executor.clone();
 

+ 14 - 0
src/cli/cli_config.rs

@@ -81,6 +81,10 @@ pub struct DarkfidConfig {
     #[serde(rename = "database_path")]
     pub database_path: String,
 
+    #[serde(default)]
+    #[serde(rename = "walletdb_path")]
+    pub walletdb_path: String,
+
     #[serde(default)]
     #[serde(rename = "log_path")]
     pub log_path: String,
@@ -105,6 +109,15 @@ impl Default for DarkfidConfig {
                 .expect("error convert Path to String"),
         );
 
+        let walletdb_path = String::from("walletdb.db");
+        let walletdb_path = join_config_path(&PathBuf::from(walletdb_path))
+            .expect("error during join walletdb_path to config path");
+        let walletdb_path = String::from(
+            walletdb_path
+                .to_str()
+                .expect("error convert Path to String"),
+        );
+
         let mut lp = PathBuf::new();
         lp.push(env::temp_dir());
         lp.push("darkfid_service_daemon.log");
@@ -117,6 +130,7 @@ impl Default for DarkfidConfig {
             subscriber_url,
             rpc_url,
             database_path,
+            walletdb_path,
             log_path,
             password,
         }

+ 6 - 5
src/wallet/walletdb.rs

@@ -28,9 +28,8 @@ pub struct WalletDb {
 }
 
 impl WalletDb {
-    pub fn new(wallet: &str, password: String) -> Result<Self> {
+    pub fn new(path: &std::path::PathBuf, password: String) -> Result<Self> {
         debug!(target: "walletdb", "new() Constructor called");
-        let path = join_config_path(&PathBuf::from(wallet))?;
         let cashier_secret = jubjub::Fr::random(&mut OsRng);
         let secret = jubjub::Fr::random(&mut OsRng);
         let public = zcash_primitives::constants::SPENDING_KEY_GENERATOR * secret;
@@ -39,7 +38,7 @@ impl WalletDb {
         let notes = Mutex::new(Vec::new());
         let witnesses = Mutex::new(Vec::new());
         Ok(Self {
-            path,
+            path: path.to_owned(),
             cashier_secrets: vec![cashier_secret.clone()],
             secrets: vec![secret.clone()],
             cashier_public,
@@ -330,7 +329,8 @@ mod tests {
 
     #[test]
     pub fn test_save_and_load_keypair() -> Result<()> {
-        let wallet = WalletDb::new("test_wallet.db", "darkfi".into())?;
+        let walletdb_path = join_config_path(&PathBuf::from("test_wallet.db"))?;
+        let wallet = WalletDb::new(&walletdb_path, "darkfi".into())?;
         wallet.init_db()?;
 
         let secret: jubjub::Fr = jubjub::Fr::random(&mut OsRng);
@@ -353,7 +353,8 @@ mod tests {
 
     #[test]
     pub fn test_put_and_get_own_coins() -> Result<()> {
-        let wallet = WalletDb::new("test_wallet.db", "darkfi".into())?;
+        let walletdb_path = join_config_path(&PathBuf::from("test_wallet.db"))?;
+        let wallet = WalletDb::new(&walletdb_path, "darkfi".into())?;
         wallet.init_db()?;
 
         let secret: jubjub::Fr = jubjub::Fr::random(&mut OsRng);