Преглед изворни кода

change the way of constructing both walletdb and cashierdb

ghassmo пре 4 година
родитељ
комит
ca438923b0
4 измењених фајлова са 14 додато и 22 уклоњено
  1. 5 5
      src/bin/cashierd.rs
  2. 1 1
      src/bin/darkfid.rs
  3. 5 13
      src/wallet/cashierdb.rs
  4. 3 3
      src/wallet/walletdb.rs

+ 5 - 5
src/bin/cashierd.rs

@@ -23,15 +23,15 @@ async fn start(executor: Arc<Executor<'_>>, config: Arc<CashierdConfig>) -> Resu
     let database_path = config.client_database_path.clone();
     let database_path = join_config_path(&PathBuf::from(database_path))?;
 
-    let wallet = Arc::new(CashierDb::new(
-        &config.cashierdb_path,
+    let wallet = CashierDb::new(
+        &PathBuf::from(&config.cashierdb_path),
         config.password.clone(),
-    )?);
+    )?;
 
-    let client_wallet = Arc::new(WalletDb::new(
+    let client_wallet = WalletDb::new(
         &PathBuf::from(&config.client_walletdb_path),
         config.client_password.clone(),
-    )?);
+    )?;
 
     let mint_params_path = join_config_path(&PathBuf::from("cashier_mint.params"))?;
     let spend_params_path = join_config_path(&PathBuf::from("cashier_spend.params"))?;

+ 1 - 1
src/bin/darkfid.rs

@@ -29,7 +29,7 @@ async fn start(executor: Arc<Executor<'_>>, config: Arc<DarkfidConfig>) -> Resul
 
     let rocks = Rocks::new(&database_path)?;
 
-    let wallet = Arc::new(WalletDb::new(&walletdb_path, config.password.clone())?);
+    let wallet = WalletDb::new(&walletdb_path, config.password.clone())?;
 
     // wallet secret key
     let secret: jubjub::Fr;

+ 5 - 13
src/wallet/cashierdb.rs

@@ -2,7 +2,6 @@ use crate::client::ClientFailed;
 use crate::serial;
 use crate::serial::{deserialize, serialize, Decodable, Encodable};
 use crate::service::btc::{PrivKey, PubKey};
-use crate::util::join_config_path;
 use crate::{Error, Result};
 
 use async_std::sync::Arc;
@@ -17,23 +16,16 @@ pub type CashierDbPtr = Arc<CashierDb>;
 
 pub struct CashierDb {
     pub path: PathBuf,
-    pub cashier_secrets: Vec<jubjub::Fr>,
-    pub cashier_public: jubjub::SubgroupPoint,
     pub password: String,
 }
 
 impl CashierDb {
-    pub fn new(wallet: &str, password: String) -> Result<Self> {
+    pub fn new(path: &PathBuf, password: String) -> Result<CashierDbPtr> {
         debug!(target: "CASHIERDB", "new() Constructor called");
-        let path = join_config_path(&PathBuf::from(wallet))?;
-        let cashier_secret = jubjub::Fr::random(&mut OsRng);
-        let cashier_public = zcash_primitives::constants::SPENDING_KEY_GENERATOR * cashier_secret;
-        Ok(Self {
-            path,
-            cashier_secrets: vec![cashier_secret.clone()],
-            cashier_public,
+        Ok(Arc::new(Self {
+            path: path.to_owned(),
             password,
-        })
+        }))
     }
 
     pub fn init_db(&self) -> Result<()> {
@@ -148,7 +140,7 @@ impl CashierDb {
         conn.pragma_update(None, "key", &self.password)?;
 
         conn.execute(
-            "INSERT INTO withdraw_keypairs(btc_key_id, d_key_private, d_key_public) 
+            "INSERT INTO withdraw_keypairs(btc_key_id, d_key_private, d_key_public)
             VALUES (:btc_key_id, :d_key_private, :d_key_public)",
             named_params! {
                 ":btc_key_id": btc_key_id,

+ 3 - 3
src/wallet/walletdb.rs

@@ -22,12 +22,12 @@ pub struct WalletDb {
 }
 
 impl WalletDb {
-    pub fn new(path: &std::path::PathBuf, password: String) -> Result<Self> {
+    pub fn new(path: &PathBuf, password: String) -> Result<WalletPtr> {
         debug!(target: "WALLETDB", "new() Constructor called");
-        Ok(Self {
+        Ok(Arc::new(Self {
             path: path.to_owned(),
             password,
-        })
+        }))
     }
 
     pub fn init_db(&self) -> Result<()> {