From 1b54e7bb432fd206a382618edd805ed4515260ce Mon Sep 17 00:00:00 2001 From: rachel-rose Date: Fri, 28 May 2021 14:40:13 +0200 Subject: [PATCH] moved wallet schema to /res and deleted old directory changed adapter.rs to load schema using include_str! --- {src/wallet => res}/schema.sql | 5 ----- src/rpc/adapter.rs | 17 ++++++++--------- src/rpc/jsonserver.rs | 4 +++- src/wallet/mod.rs | 1 - 4 files changed, 11 insertions(+), 16 deletions(-) rename {src/wallet => res}/schema.sql (88%) delete mode 100644 src/wallet/mod.rs diff --git a/src/wallet/schema.sql b/res/schema.sql similarity index 88% rename from src/wallet/schema.sql rename to res/schema.sql index 5c3bdf2b5..a2d44c340 100644 --- a/src/wallet/schema.sql +++ b/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 ); - diff --git a/src/rpc/adapter.rs b/src/rpc/adapter.rs index 860d39d04..9ef51ab61 100644 --- a/src/rpc/adapter.rs +++ b/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: ) diff --git a/src/rpc/jsonserver.rs b/src/rpc/jsonserver.rs index 63f0020ed..4132a282e 100644 --- a/src/rpc/jsonserver.rs +++ b/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) diff --git a/src/wallet/mod.rs b/src/wallet/mod.rs deleted file mode 100644 index 78d84fdb0..000000000 --- a/src/wallet/mod.rs +++ /dev/null @@ -1 +0,0 @@ -// Empty mod.rs file for now