Przeglądaj źródła

moved wallet schema to /res and deleted old directory

changed adapter.rs to load schema using include_str!
rachel-rose 5 lat temu
rodzic
commit
1b54e7bb43
4 zmienionych plików z 11 dodań i 16 usunięć
  1. 0 5
      res/schema.sql
  2. 8 9
      src/rpc/adapter.rs
  3. 3 1
      src/rpc/jsonserver.rs
  4. 0 1
      src/wallet/mod.rs

+ 0 - 5
src/wallet/schema.sql → res/schema.sql

@@ -1,4 +1,3 @@
-SQLCIPHER_OPEN_NOMUTEX;
 ATTACH DATABASE 'wallet.db' AS wallet KEY 'testkey';
 SELECT sqlcipher_export('wallet');
 CREATE TABLE IF NOT EXISTS keys(
@@ -10,12 +9,8 @@ CREATE INDEX IF NOT EXISTS key_public on keys(key_public);
 CREATE TABLE IF NOT EXISTS coins(
     coin BLOB NOT NULL
     witness BLOB NOT NULL
-);
-
-CREATE TABLE IF NOT EXISTS note(
     serial BLOB NOT NULL,
     value INT NOT NULL,
     coin_blind BLOB NOT NULL,
     valcom_blind BLOB NOT NULL
 );
-

+ 8 - 9
src/rpc/adapter.rs

@@ -1,5 +1,5 @@
-#[macro_use]
 use std::sync::Arc;
+use log::*;
 use rusqlite::Connection;
 use ff::Field;
 use rand::rngs::OsRng;
@@ -7,7 +7,6 @@ use std::fs::File;
 use std::io::prelude::*;
 use crate::serial;
 use crate::Result;
-use smol::Async;
 
 // Dummy adapter for now
 pub struct RpcAdapter {}
@@ -35,17 +34,17 @@ impl RpcAdapter {
     }
 
     pub async fn new_wallet() -> Result<()> {
-        println!("Creating a new wallet...");
+        debug!(target: "adapter", "new_wallet() [START]");
         let path = dirs::home_dir()
             .expect("Cannot find home directory.")
             .as_path()
             .join(".config/darkfi/wallet.db");
-        let conn = Connection::open(&path).expect("Failed to connect to database.");
-        let mut db_file = File::open("wallet.sql")?;
-        let mut contents = String::new();
-        db_file.read_to_string(&mut contents)?;
-        println!("New wallet created");
-        Ok(conn.execute_batch(&mut contents)?)
+        debug!(target: "adapter", "new_wallet() [FOUND PATH]");
+        println!("Found path: {:?}", &path);
+        debug!(target: "adapter", "new_wallet() [TRY DB CONNECT]");
+        let connect = Connection::open(&path).expect("Failed to connect to database.");
+        let contents = include_str!("../../res/schema.sql");
+        Ok(connect.execute_batch(&contents)?)
     }
     
     //pub async fn decrypt(conn: &Connection, password: )

+ 3 - 1
src/rpc/jsonserver.rs

@@ -155,15 +155,17 @@ impl RpcInterface {
             Ok(jsonrpc_core::Value::Null)
         });
         io.add_method("new_wallet", move |_| async move {
+            println!("New wallet method called...");
             RpcAdapter::new_wallet().await;
             Ok(jsonrpc_core::Value::Null)
         });
         io.add_method("key_gen", move |_| async move {
+            println!("beep");
             //let connection = RpcAdapter::db_connect().await;
             //let (public, private) = RpcAdapter::key_gen().await;
             // getting an error on the following:
             // RpcAdapter::save_key(&connection, private, public).await;
-            Ok(jsonrpc_core::Value::Null)
+            Ok(jsonrpc_core::Value::String("Attempted key generation".into()))
         });
         debug!(target: "rpc", "JsonRpcInterface::handle_input() [END]");
         Ok(io)

+ 0 - 1
src/wallet/mod.rs

@@ -1 +0,0 @@
-// Empty mod.rs file for now