Explorar o código

added PRIMARY KEY to sqlite and removed all keyID variables from code

rachel-rose %!s(int64=5) %!d(string=hai) anos
pai
achega
22fee9c510
Modificáronse 4 ficheiros con 11 adicións e 18 borrados
  1. 1 1
      res/schema.sql
  2. 0 1
      src/bin/darkfid.rs
  3. 3 1
      src/rpc/adapter.rs
  4. 7 15
      src/wallet/walletdb.rs

+ 1 - 1
res/schema.sql

@@ -5,8 +5,8 @@ CREATE TABLE IF NOT EXISTS keys(
     key_public BLOB NOT NULL,
     key_private BLOB NOT NULL
 );
-CREATE INDEX IF NOT EXISTS key_public on keys(key_public);
 CREATE TABLE IF NOT EXISTS coins(
+    coin_id INT PRIMARY KEY NOT NULL,
     coin BLOB NOT NULL,
     witness BLOB NOT NULL,
     serial BLOB NOT NULL,

+ 0 - 1
src/bin/darkfid.rs

@@ -200,7 +200,6 @@ async fn start(executor: Arc<Executor<'_>>, options: ClientProgramOptions) -> Re
     let nullifiers = RocksColumn::<columns::Nullifiers>::new(rocks);
 
     let state = State {
-
         tree: CommitmentTree::empty(),
         merkle_roots,
         nullifiers,

+ 3 - 1
src/rpc/adapter.rs

@@ -16,7 +16,9 @@ impl RpcAdapter {
         debug!(target: "adapter", "key_gen() [START]");
         let (public, private) = WalletDB::create_key().await;
         let path = WalletDB::path("wallet.db").expect("Failed to get path");
-        WalletDB::save_key(path, public, private).await.expect("Failed to save key");
+        WalletDB::save_key(path, public, private)
+            .await
+            .expect("Failed to save key");
         Ok(())
     }
 

+ 7 - 15
src/wallet/walletdb.rs

@@ -28,19 +28,15 @@ impl WalletDB {
         Ok(path)
     }
 
-    // unique index in sql
-    // unique index attribute will generate new ID every new table
     pub async fn save_key(path: PathBuf, pubkey: Vec<u8>, privkey: Vec<u8>) -> Result<()> {
         debug!(target: "key_gen", "Generating keys...");
         let connect = Connection::open(&path).expect("Failed to connect to database.");
-        // TODO: ID should not be fixed
-        let id = 0;
         debug!(target: "adapter", "key_gen() [Generating public key...]");
         connect.execute(
-            "INSERT INTO keys(key_id, key_private, key_public)
-            VALUES (:id, :privkey, :pubkey)",
-            named_params! {":id": id,
-             ":privkey": privkey,
+            "INSERT INTO keys(key_private, key_public)
+            VALUES (:privkey, :pubkey)",
+            named_params! {
+            ":privkey": privkey,
              ":pubkey": pubkey
             },
         )?;
@@ -60,7 +56,6 @@ impl WalletDB {
     pub async fn get(path: PathBuf) -> Result<()> {
         debug!(target: "get_cash_public", "Returning cashier keys...");
         let connect = Connection::open(&path).expect("Failed to connect to database.");
-        let _id = 0;
         let mut stmt = connect.prepare("SELECT key_public FROM keys").unwrap();
         let key_iter = stmt
             .query_map::<Vec<u8>, _, _>([], |row| row.get(0))
@@ -80,14 +75,11 @@ impl WalletDB {
         debug!(target: "save_cash_key", "Save cashier keys...");
         //let path = Self::wallet_path();
         let connect = Connection::open(&path).expect("Failed to connect to database.");
-        let id = 0;
         // Write keys to database
         connect.execute(
-            "INSERT INTO cashier(key_id, key_public)
-            VALUES (:id, :pubkey)",
-            named_params! {":id": id,
-             ":pubkey": pubkey
-            },
+            "INSERT INTO cashier(key_public)
+            VALUES (:pubkey)",
+            named_params! {":pubkey": pubkey},
         )?;
         Ok(())
     }