Răsfoiți Sursa

cashierd: add refresh option

ghassmo 4 ani în urmă
părinte
comite
61fea1802d
3 a modificat fișierele cu 63 adăugiri și 1 ștergeri
  1. 28 0
      src/bin/cashierd.rs
  2. 1 1
      src/bin/darkfid.rs
  3. 34 0
      src/wallet/cashierdb.rs

+ 28 - 0
src/bin/cashierd.rs

@@ -713,6 +713,7 @@ async fn main() -> Result<()> {
         (@arg CONFIG: -c --config +takes_value "Sets a custom config file")
         (@arg ADDRESS: -a --address "Get Cashier Public key")
         (@arg verbose: -v --verbose "Increase verbosity")
+        (@arg refresh: -r --refresh "Refresh the wallet and slabstore")
     )
     .get_matches();
 
@@ -732,6 +733,33 @@ async fn main() -> Result<()> {
 
     let config: CashierdConfig = Config::<CashierdConfig>::load(config_path)?;
 
+    if args.is_present("refresh") {
+        debug!(target: "CASHIER DAEMON", "Refresh the wallet and the database");
+
+        let client_wallet = WalletDb::new(
+            expand_path(&config.client_wallet_path)?.as_path(),
+            config.client_wallet_password.clone(),
+        )?;
+
+        client_wallet.remove_own_coins()?;
+
+        let wallet = CashierDb::new(
+            expand_path(&config.cashier_wallet_path)?.as_path(),
+            config.cashier_wallet_password.clone(),
+        )?;
+
+        wallet.remove_withdraw_and_deposit_keys()?;
+
+        if let Some(path) = expand_path(&config.database_path)?.to_str() {
+            debug!(target: "CASHIER DAEMON", "Remove database: {}", path);
+            std::fs::remove_dir_all(path)?;
+        }
+
+        println!("Wallet got updated successfully.");
+
+        return Ok(());
+    }
+
     let ex = Arc::new(Executor::new());
     let (signal, shutdown) = async_channel::unbounded::<()>();
 

+ 1 - 1
src/bin/darkfid.rs

@@ -619,7 +619,7 @@ async fn main() -> Result<()> {
     let args = clap_app!(darkfid =>
         (@arg CONFIG: -c --config +takes_value "Sets a custom config file")
         (@arg verbose: -v --verbose "Increase verbosity")
-        (@arg refresh: -r --refresh "Refresh the wallet and own coins")
+        (@arg refresh: -r --refresh "Refresh the wallet and slabstore")
     )
     .get_matches();
 

+ 34 - 0
src/wallet/cashierdb.rs

@@ -135,6 +135,21 @@ impl CashierDb {
         Ok(keys)
     }
 
+    pub fn remove_withdraw_and_deposit_keys(&self) -> Result<()> {
+        debug!(target: "CASHIERDB", "Remove withdraw and deposit keys");
+
+        // open connection
+        let conn = Connection::open(&self.path)?;
+        // unlock database
+        conn.pragma_update(None, "key", &self.password)?;
+
+        conn.execute("DELETE FROM deposit_keypairs;", [])?;
+        conn.execute("DELETE FROM withdraw_keypairs;", [])?;
+        Ok(())
+    }
+
+
+
     pub fn put_withdraw_keys(
         &self,
         token_key_public: &[u8],
@@ -625,6 +640,25 @@ mod tests {
 
         assert!(addr.is_none());
 
+        wallet.put_withdraw_keys(
+            &token_addr,
+            &public2,
+            &secret2,
+            &network,
+            &token_id,
+            String::new(),
+        )?;
+
+        let addr = wallet.get_withdraw_keys_by_token_public_key(&token_addr, &network)?;
+
+        assert!(addr.is_some());
+        
+        wallet.remove_withdraw_and_deposit_keys()?;
+
+        let addr = wallet.get_withdraw_keys_by_token_public_key(&token_addr, &network)?;
+
+        assert!(addr.is_none());
+
         std::fs::remove_file(walletdb_path)?;
 
         Ok(())