Procházet zdrojové kódy

return asset_id when request token public key from cashierdb

ghassmo před 4 roky
rodič
revize
889a0d3eca
2 změnil soubory, kde provedl 13 přidání a 10 odebrání
  1. 12 10
      src/wallet/cashierdb.rs
  2. 1 0
      src/wallet/wallet_api.rs

+ 12 - 10
src/wallet/cashierdb.rs

@@ -204,8 +204,7 @@ impl CashierDb {
     pub fn get_withdraw_coin_public_key_by_dkey_public(
         &self,
         pub_key: &jubjub::SubgroupPoint,
-        asset_id: &Vec<u8>,
-    ) -> Result<Option<Vec<u8>>> {
+    ) -> Result<Option<(Vec<u8>, jubjub::Fr)>> {
         debug!(target: "CASHIERDB", "Get coin address by pub_key");
         // open connection
         let conn = Connection::open(&self.path)?;
@@ -217,15 +216,18 @@ impl CashierDb {
         let confirm = self.get_value_serialized(&false)?;
 
         let mut stmt = conn.prepare(
-            "SELECT coin_key_id FROM withdraw_keypairs WHERE d_key_public = :d_key_public AND asset_id = :asset_id AND confirm = :confirm;",
+            "SELECT coin_key_id, asset_id FROM withdraw_keypairs WHERE d_key_public = :d_key_public AND confirm = :confirm;",
         )?;
-        let addr_iter = stmt.query_map::<Vec<u8>, _, _>(
-            &[
-                (":d_key_public", &d_key_public),
-                (":asset_id", &asset_id),
-                (":confirm", &&confirm),
-            ],
-            |row| Ok(row.get(0)?),
+        let addr_iter = stmt.query_map::<(Vec<u8>, jubjub::Fr), _, _>(
+            &[(":d_key_public", &d_key_public), (":confirm", &&confirm)],
+            |row| {
+                let coin_public_key = row.get(0)?;
+                let asset_id = row.get(1)?;
+                let asset_id: jubjub::Fr = self
+                    .get_value_deserialized(asset_id)
+                    .expect("deserialize asset_id");
+                Ok((coin_public_key, asset_id))
+            },
         )?;
 
         let mut coin_addresses = vec![];

+ 1 - 0
src/wallet/wallet_api.rs

@@ -14,6 +14,7 @@ pub trait WalletApi {
         Ok(v)
     }
 
+    // TODO pass a reference of Vec<u8>
     fn get_value_deserialized<D: Decodable>(&self, key: Vec<u8>) -> Result<D> {
         let v: D = deserialize(&key)?;
         Ok(v)