Explorar o código

cashier pub key validity check

rachel-rose %!s(int64=5) %!d(string=hai) anos
pai
achega
75c2bc3b02
Modificáronse 3 ficheiros con 13 adicións e 13 borrados
  1. 7 7
      src/bin/darkfid.rs
  2. 5 5
      src/rpc/adapter.rs
  3. 1 1
      src/wallet/walletdb.rs

+ 7 - 7
src/bin/darkfid.rs

@@ -17,6 +17,7 @@ use drk::service::{ClientProgramOptions, GatewayClient, Subscriber};
 use drk::state::{state_transition, ProgramState, StateUpdate};
 use drk::wallet::WalletDB;
 use drk::{tx, Result};
+use rusqlite::{named_params, Connection};
 
 use async_executor::Executor;
 use bellman::groth16;
@@ -47,14 +48,13 @@ pub struct State {
 
 impl ProgramState for State {
     fn is_valid_cashier_public_key(&self, _public: &jubjub::SubgroupPoint) -> bool {
-        // TODO
         // Still needs to be tested
-        let path = WalletDB::path("cashier.db");
-        //let connect = Connection::open(&path).expect("Failed to connect to database.");
-        //connect.execute(
-        //    " SELECT key_public FROM cashier WHERE key_public IN (SELECT key_public)",
-        //Ok(())
-        true
+        let path = WalletDB::path("cashier.db").expect("Failed to get path");
+        let connect = Connection::open(&path).expect("Failed to connect to database.");
+        let mut stmt = connect
+            .prepare("SELECT key_public FROM cashier WHERE key_public IN (SELECT key_public)")
+            .expect("Cannot generate statement.");
+        stmt.exists([1i32]).unwrap()
     }
 
     fn is_valid_merkle(&self, merkle_root: &MerkleNode) -> bool {

+ 5 - 5
src/rpc/adapter.rs

@@ -14,35 +14,35 @@ impl RpcAdapter {
 
     pub async fn key_gen() -> Result<PathBuf> {
         debug!(target: "adapter", "key_gen() [START]");
-        let path = WalletDB::path("wallet.db").await.expect("Failed to get path");
+        let path = WalletDB::path("wallet.db").expect("Failed to get path");
         //WalletDB::key_gen(path).await?;
         Ok(path)
     }
 
     pub async fn new_wallet() -> Result<()> {
         debug!(target: "adapter", "new_wallet() [START]");
-        let path = WalletDB::path("wallet.db").await.expect("Failed to get path");
+        let path = WalletDB::path("wallet.db").expect("Failed to get path");
         WalletDB::new(path).await?;
         Ok(())
     }
 
     pub async fn new_cashier_wallet() -> Result<()> {
         debug!(target: "adapter", "new_cashier_wallet() [START]");
-        let path = WalletDB::path("cashier.db").await.expect("Failed to get path");
+        let path = WalletDB::path("cashier.db").expect("Failed to get path");
         WalletDB::new(path).await?;
         Ok(())
     }
 
     pub async fn save_cash_key(pubkey: Vec<u8>) -> Result<()> {
         debug!(target: "adapter", "save_cash_key() [START]");
-        let path = WalletDB::path("cashier.db").await.expect("Failed to get path");
+        let path = WalletDB::path("cashier.db").expect("Failed to get path");
         WalletDB::save(path, pubkey).await?;
         Ok(())
     }
 
     pub async fn save_key(pubkey: Vec<u8>) -> Result<()> {
         debug!(target: "adapter", "save_key() [START]");
-        let path = WalletDB::path("wallet.db").await.expect("Failed to get path");
+        let path = WalletDB::path("wallet.db").expect("Failed to get path");
         WalletDB::save(path, pubkey).await?;
         Ok(())
     }

+ 1 - 1
src/wallet/walletdb.rs

@@ -24,7 +24,7 @@ impl WalletDB {
     //        let privkey = serial::serialize(&secret);
     //        Ok(pubkey, privkey)
     //    }
-    pub async fn path(wallet: &str) -> Result<PathBuf> {
+    pub fn path(wallet: &str) -> Result<PathBuf> {
         let mut path = dirs::home_dir()
             .expect("cannot find home directory.")
             .as_path()