fixed 'not a database' error

This commit is contained in:
rachel-rose
2021-06-22 13:23:37 +02:00
parent 0613393e95
commit 4cee7d36a8
2 changed files with 20 additions and 11 deletions

View File

@@ -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>(())

View File

@@ -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<Self> {
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<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>) {