From 4cee7d36a82e71284bafba8c8d94b714f072586e Mon Sep 17 00:00:00 2001 From: rachel-rose Date: Tue, 22 Jun 2021 13:23:37 +0200 Subject: [PATCH] fixed 'not a database' error --- src/bin/darkfid.rs | 7 +++++++ src/wallet/walletdb.rs | 24 +++++++++++++----------- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/src/bin/darkfid.rs b/src/bin/darkfid.rs index df5f8f4b8..30bacbb48 100644 --- a/src/bin/darkfid.rs +++ b/src/bin/darkfid.rs @@ -1,4 +1,7 @@ use async_std::sync::Arc; +use drk::rpc::adapter::RpcAdapter; +use drk::rpc::options::ProgramOptions; +use drk::rpc::jsonserver; use rand::rngs::OsRng; use std::net::SocketAddr; @@ -226,6 +229,8 @@ fn main() -> Result<()> { let ex = Arc::new(Executor::new()); let (signal, shutdown) = async_channel::unbounded::<()>(); + let rpc_options = ProgramOptions::load()?; + let options = ClientProgramOptions::load()?; let logger_config = ConfigBuilder::new().set_time_format_str("%T%.6f").build(); @@ -246,6 +251,7 @@ fn main() -> Result<()> { ]) .unwrap(); + //let adapter = RpcAdapter::new("wallet.db")?; let ex2 = ex.clone(); let (_, result) = Parallel::new() @@ -254,6 +260,7 @@ fn main() -> Result<()> { // Run the main future on the current thread. .finish(|| { smol::future::block_on(async move { + //jsonserver::start(ex2.clone(), rpc_options, adapter).await?; start(ex2, options).await?; drop(signal); Ok::<(), drk::Error>(()) diff --git a/src/wallet/walletdb.rs b/src/wallet/walletdb.rs index 6daddbf89..c27898133 100644 --- a/src/wallet/walletdb.rs +++ b/src/wallet/walletdb.rs @@ -8,7 +8,7 @@ use ff::Field; use log::*; use rand::rngs::OsRng; use rusqlite::{named_params, Connection, OpenFlags}; -use std::path::PathBuf; +use std::path::{Path, PathBuf}; pub struct WalletDB { pub path: PathBuf, @@ -22,14 +22,16 @@ pub struct WalletDB { impl WalletDB { pub fn new(wallet: &str) -> Result { 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 cashier_secret = jubjub::Fr::random(&mut OsRng); let secret = jubjub::Fr::random(&mut OsRng); let _public = zcash_primitives::constants::SPENDING_KEY_GENERATOR * 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 { path, own_coins: vec![], @@ -66,13 +68,13 @@ impl WalletDB { } fn create_path(wallet: &str) -> Result { - 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, Vec) {