Browse Source

drk: Properly add DAO coins to the wallet when scanning.

parazyd 3 years ago
parent
commit
b2dea1a2c6
2 changed files with 13 additions and 2 deletions
  1. 11 1
      bin/drk/src/wallet_dao.rs
  2. 2 1
      bin/drk/src/wallet_money.rs

+ 11 - 1
bin/drk/src/wallet_dao.rs

@@ -214,6 +214,17 @@ impl Drk {
         Ok(())
     }
 
+    /// Fetch all DAO secret keys from the wallet
+    pub async fn get_dao_secrets(&self) -> Result<Vec<SecretKey>> {
+        let daos = self.get_daos().await?;
+        let mut ret = Vec::with_capacity(daos.len());
+        for dao in daos {
+            ret.push(dao.secret_key);
+        }
+
+        Ok(ret)
+    }
+
     /// Replace the DAO Merkle trees in the wallet.
     pub async fn put_dao_trees(
         &self,
@@ -632,7 +643,6 @@ impl Drk {
     /// Append data related to DAO contract transactions into the wallet database.
     /// Optionally, if `confirm` is true, also append the data in the Merkle trees, etc.
     pub async fn apply_tx_dao_data(&self, tx: &Transaction, confirm: bool) -> Result<()> {
-        eprintln!("Enter apply_tx_dao_data()");
         let cid = *DAO_CONTRACT_ID;
         let mut daos = self.get_daos().await?;
         let mut daos_to_confirm = vec![];

+ 2 - 1
bin/drk/src/wallet_money.rs

@@ -519,6 +519,7 @@ impl Drk {
         }
 
         let secrets = self.get_money_secrets().await?;
+        let dao_secrets = self.get_dao_secrets().await?;
         let mut tree = self.get_money_tree().await?;
 
         let mut owncoins = vec![];
@@ -533,7 +534,7 @@ impl Drk {
             let enc_note =
                 EncryptedNote { ciphertext: output.ciphertext, ephem_public: output.ephem_public };
 
-            for secret in &secrets {
+            for secret in secrets.iter().chain(dao_secrets.iter()) {
                 if let Ok(note) = enc_note.decrypt(secret) {
                     eprintln!("Successfully decrypted a Money Note");
                     eprintln!("Witnessing coin in Merkle tree");