Browse Source

fixed 'not a database' error

rachel-rose 5 years ago
parent
commit
4cee7d36a8
2 changed files with 20 additions and 11 deletions
  1. 7 0
      src/bin/darkfid.rs
  2. 13 11
      src/wallet/walletdb.rs

+ 7 - 0
src/bin/darkfid.rs

@@ -1,4 +1,7 @@
 use async_std::sync::Arc;
 use async_std::sync::Arc;
+use drk::rpc::adapter::RpcAdapter;
+use drk::rpc::options::ProgramOptions;
+use drk::rpc::jsonserver;
 use rand::rngs::OsRng;
 use rand::rngs::OsRng;
 use std::net::SocketAddr;
 use std::net::SocketAddr;
 
 
@@ -226,6 +229,8 @@ fn main() -> Result<()> {
     let ex = Arc::new(Executor::new());
     let ex = Arc::new(Executor::new());
     let (signal, shutdown) = async_channel::unbounded::<()>();
     let (signal, shutdown) = async_channel::unbounded::<()>();
 
 
+    let rpc_options = ProgramOptions::load()?;
+
     let options = ClientProgramOptions::load()?;
     let options = ClientProgramOptions::load()?;
 
 
     let logger_config = ConfigBuilder::new().set_time_format_str("%T%.6f").build();
     let logger_config = ConfigBuilder::new().set_time_format_str("%T%.6f").build();
@@ -246,6 +251,7 @@ fn main() -> Result<()> {
     ])
     ])
     .unwrap();
     .unwrap();
 
 
+    //let adapter = RpcAdapter::new("wallet.db")?;
     let ex2 = ex.clone();
     let ex2 = ex.clone();
 
 
     let (_, result) = Parallel::new()
     let (_, result) = Parallel::new()
@@ -254,6 +260,7 @@ fn main() -> Result<()> {
         // Run the main future on the current thread.
         // Run the main future on the current thread.
         .finish(|| {
         .finish(|| {
             smol::future::block_on(async move {
             smol::future::block_on(async move {
+                //jsonserver::start(ex2.clone(), rpc_options, adapter).await?;
                 start(ex2, options).await?;
                 start(ex2, options).await?;
                 drop(signal);
                 drop(signal);
                 Ok::<(), drk::Error>(())
                 Ok::<(), drk::Error>(())

+ 13 - 11
src/wallet/walletdb.rs

@@ -8,7 +8,7 @@ use ff::Field;
 use log::*;
 use log::*;
 use rand::rngs::OsRng;
 use rand::rngs::OsRng;
 use rusqlite::{named_params, Connection, OpenFlags};
 use rusqlite::{named_params, Connection, OpenFlags};
-use std::path::PathBuf;
+use std::path::{Path, PathBuf};
 
 
 pub struct WalletDB {
 pub struct WalletDB {
     pub path: PathBuf,
     pub path: PathBuf,
@@ -22,14 +22,16 @@ pub struct WalletDB {
 impl WalletDB {
 impl WalletDB {
     pub fn new(wallet: &str) -> Result<Self> {
     pub fn new(wallet: &str) -> Result<Self> {
         let path = Self::create_path(wallet)?;
         let path = Self::create_path(wallet)?;
-        let conn = Connection::open(&path)?;
-        //let conn = Arc::new(Connection::open_with_flags(&path, OpenFlags::SQLITE_OPEN_NO_MUTEX)?);
+        let conn = Connection::open_with_flags(&path, OpenFlags::SQLITE_OPEN_CREATE)?;
         let contents = include_str!("../../res/schema.sql");
         let contents = include_str!("../../res/schema.sql");
         let cashier_secret = jubjub::Fr::random(&mut OsRng);
         let cashier_secret = jubjub::Fr::random(&mut OsRng);
         let secret = jubjub::Fr::random(&mut OsRng);
         let secret = jubjub::Fr::random(&mut OsRng);
         let _public = zcash_primitives::constants::SPENDING_KEY_GENERATOR * secret;
         let _public = zcash_primitives::constants::SPENDING_KEY_GENERATOR * secret;
         let cashier_public = zcash_primitives::constants::SPENDING_KEY_GENERATOR * cashier_secret;
         let cashier_public = zcash_primitives::constants::SPENDING_KEY_GENERATOR * cashier_secret;
-        conn.execute_batch(&contents)?;
+        match conn.execute_batch(&contents) {
+            Ok(v) => println!("Database initalized successfully {:?}", v),
+            Err(err) => println!("Error: {}", err),
+        };
         Ok(Self {
         Ok(Self {
             path,
             path,
             own_coins: vec![],
             own_coins: vec![],
@@ -66,13 +68,13 @@ impl WalletDB {
     }
     }
 
 
     fn create_path(wallet: &str) -> Result<PathBuf> {
     fn create_path(wallet: &str) -> Result<PathBuf> {
-        let mut path = dirs::home_dir()
-            .ok_or(Error::PathNotFound)?
-            .as_path()
-            .join(".config/darkfi/");
-        path.push(wallet);
-        debug!(target: "walletdb", "CREATE PATH {:?}", path);
-        Ok(path)
+       let mut path = dirs::home_dir()
+           .ok_or(Error::PathNotFound)?
+           .as_path()
+           .join(".config/darkfi/");
+       path.push(wallet);
+       debug!(target: "walletdb", "CREATE PATH {:?}", path);
+       Ok(path)
     }
     }
 
 
     pub async fn key_gen(&self) -> (Vec<u8>, Vec<u8>) {
     pub async fn key_gen(&self) -> (Vec<u8>, Vec<u8>) {